Jump to content

  • Log In with Google      Sign In   
  • Create Account


How to apply Matrix Transformation to individual models.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
11 replies to this topic

#1 InfinityMachine   Members   -  Reputation: 168

Like
0Likes
Like

Posted 05 February 2014 - 11:46 AM

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, 05 February 2014 - 11:46 AM.

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


Sponsor:

#2 cozzie   Members   -  Reputation: 1585

Like
2Likes
Like

Posted 05 February 2014 - 01:39 PM

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.

#3 InfinityMachine   Members   -  Reputation: 168

Like
0Likes
Like

Posted 05 February 2014 - 02:55 PM

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.


#4 cozzie   Members   -  Reputation: 1585

Like
0Likes
Like

Posted 05 February 2014 - 04:38 PM

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



#5 InfinityMachine   Members   -  Reputation: 168

Like
0Likes
Like

Posted 05 February 2014 - 06:01 PM

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.


#6 richardurich   Members   -  Reputation: 1187

Like
2Likes
Like

Posted 05 February 2014 - 07:56 PM

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.



#7 TheChubu   Crossbones+   -  Reputation: 4101

Like
2Likes
Like

Posted 05 February 2014 - 08:05 PM

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


#8 InfinityMachine   Members   -  Reputation: 168

Like
0Likes
Like

Posted 05 February 2014 - 11:09 PM

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.


#9 InfinityMachine   Members   -  Reputation: 168

Like
0Likes
Like

Posted 05 February 2014 - 11:18 PM

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, 05 February 2014 - 11:45 PM.

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


#10 InfinityMachine   Members   -  Reputation: 168

Like
0Likes
Like

Posted 05 February 2014 - 11:26 PM

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.


#11 TheChubu   Crossbones+   -  Reputation: 4101

Like
1Likes
Like

Posted 06 February 2014 - 04:45 AM

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

Yes and no.

 

I don't know the particulars of DirectX but I think there are a few steps you're missing. When I'm saying you "do the math in the GPU" I'm saying that you do the transforms in a shader. As far as I'm seeing you're not using any shaders.

 

Shaders are programs that are executed in the GPU. They're coded in a specific language, DirectX shader language is HLSL.

 

The vertex shader stage is dedicated for this purpose. When you issue your draw call (after setting up the appropriate vertex buffer and matrix constant buffer) the GPU will grab the vertices (in model space, like when you loaded them) in the order they're presented (or by indexing like you're doing) and it will multiply each one by the matrix you're passing to the vertex shader.

 

In your vertex shader you'll have something like:

 

incoming vertexPosition; // This one will be changed each time the program gets executed for each vertex you send to the GPU.
incoming constant matrixTransform; // This one is constant for the whole model. Changed before you draw the next model.
 
vertex program
{
    finalPosition = vertexPosition * matrixTransform; // Row vertex * 4x4 transform matrix (which is modelMat * viewMat * projMat, precomputed in CPU ).
}
( I could put "correct" GLSL but it wouldn't help you at all :D

 

After that you have a pixel shader stage that will compute each pixel produced by the geometry that was processed by the vertex shader.

 

Now you might be using fixed function pipeline on DirectX (9 I think?), things change quite a bit in that case, and there is where my knowledge ends. No idea how to use OpenGL fixed function pipeline, much less DX's.


"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


#12 InfinityMachine   Members   -  Reputation: 168

Like
0Likes
Like

Posted 08 February 2014 - 12:33 PM

I modeled a system (Using a object class: I import models, store the start, number of verts/indices in a dynamic data struture (for global/debug) and it looks like it's working. There was a load of screaming, but after having to create masses of functions, literally building from the ground up,Thanks guys! I'm one level closer to the game I want to create and I'm on top of my code!


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





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS