# Help me to get it right

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

## Recommended Posts

I started not long ago with 3d programming, especially direct 3d. I am getting somewhat it... but i need to ask a few questions. I've never bought a book on this subject, all my information was based on the directx api docs and the tutorials on the net (thanks nehe and drunken hyena!). Modell space and screen space: According to this tutorial: http://www.drunkenhyena.com/cgi-bin/view_article.pl?chapter=2;article=27;lang=cpp coordinates in model space can be every size i want to. Original: "As mentioned in the 3D Primer, Model Space vertices are defined relative to each other, often with (0,0,0) in the center. When we used Screen Space coordinates it was obvious what what unit was equal to, 1 pixel. In Model Space you can define your units to be whatever size you want them to be. They can be inches, feet, meters or light-years, whatever scale suits your needs. Because most games are done in a human-relative scale, 1 meter is a very common unit. Also, while it's not required it's a good idea to make your units consistent. If 1 unit is 1 meter for 1 model, make it the same for each other model as well as your World Space units. If your Model Space units and World Space units are different then you'll have to scale them when they are rendered. " So.. where can i set the size of the coordinates? How does directx know, that i meant with 1.0f one meter, and not one light year? Another thing is the conversion from model space to world space. How i do this right now: void rendering() { D3DXMATRIXA16 world1; D3DXMATRIXA16 world2; ddevice9->Clear(0, NULL, D3DCLEAR_TARGET, 0x66FF33, 0, 0); ddevice9->BeginScene(); D3DXMatrixTranslation(&world1, 0.2f, 0.0f, 0.0f); ddevice9->SetTransform(D3DTS_WORLD, &world1); ddevice9->SetStreamSource(0, vb9, 0, sizeof(CUSTOMVERTEX)); ddevice9->SetFVF(ourvertexform); ddevice9->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 1); D3DXMatrixTranslation(&world2, -0.2f, 0.0f, 0.0f); ddevice9->SetTransform(D3DTS_WORLD, &world2); ddevice9->SetStreamSource(0, vb2, 0, sizeof(CUSTOMVERTEX)); ddevice9->SetFVF(ourvertexform); ddevice9->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 1); ddevice9->EndScene(); ddevice9->Present(NULL, NULL, NULL, NULL); } I think thats fairly simple to see, what i mean. For every object i set always a (new) world space, and then i call the draw routine. Is this the right thing to do? Do professional games follow the same principle? (of course much bigger.. but you got the idea). It's for a beginner a bit weird, to imagine, that for every single foot soldier in warcraft or c&c generals the world space is exclusivley set. I hope my questions aren't too dumb.

##### Share on other sites
Hi,

When constructing the matrix, D3DXMatrixTranslation is not your only option. You can use D3DXMatrixScaling to scale your object and then multiply these matrices to achieve both translation and scaling.

About the setting of transformation before every object: yes, I think so. At least, we do it like this. However, you don't always have to set the FVF if it's the same for all objects. It's enough if you do it once.

Peter

##### Share on other sites
Well, thanks. I haven't still an answer for the first question though..

##### Share on other sites
In a professional game you'd make certain design choices as per the resolution of using just 1 unit as 1 meter. Let's say we make the descision of having 1 unit in 3d space represent 1 meter, how do you tell direct3d that? Well direct3d doesn't need to know that because that would make no sense at all. On the other hand, the guy making your 3d modells would need to know that since he'd be the guy RESIZING the models so that the top vertice of for example his human would have the top vertice at x something, y = 0.9f, z something (that is if we're using y as up axis); and the lowest vertices at x something, y = -0.9f; and z something. Those are just some coordinates, our human would then have his 0, 0, 0 coordinate right in his belly or, special place. *cough* (In modelspace, and it's around that point that your vertices gets rotated. So if you wanted the character to rotate around his head, you'd have to move all the vertices in the model down a bit so that the 0,0,0 place would be inside his head and then rotate it.)

So after we've loaded the model we're going to have our 1.8m character somewhere in the world, wherever you want to place him. Each object will have it's own matrix or variables containing data specifying his 3D location and rotation and such. Before rendering you'd take those values and build a matrix, set it as the world matrix and then render the object.

So now we want to move our character, but how fast? Well let's just define that he can move at a speed of 2 meters per second, that works out great since we descided that 1 unit = 1 meter.

So we'll just take our Pos += D3DXVec3Normalize(&moveInDirection, &moveInDirection) * movementSpeed * deltaTime;(how long it took to render the last frame) make a translation matrix out of the D3DXVECTOR3 Pos's x, y, z components and set his personal offsetmatrix as the worldmatrix temporarily and render him.

So in conclusion d3d doesn't need to know that 1 unit is 1 meter or whatever you want, it's all up to you to manage your game and resources accordingly.

1. 1
Rutin
44
2. 2
3. 3
4. 4
5. 5

• 10
• 28
• 20
• 9
• 20
• ### Forum Statistics

• Total Topics
633409
• Total Posts
3011706
• ### Who's Online (See full list)

There are no registered users currently online

×