A question when using transformManager #7439
Replies: 2 comments 1 reply
-
And this is another screenshot which the cube with underscore was rendered correctly while the cube with -> did not show up(I mark them using edgebox using GL.LINES) when use TransformManager to set the position, angle, and size. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Make sure your matrix is in the correct order (row vs column major). |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I wanna render objects into scene and adjust the object position, angle, size information according to the information from backend and I attempt to achieve in 2 different ways. First is after calculate the transformMatrix, I apply it to every point in kotlin(cpu) and set them into vertex buffer. I did it like this:
private fun getVertexDataPoint(difx: Float, dify: Float, difz: Float): Float3 { // do rotation with transformMatrix
val float4Arr = floatArrayOf(this.position.x+difx, this.position.y + dify, this.position.z + difz, 1f)
val result = floatArrayOf(0f, 0f, 0f, 0f)
Matrix.multiplyMV(result, 0, transformMatrix, 0, float4Arr, 0)
return Float3(result[0], result[1], result[2])
}
render part:
renderableManager.let {
if (it != null && it.hasComponent(entity)) {
val renderInstacne = renderableManager?.getInstance(entity)
if (renderInstacne != null) {
it.setGeometryAt(renderInstacne, 0, RenderableManager.PrimitiveType.TRIANGLES,geometry.vertexBuffer,geometry.indexBuffer, 0, indicesList.size)
}
} else {
RenderableManager.Builder(1)
// Overall bounding box of the renderable
.boundingBox(Box(0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.01f))
// Sets the mesh data of the first primitive
.geometry(
0,
RenderableManager.PrimitiveType.TRIANGLES,
geometry.vertexBuffer,
geometry.indexBuffer,
0,
indicesList.size
)
.material(0, materialInstance)
.build(engine, entity)
}
}
and I can get the correct result:
and another way which I think should be the correct way is set the data to vertexbuffer directly and use transformManager to adjust it position ,size, and angle
I did it like this:
private fun getVertexDataPoint(difx: Float, dify: Float, difz: Float): Float3 { // do rotation with transformMatrix
val float4Arr = floatArrayOf(this.position.x+difx, this.position.y + dify, this.position.z + difz, 1f)
return Float3(float4Arr[0], float4Arr[1], float4Arr[2])
}
Render part:
renderableManager.let {
if (it != null && it.hasComponent(entity)) {
val renderInstacne = renderableManager?.getInstance(entity)
if (renderInstacne != null) {
it.setGeometryAt(renderInstacne, 0, RenderableManager.PrimitiveType.TRIANGLES,geometry.vertexBuffer,geometry.indexBuffer, 0, indicesList.size)
}
} else {
RenderableManager.Builder(1)
// Overall bounding box of the renderable
.boundingBox(Box(0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.01f))
// Sets the mesh data of the first primitive
.geometry(
0,
RenderableManager.PrimitiveType.TRIANGLES,
geometry.vertexBuffer,
geometry.indexBuffer,
0,
indicesList.size
)
.material(0, materialInstance)
.build(engine, entity)
}
}
val transformManager = engine.transformManager
scene.addEntity(entity)
transformManager.setTransform(transformManager.getInstance(entity), transformMatrix)
However, I got the result that miss some object that should be rendered in scene with the same data before:
If someone know the reason why I used the same transfromMatrix and same data source but lose some object when using transformManager(as I know it do transform in gpu which should be a better way). Thanks so much!
Beta Was this translation helpful? Give feedback.
All reactions