Recommended Posts

Alright, I have two objects, let's call them A and B. They each contain a position, rotation, and scale (PRS for simplicity) to describe themselves in the world. Let's say the objects are set up as follows:
Note: rotations are in degrees
I want to be able to figure out two things:
First, Given both objects' world PRS, I want to find object B's relative PRS
Second, Given object A's world PRS and object B's relative PRS, I want object B's world PRS.
The more simple you explain the math, the more likely I'll understand it. Assume I know only the basics about trig.
For those that want to know why, I want to take an object that's in world coordinates, and make it a child of another object while maintaining it's actual PRS.

Share this post

Link to post

Share on other sites

But what about for arbitrary values for any of the PRS components? Like if object A's rotation were 26 degrees instead of 0? Or if it's scale.x were 1.3? Keep in mind, I also need relative rotation and scaling.

Edit: An exampleLet's say I'm playing Super Smash Brothers Brawl. I find the fan item and pick it up. Then let's say I get the growth mushroom. The fan scales with me, rotates with me, and moves with me because it is positioned and whatnot relative to me. Then let's say I drop it. The fan no longer moves, rotates, or scales with me, but it stays where I drop it because it is now positioned relative to the world. I want to figure out the transition from object space to world space and back using my PRS structure.

0

Share this post

Link to post

Share on other sites

What I would do is simply have a variable for the parent object. So like your example, the parent would be the player. If there is a parent, the position and scale would be relative to the player. I would also keep track of the old position. So the object's position would be relative to the player's hand. So we have the actual position and the old position. The old position gets updated just like the actual position relative to the player. But when there is no parent, we set set the actual position with the old position, which doesn't get updated anymore. let me try to explain it with code...

Entity parent;Coord oldPositionCoord position

// This is called when there is no longer a parent entitylostParent(){ position = oldPosition;}

Share this post

Link to post

Share on other sites

I just realized the renderer does the object space to world space conversion every frame, and I can just ask that for the derived PRS data. There's half of the problem solved.

But that still leaves the problem of getting the world space to object space conversion. Your idea would have worked with little modification were it not for the fact that I use the data directly in the renderer's scene graph.