• Create Account

# Matching the rotation of one object with another

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.

4 replies to this topic

### #1Kimimaru  Members   -  Reputation: 144

Like
0Likes
Like

Posted 02 September 2013 - 05:52 PM

Hey everyone! I implemented a way of drawing objects partially underwater, but an issue with rotation popped up.

How I do my drawing is I check the depth of the water and draw the top part of the object normally and the part submerged in water (height of the sprite - the water depth) separately. Since these two parts are often different sizes, rotating the object will cause both parts to rotate at different speeds, disfiguring the object.

What I need is a calculation that will change the submerged part's rotation to match with the rotation of the unsubmerged part. Think of two circles with one smaller and one larger. It will take the smaller one less time to complete a full rotation, so it won't be rotating in unison with the larger circle. I need something that, given the rotation value, will modify the smaller circle's rotation value and place it at the same point of rotation as the larger one (Ex. both circles will be at pi/2 rad in 3 seconds as opposed to the smaller circle reaching pi in 3 seconds and the larger one reaching pi/2 in 3).

Edited by Kimimaru, 02 September 2013 - 05:52 PM.

### #2PandaDragonThing  Members   -  Reputation: 273

Like
1Likes
Like

Posted 03 September 2013 - 05:43 AM

I think the problem is your rotating both around their respective center and thus not making them rotate together. Rotate both around a common point, probably the center of the bottom part in this case.

//Do this for both pieces
glTranslatef( Bottom.x, Bottom.y, Bottom.z );
glRotatef( Rotation, 0.0f, 1.0f, 0.0f );


This is if you're using OpenGL( deprecated method shown ), but the same idea would apply.

Edited by PandaDragonThing, 03 September 2013 - 05:43 AM.

### #3Kimimaru  Members   -  Reputation: 144

Like
0Likes
Like

Posted 03 September 2013 - 09:54 AM

Yeah, that's precisely it. I'd want them to both rotate around the original center as if they were one piece, but I still need them separated so the lower part is drawn under the water. What I think I need actually is to change the origin I'm drawing both parts at and make sure their origins meet up in the same spot.

Say I had an entire sprite that was of height 70 and the top part was 20 and the bottom was 50. If my origin had a Y value of 35, I need to have the top part rotate around 35 and the bottom part to rotate around that same amount relative to its total size...how exactly to do it isn't coming to me, though. Especially when you consider that the top and bottom parts can be changing in size if the object is heading towards the surface of the water or coming into the water.

EDIT: Never mind; everything works fine when the rotation is 0, so I may have to adjust the rotation. It also seems like I'll need to change the parts drawn underwater depending on the rotation...so if an object is rotated by pi radians vertically then the part that wasn't underwater must now be underwater and the previously submerged part must now be above the surface.

Any ideas?

Edited by Kimimaru, 03 September 2013 - 12:59 PM.

### #4Kimimaru  Members   -  Reputation: 144

Like
0Likes
Like

Posted 03 September 2013 - 02:44 PM

Sorry for the double post, but I uploaded a video simulating my problem: http://s300.photobucket.com/user/Kimimaru4000/media/RotationTest.mp4.html

You can see the effects of the rotation on the bottom part that is submerged in water. The rotations themselves are fine and match up, but it looks like I need to change the position or something. Any advice?

Edited by Kimimaru, 03 September 2013 - 02:46 PM.

### #5L. Spiro  Crossbones+   -  Reputation: 7452

Like
1Likes
Like

Posted 03 September 2013 - 07:07 PM

I really can’t understand your explanation nor the video at all.

I assume this is what you want to ask: “I want these 2 objects to stick together to form a single solid object under all rotations and scales etc.”

Make a parent object (which does not need an image of its own) and make the 2 body parts children of that object with local offsets from it.  The torso will have a positive Y offset and the legs will have a negative Y offset.  These should be stored in matrices.

When rendering, take the world matrix of the parent object and “propagate” it into all of its children.  In other words the parent has a world matrix and the 2 children have local matrices.  They need world matrices, and you get that by multiplying them with the parent’s world matrix.

That is, for each child, CHILD[i].WORLD_MATRIX = PARENT.WORLD_MATRIX * CHILD[I].LOCAL_MATRIX.

Draw using the childrens’ world matrices.  After this is done, any scaling, offsetting, or rotating done to the parent will correctly trickle down into the children.

L. Spiro

It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013

I went to my local Subway once to find some guy yelling at the staff.  When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

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