Help: TransformVect in C#

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
Kikketer
Posts: 9
Joined: Fri Nov 11, 2005 3:41 pm
Location: Wisconsin
Contact:

Help: TransformVect in C#

Post by Kikketer »

When I attempt to use a Matrix4 to calculate forward movement of my node I run into trouble when attempting to use the .TransformVect() method.

my Matrix4 is called mov.

I have a seperate class that has all the information about my node (like current position and speed type things). So from what I understand you send the TransformVect a new Vector3D of the position that the node should move in...

So say the CurrentPosition property of my class is Vector3D(0,0,0) and I want to move it forward I do the following:

Code: Select all

mov.SetRotaionDegrees(node.Rotation) // the node is set to my seperate class
mov.TransformVect(myObject.NewPosition)
The .NewPosition is the transformed position: Vector3D(0,0,3)

The problem is at TransformVect, it is trying to use a ref. How do I pass back a ref variable of my new Vector3D?
- Give a weed an inch, it'll take a yard -
Mianpe

Post by Mianpe »

I'm not exactly sure what you are asking, but the TransformVect method just transforms the Vector3D that you pass it using the translation/rotation that you set earlier. So you do like:

mov.SetRotaionDegrees(node.Rotation)
mov.TransformVect(ref myObject.CurrentPosition)

and now myObject.CurrentPosition will be the new transformed location.
Kikketer
Posts: 9
Joined: Fri Nov 11, 2005 3:41 pm
Location: Wisconsin
Contact:

Post by Kikketer »

I guess what I'm really asking is how do I transform a node from one position to another based on time (not speed of the loop). I made a simple thing where my node was flying along the Z axis by simply adding to the Z coordinate, but this proved to go at different speeds depending on the speed of the system.

How can I say "Move from (0,0,0) along the Z axis at 9 points per second"?

Thanks
- Give a weed an inch, it'll take a yard -
Mianpe

Post by Mianpe »

Personally, I keep a DateTime variable called LastUpdate and each time I enter the loop I do something like:

float timeDiff = (float)DateTime.Now.Subtract(LastUpdate).TotalMilliseconds;
LastUpdate = DateTime.Now;

Then I can translate an object based on it's velocity:

Matrix4 mat = new Matrix4();
Vector3D trans = new Vector3D();
trans -= myObject.Velocity * -timeDiff;
mat.SetTranslation(trans);
mat.TranslateVect(ref myObject.Position);

In your example, the velocity would be:
Vector3D Velocity = new Vector3D(0, 0, 0.009);


(As a side note, it seems that Irrlicht.NET doesn't let you add Vector3D objects, but it will let you subtract them. This seems odd to me.)

Hope that helps.
Kikketer
Posts: 9
Joined: Fri Nov 11, 2005 3:41 pm
Location: Wisconsin
Contact:

Post by Kikketer »

This may sound incredibly noob but I can't seem to get it to work with the ref keyword. If I use a property the compliler tells me that ref can't be used with properties or indexes. When I create a get method the compiler tells me that the argument must be an IValue...

I'm going to keep trying stuff,

Thanks
- Give a weed an inch, it'll take a yard -
Mianpe
Posts: 1
Joined: Tue Nov 15, 2005 3:00 pm

Post by Mianpe »

True, you can't pass a property as a ref parameter (that's a .NET thing not an Irrlicht thing). My example assumes a public Vector3D variable "Position".

If you want to use a property (i.e. if you have code to execute when getting CurrentPosition), you would need to do:

Vector3D pos = myObject.CurrentPosition;
mat.TranslateVect(ref pos);
myObject.CurrentPosition = pos;
Locked