Noob: How do I move a node in a forward direction?

Irrlicht.Net is no longer developed or supported, Irrlicht.Net Cross Platform is a much more complete wrapper. Please ask your C# related questions on their forums first.
Locked
robpearmain
Posts: 12
Joined: Mon May 22, 2006 2:56 pm

Noob: How do I move a node in a forward direction?

Post by robpearmain »

Hi,

My node is at position(0,0,0)
It is rotated so that node.Rotation.Y=45

I want it to move forward in that direction by 2

How can I do that?

Cheers
robpearmain
Posts: 12
Joined: Mon May 22, 2006 2:56 pm

This kind of works

Post by robpearmain »

Code: Select all

        public void Move(ISceneNode node, float speed)
        {

            Vector3D v = node.Position;
            Vector3D r = node.Rotation;

            v.X = v.X + (float)((Math.Cos(r.Y * 3.14159265 / 180) * speed));
            v.Z = v.Z - (float)(Math.Sin(r.Y * 3.14159265 / 180) * speed);

            node.Position = v; 


        }
DeusXL
Posts: 114
Joined: Sun Mar 14, 2004 9:37 am
Contact:

Post by DeusXL »

There may be a problem with more complex movements/rotations... I prefer (with irrlicht) to use Node.AbsoluteTransformation :

Code: Select all

Vector3D pos = Node.Position;
Matrix4 mat = Node.AbsoluteTransformation;
pos += new Vector3D(mat.get_M(0, 0) * fwdmov * coeff,
                   0,
                   mat.get_M(2, 0) * fwdmov * coeff);
Node.Position = pos;
Where fwdmov is a float reprensenting the amount of movement and coeff may be used for time synchronisation... (then your "speed" is equal to "fwdmov * coeff")
Irrlicht .NET complete and Cross Platform Wrapper
The kid on my avatar wrote:A painless lesson is one without any meaning
robpearmain
Posts: 12
Joined: Mon May 22, 2006 2:56 pm

Awesome, many thanks

Post by robpearmain »

Thanks
needforhint
Posts: 322
Joined: Tue Aug 30, 2005 10:34 am
Location: slovakia

Post by needforhint »

set the node as a child of camera, thus child is placed ralativly to his parent, and the parent iz the zero coordinate for that relative space. thus if you higher lover z value it will move from you, as you can see in my example here http://www.medeal.sk/irr/newstress.zip
what is this thing...
Locked