Public Group

# How to apply Matrix Transformation to individual models.

This topic is 1807 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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())

Edited by InfinityMachine

##### Share on other sites
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.

##### Share on other sites

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.

##### Share on other sites

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

##### Share on other sites

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.

##### Share on other sites

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.

##### Share on other sites

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.

##### Share on other sites

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.

##### Share on other sites

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!

Edited by InfinityMachine

##### Share on other sites

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.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 19
• 15
• 10
• 9
• 11
• ### Forum Statistics

• Total Topics
634097
• Total Posts
3015511
×