• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
InfinityMachine

How to apply Matrix Transformation to individual models.

11 posts in this topic

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
0

Share this post


Link to post
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.
2

Share this post


Link to post
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.

0

Share this post


Link to post
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.

0

Share this post


Link to post
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.

2

Share this post


Link to post
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.

2

Share this post


Link to post
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. 

0

Share this post


Link to post
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
0

Share this post


Link to post
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.

0

Share this post


Link to post
Share on other sites

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.

1

Share this post


Link to post
Share on other sites

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!

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0