How to apply Matrix Transformation to individual models.

Started by
10 comments, last by InfinityMachine 10 years, 2 months ago

Hello! I've worked to import models from Maya using custom code into a C++/DirectX game. But, while trying to come up with a way to render multiple imported models, I've run into an issue identifying the individual vertex buffer to apply the transformations to. Is this something I can use function "scoping" to separate the models from each other and draw individually? Or are they all stored in the one global buffer?

(Vertices are rendered using DrawIndex())

Find yourself. If you can't, keep looking.

Advertisement
I think you should load the models from the maya export into separate meshes/ models, that way you can handle them individually. Transformations, rotations, scaling, rendering, culling etc.

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

That's exactly what I was running into. But it looks like the problem was getting the intended vertices out of the contiguous vertex buffer.

Find yourself. If you can't, keep looking.

Okay. Maybe you could try another Maya file loader. Personally no experience with this, I'm using Max (2011)

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

Okay. Maybe you could try another Maya file loader. Personally no experience with this, I'm using Max (2011)

I wrote the parser (file loader); it works, but I'm unfamiliar with DirectX methodology, and was coding partially in the dark. I didn't know how to apply matrix transformations to specific vertices in the buffer, particularly enough to provide the feel of a direct transform (done with members of the same class) when multiple objects were in the buffer at once.

Find yourself. If you can't, keep looking.

You aren't changing the coordinates of the vertices, are you? You're supposed to pass the matrix into the shaders and change the coordinates inside the shader. Directly changing the coordinates of vertices will accumulate FP rounding errors and cause you to send the vertex data back and forth between the CPU and GPU every frame.

I admit I'm not fully understanding what you're actually doing, nor what you want to do though. If you still need help, perhaps just explain what you're doing as if to a child so you don't leave anything important out. If you're just following a tutorial and trying to modify it to learn something new, link to the tutorial and explain what you're trying to add.

When you import your models, they should be centered on themselves, in their "model space".

Matrix transforms aren't usually done on the CPU these days (unless targeting specific GPU/CPU load balance I guess), so the idea is that you grab these models, construct a matrix representing their position and orientation in the world, send them off to the GPU, and do the math there. You'll also need other matrices (view matrix for moving everything to camera space, projection matrix to move everything to screen space, and you'll also need a matrix for normals if you're doing lightning).

Set up a matrix (world, view and projection combined), set up a buffer with a model and send them to the shader. Rinse and repeat for each model. Forever.

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

You aren't changing the coordinates of the vertices, are you? You're supposed to pass the matrix into the shaders and change the coordinates inside the shader. Directly changing the coordinates of vertices will accumulate FP rounding errors and cause you to send the vertex data back and forth between the CPU and GPU every frame.

I admit I'm not fully understanding what you're actually doing, nor what you want to do though. If you still need help, perhaps just explain what you're doing as if to a child so you don't leave anything important out. If you're just following a tutorial and trying to modify it to learn something new, link to the tutorial and explain what you're trying to add.

No tutorial, but yes: DirectX documentation and MSDN. I managed to import some of my Maya goods into my exe: Great! Then I thought, I should import another .obj! Of course wrapping up my process. (minus the obj parsing copies and other slow stuff -> gets delete[] in scope) Running the function twice, didn't work, presumably because I neglected to update the total number of indices for DrawIndexed(). Which I could wrap my mind around. But when it comes to performing transforms I gasped! Where's my data? How can I refer to Object 3's vertex data to perform a transform? I felt that Willy Wonka's magic teleporter was upon me, and little chocolate vertices were giggling all at once above my head. Elusive.

Find yourself. If you can't, keep looking.

When you import your models, they should be centered on themselves, in their "model space".

Matrix transforms aren't usually done on the CPU these days (unless targeting specific GPU/CPU load balance I guess), so the idea is that you grab these models, construct a matrix representing their position and orientation in the world, send them off to the GPU, and do the math there. You'll also need other matrices (view matrix for moving everything to camera space, projection matrix to move everything to screen space, and you'll also need a matrix for normals if you're doing lightning).

Set up a matrix (world, view and projection combined), set up a buffer with a model and send them to the shader. Rinse and repeat for each model. Forever.

Ok something like: (Which I may magic wrap)


Import model01->(VertBuff)(IndiceBuff)
Import model02->(VertBuff)(IndiceBuff)

Render()
Clear the heck out(everything)

Store transforms-> float4x4, Rotation, Translate, Scale
Perform transform->DXfunctionRotX->m1VertBuff
Draw(Vertbuff, ...)

Store transforms-> float4x4, Rotation, Translate, Scale
Perform transform->DXfunctionRotX->m1VertBuff
Draw(Vertbuff, ...)

Swap backbuffer


You know that was so straight forward... I forgot the nature of the pipeline. Thanks! I'll try to implement this tonight!

Find yourself. If you can't, keep looking.

You aren't changing the coordinates of the vertices, are you? You're supposed to pass the matrix into the shaders and change the coordinates inside the shader. Directly changing the coordinates of vertices will accumulate FP rounding errors and cause you to send the vertex data back and forth between the CPU and GPU every frame.

I admit I'm not fully understanding what you're actually doing, nor what you want to do though. If you still need help, perhaps just explain what you're doing as if to a child so you don't leave anything important out. If you're just following a tutorial and trying to modify it to learn something new, link to the tutorial and explain what you're trying to add.

Although I'm not changing the vertices directly that was a good point. I read about that I believe either during reading up on optimization or maybe newer Dx11 features. I'll provide the link for future eyes when I can find it.

Find yourself. If you can't, keep looking.

This topic is closed to new replies.

Advertisement