PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

path finding in 3D ? looking for information

I have discovered that the coordinate system used by PocketGL introduces errors when moving objects especially inter-related ones. eg: a rotating gun turret which has a barrel which goes in & out. As the object animates the barrel slowly moves out of allignment & I put this down to the rounding which goes on in the fixed maths coordinate system.

One possible solution would be to use some kind of path finding to force the barrel back to it's origin thus eliminating the errors.

Any advice will be gladly received. If I'm stuck I can just re-work the weapons so that none of them have this kind of movement but that seems the wrong way to go especially as I have some more complex meshes in mind for my next game.

(of course I could just have bugs in my code)
I have a hunch what you're doing, and if I'm right then you can't do it in that way. You must bind the objects together, or even with floating point math errors would accumulate causing the same problem.

The coordinate system of the child must be relative to the parent, not to the world. If you're doing the latter then that is your problem. Build a matrix stack representing the position and rotation of the parents and then transform the child by that.

Dan East
Dan, as you are always correct I will go with your suggestion. I'm not 100% sure how to go about it but I will spend a couple of hours tomorrow & only re-post if I get stuck.
Basically for my weapons I have a main 3d sprite with up to 2 child sprites. Each has a position & rotation vector & various counters & flags.
Up till now I have only had to do simple parent child things like rotate a dish on top of a base.
Code:

CMatrix44 matrix;
matrix.LoadIdentity();
matrix.Translate(&parent;_pos);
matrix.RotateX(parent_rot.x);
matrix.RotateY(parent_rot.y);
matrix.RotateZ(parent_rot.z);

Vector4s worldpos;
matrix.Transform(&child;_pos, &worldpos;);


Note that doesn't transform the rotation of the child, just the position. child_pos should be relative to the parent, not the world.

Dan East
thanks Dan, I will implement this tomorrow.
Is your animation hard-coded or are you using some sort of keyframing system for the animation?
I've learned a lot about object linking by writing a realtime 3d-studio keyframing engine...
Conan · 03 Dec 2003, 18:49 UTC — thanks Dan
Dan, your advice was correct. I made the child's movement relative to the parent & removed the rotation from the child before calculating it's movement & the child now moves correctly, ie: the gun barrel goes out & in from the turrel like it's supposed to. As I have 8 weapon types including several with some parent/child arrangement it was vital to solve this.

Now as you know you have solved several of my big problems with 3D :lol: so how about me buying you a beer (or a case of beer to be precise) just to say thanks. As I'm in sunny Scotland I can't invite you down the pub so if you use paypal can you email me an email address to use & the price of a crate of beer in your neck of the woods & I will send you some cash to enjoy a beverage or two on me.

I still need some path finding to navigate ships but I will sit my wife down at the weekend & get some help as she's a maths teacher.

Re: the question about hard coding animation, yes at present I am coding the animation based on specific objects' requirements. Most objects are simple single mesh things so with only 8 weapons & a few other multi-mesh moving part items it's easy enough to do manually but as I do it I'm thinking about how to script an animation. Seems hard when every item is different.
Since you're still looking for information on path-finding, maybe you want to check this out:

http://www.d.kth.se/~f93-maj/pathfinder/3.html
I had a read. It's mostly to do with the more typical 2d path finding where sprites have to navigate obstacles on terrain to get to where they are going.

What I need to do is guide a missile from xyz-A to xyz-B. I don't think this will be very hard to achieve but I will see what my wife says when she gets the problem to work on.