Jump to content
  • Advertisement
Sign in to follow this  
markookram

Rotating objects independantly

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Basically I want to rotate/move objects in the 3D world independantly from each other, but many tutorials I have read just do this... device.Transform.World = Matrix.RotationZ(angle); ...and rotate the whole world! What is the best way to divide the world into seperate objects that can be manipulated independantly? I'm guessing some sort of vertex array, but then I can't use the rotation matrixes on them?

Share this post


Link to post
Share on other sites
Advertisement
it works like this. you render one object, using device.Transform.World = Matrix.RotationZ(angle);. then another, but before rendering you set another angle. or matrix or whatever.

Share this post


Link to post
Share on other sites
This answer might be similar to my question about rending multiple instances of objects to the screen at the same time when each object has it's OWN render() function to be called. I'm having a hard time grasping how this would be done. Wouldn't this mean that each object would have it's own begin() and endscene() and would just render one object at a time?

I think my above problem is similar to yours. You somehow need to have each object rotate itself with a member function, then pass that information to the renderer. I'm a bit lost. actually lots of bits lost. (thanks i'll be here all week)

Share this post


Link to post
Share on other sites
every object has a Worldmatrix.

you basically calculate it per object.
like

Object1:
Worldmatrix = Rotationmatrix * Translationmatrix

if you want to rotate that object recalculate the world matrix of that object
and then render your object based on that worldmatrix :)

Share this post


Link to post
Share on other sites
every object is rendered using whatever transformations you have set. so if you had one cube mesh in memory, and you wanted to render it ten times, but in different places, you would do it like this.

set transformation matrix to position 1
render the cube
set transformation matrix to position 2
render the same cube
set transformation matrix to position 3
render still the same cube
.
.
.


clear?

Share this post


Link to post
Share on other sites
Quote:
Original post by induster
I'm having a hard time grasping how this would be done. Wouldn't this mean that each object would have it's own begin() and endscene() and would just render one object at a time?


Nope, just call BeginScene. Set up your view and projection matricies and then before you call Render, Draw, or whatever on your object you set up the world transform. Each object in your world should have it's own world transform based on it's position, orientation, and scale.

For example.


D3DDevice_->Clear(0,NULL,D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0),1.0f,0);

D3DDevice_->BeginScene();

SetupViewMatrix();

for( unsigned i = 0; i < objects_.size(); ++i )
{
objects_->GetWorldMatrix( &matWorld_ );
D3DDevice_->SetTransform( D3DTS_WORLD, &matWorld_ );
DrawModel( objects_->GetModel() );
}

D3DDevice_->EndScene();

D3DDevice_->Present(NULL,NULL,NULL,NULL);




I wouldn't recommend doing it exactly as shown but it works well enough.

Share this post


Link to post
Share on other sites
Ok, I think I see now. The actual begin and end scene should be located in it's own class. Like a drawscene class that takes in all objects as arguments. Now I'm seeing where it would be important to organize all objects into an array or list to make passing them easier.

thanks everyone

Share this post


Link to post
Share on other sites
Use a class if you mean that?

like:


class Object
{
Matrix worldMatrix;
Matrix rotationMatrix;
Matrix translationMatrix;

void Rotate(Vector3 rotation;
{
// calculation here the rotation matrix;
}

void SetPosition(Vector3 rotation)
{
// calculate here the translation matrix;
}

void Render()
{
worldMatrix = rotationMatrix * translationMatrix;

// render calls
}
}



a bit like that ;)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!