#### Archived

This topic is now archived and is closed to further replies.

# A few quick questions about DX8...

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

## Recommended Posts

I have a few questions regarding Direct X 8. 1. I have been through the D3D matrix tutorial. There is something I can''t get to work/understand. Lets suppose I want to rotate my model around the X/Y axis. I tried doing something like
//for the world matrix, just rotate the object about the  axis
D3DXMATRIX matWorld;

D3DXMatrixRotationY(&matWorld, timeGetTime()/900.0f);
D3DXMatrixRotationX(&matWorld, timeGetTime()/900.0f);
lpd3ddevice->SetTransform(D3DTS_WORLD, &matWorld);

It only wants to rotate around the Y axis or the X axis. I tried multiplying the results from the two matrices and using the result from that in SetTransform() but It resulted in some really wierd stuff (wierd rotations of all directions). Also I am having trouble understanding the model space and world space coordinates. I realize when I do:
lpd3ddevice->SetTransform(D3DTS_WORLD, &matWorld);

it should change it from model to world space, right? Now if I have multiple models (or objects) and I want to rotate several of them in model space then change them to world space what would I do? 2. When I first initialize my vertex buffer, and I don''t know how big it should be. How do I handle this? I don''t want to go ahead and allocate so much (enough for say, 10000 vertices) because that seems kind of wasteful. I also don''t want to overflow the vertex buffer (I can imagine the results). How should this be handled?

##### Share on other sites
quote:
Original post by Moe

I have a few questions regarding Direct X 8.

1. I have been through the D3D matrix tutorial. There is something I can't get to work/understand. Lets suppose I want to rotate my model around the X/Y axis.

Try:

  D3DXMATRIX rotationAroundX;D3DXMATRIX rotationAroundY;D3DXMatrixRotationY(&rotationAroundY, timeGetTime()/900.0f);D3DXMatrixRotationX(&rotationAroundX, timeGetTime()/900.0f);D3DXMatrixMultiply(&matWorld, &rotationAroundX, &rotationAroundY);lpd3ddevice->SetTransform(D3DTS_WORLD, &matWorld);

quote:

Also I am having trouble understanding the model space and world space coordinates. I realize when I do:
lpd3ddevice->SetTransform(D3DTS_WORLD, &matWorld);

it should change it from model to world space, right? Now if I have multiple models (or objects) and I want to rotate several of them in model space then change them to world space what would I do?

Draw one object then do another SetTransform and draw another object.

-------
Andrew

Edited by - acraig on February 13, 2001 10:38:35 PM

##### Share on other sites
two solutions, its late and i dont know which is better:
1)D3DXMatrixRotationX(&matWorld, timeGetTime()/900.0f);
lpd3ddevice->SetTransform(D3DTS_WORLD, &matWorld);
D3DXMatrixRotationY(&matWorld, timeGetTime()/900.0f);
lpd3ddevice->MultiplyTransform(D3DTS_WORLD, &matWorld);
---or---
2)D3DXMatrixRotationYawPitchRoll(&matWorld,
timeGetTime()/900.0f,
timeGetTime()/900.0f,
0.0f);

i''m pretty new to vertex buffers, but from my limited experiance i always make my vertex buffers the exact size fo the number of verticies unless i dont know what that size is. then i just make the vertex buffer a dynamic vertex buffer much in the same way you would make a dymnamic array in C.

ok im going to bed before i fall asleep right here and get a bad case of keyboard face again.

Brett Lynnes
cheez_keeper@hotmail.com
"ZZZZZZzzzzzzzzzzzzzzz" - *snore*

##### Share on other sites
The world matrix is indeed what gets your objects from local/object space to global/world space. If you need to rotate objects about their own axis, use the world matrix.

It's important you do everything in the right order though. If you need to scale your objects, do this first, then do your x,y,z rotations in that order, then you translate them. You have to multiply the matrices at every point, and you need to set the world matrix to the identity matrix before you start every frame.

If you need to rotate and translate different objects by different amounts (which of course you will) you need to generate new matrices for each object and call SetTransform for each object. This of course means you have to draw them with seperate DrawPrimitive calls.

Global translation and rotation is done with the view matrix and processes your objects into camera/view space. Again set your view matix to the identity first. You'll probably only need to generate your view matrix once per frame.

The only thing I can see wrong with your code is that you aren't multiplying your matrices and that you should make sure when you do multiply them, you supply the arguments in the right order. X rotation should come before Y or you will get strange effects.

Edited by - simon_brown75 on February 14, 2001 9:23:24 AM

##### Share on other sites
Thanks.

I am pretty new to this programming stuff (I have been using VC++ for less than a year). How would I go about creating a dynamic vertex buffer?

I want to be on the safe side because I plan to load numerous models (probably .x files to start) and have a particle system. It will be almost impossible to know how many particles etc I will have on the screen at one time and I would like to play it the safe way rather than the sorry way.

Never cross the thin line between bravery and stupidity.

1. 1
Rutin
65
2. 2
3. 3
4. 4
5. 5

• 17
• 10
• 29
• 20
• 9
• ### Forum Statistics

• Total Topics
633415
• Total Posts
3011768
• ### Who's Online (See full list)

There are no registered users currently online

×