rotation functions

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Skatebone
Posts: 15
Joined: Sat Sep 01, 2012 8:23 pm

rotation functions

Post by Skatebone »

What is wrong with these two functons?

Code: Select all

node.Rotation.RotationToDirection(camera.Target)
node.Rotation.RotateYZby(45)
I cant get the node to rotate without rotation animator..
Edit: i dont use the two functions together btw and I also tried the rotate via a vector. I cant see a way to bypass this with matrices and why are these functions not working properly? What am I doing wrong?

Code: Select all

        Dim node As AnimatedMeshSceneNode = smgr.AddAnimatedMeshSceneNode(mesh, Nothing, 2, New Vector3Df(60000, 0, 60000))
 
        If node <> Nothing Then
            node.SetMaterialFlag(MaterialFlag.Lighting, False)
            node.SetMD2Animation(AnimationTypeMD2.Wave)
            node.SetMaterialTexture(0, driver.GetTexture("dwarf.jpg"))
            node.SetFrameLoop(1, 13)
            node.AnimationSpeed = 15
            node.Scale = New Vector3Df(3)
            node.Rotation.RotationToDirection(camera.Target)
            node.Rotation.RotateYZby(45)
        End If
Thank you
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: rotation functions

Post by greenya »

You should write next:

Code: Select all

node.Rotation = node.Rotation.RotationToDirection(camera.Target)
node.Rotation = node.Rotation.RotateYZby(45)
Because node.Rotation returns a copy. Why? If it wouldn't return copy, next code is much "unexpected" then code above:

Code: Select all

Vector3Df r = node.Rotation;
r.X = 10;
// now node.Rotation.X is 10 also
P.S.: the only thing is come to my mind how to make it a bit clear, is to remove ability to set properties like Rotation by assigning to it a value. And add method SetRotation() instead. Well, i'm not sure about this change anyway.
Skatebone
Posts: 15
Joined: Sat Sep 01, 2012 8:23 pm

Re: rotation functions

Post by Skatebone »

Thanks green!

I did manage to get the node to rotate but my new problem is to get the direction vector of the rotation:

Here is my fail code:

Code: Select all

 
Dim tempx as integer = 0
If KeyStore(KeyCode.Right) = True Then
 
 Dim l1 As New Line3Df
l1.Set(node.Position, New Vector3Df(node.Position.X, 100, node.Position.Z - 100))
l1.Vector.RotationToDirection(New Vector3Df(0, tempx, 0))
node.Rotation = node.Rotation.RotationToDirection(New Vector3Df(0, tempx, 0))
 camera.Position = l1.End
 'camera.Target = New Vector3Df(node.Position.X, 100, node.Position.Z)
tempx += 1
End If
What I am trying to do is getting the camera to follow the rotation of my node.

The aim of my project is to try and design an mmorpg style camera. What I really want is to draw a line(preferibly visible; i used driver.draw3dline but couldnt get it working) perpendicular to my node so as when my node rotates, if i take the end point of the line, I can assign that to my camera, set the camera's target to my node and its done.

I know that my code wont work and I will need to work with dot product but I cant still manage to work it out as although I do know how vectors and matrices work I am new to this type of programming.

Thanks for your time green, Ireally appreciate :)
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: rotation functions

Post by greenya »

Try next:

Code: Select all

Vector3Df d = node.Rotation.RotationToDirection(new Vector3Df(1,0,0)); // try "1,0,0", "0,1,0" and "0,0,1"
camera.Position = node.Position + d * 100.0f; // try "+" and "-"; "100.0f" is a desired distance from node to camera
P.S.: after you update camera.Position you may need also to update camera.Target (e.g. "camera.Target = node.Position;").
Skatebone
Posts: 15
Joined: Sat Sep 01, 2012 8:23 pm

Re: rotation functions

Post by Skatebone »

It doesnt work, the camera simply goes up since the rotation is (0,x,0)

Look at mine:

Image

Code: Select all

 
Dim mt1 As New Matrix
driver.SetTransform(TransformationState.Texture0, mt1)
mt1.TranslateVector(New Vector3Df(0, 100, -100))
//Here I need to extract the resultant position of the camera from mt1! Grrr!
 
//This works because of: driver.SetTransform(TransformationState.Texture0, mt1)
driver.Draw3DLine(New Vector3Df(0, 0, 50), New Vector3Df(0, 100, -100), Color.OpaqueRed)
 
Also do I need to do this to fill the matrix?

Code: Select all

mt1 = driver.GetTransform(TransformationState.Texture0)
The Line is being drawn exacty as I want it. The start position will be the camera.Target and the end position will be the camera.position! How can I get those 2 vectors from the matrix? Thanks!
Last edited by Skatebone on Thu Sep 06, 2012 12:53 pm, edited 1 time in total.
Skatebone
Posts: 15
Joined: Sat Sep 01, 2012 8:23 pm

MMO camera

Post by Skatebone »

I did make some progress with the MMO (camera following object) project but still I cant understand why it isnt working..

Since

Code: Select all

driver.SetTransform(TransformationState.Texture0, New Matrix())
driver.Draw3DLine(New Vector3Df(0, 0, 50), New Vector3Df(0, 100, -100), Color.OpaqueRed)
//Where New Vector3Df(0, 100, -100) is the point where I want my camera position to be (relative to the object using texture0)  
So I tried:

Code: Select all

    Private Function CamBehindTarg(ByVal PositionVec As Vector3Df, Optional ByVal TransformState As Integer = 3) As Vector3Df
 
//Driver is setting the transformation matrix at Texture0 to empty.(so the direction of the object is currently 0 degrees)
//When I start rotating the object, the Texture0 also rotates, hence changing the matrix!
        driver.SetTransform(TransformState, New Matrix())
//So we copy the new matrix into our variable.
        Dim mt1 As Matrix = driver.GetTransform(TransformState)
//Now we input our position vector into the matrix.
        mt1.TransformVector(PositionVec)
//We return the translated position vector.
        Return PositionVec
    End Function
In Main loop:

Code: Select all

camera.Position = CamBehindTarg(New Vector3Df(0, 100, -100))
I dont know if this is really what is going on, I kinda need some guide for this :)
Also when debugging I noticed that mt1 is remaining as a unit matrix becuse PositionVec is being returned as inputted >.>
Thanks
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: rotation functions

Post by greenya »

If your question: why in next code "vec" doesn't get changed:

Code: Select all

            Vector3Df vec = new Vector3Df(0, 100, -100);
            Matrix mt1 = new Matrix();
            mt1.TransformVector(ref vec);
            // now vec == (0, 100, -100)
then answer is: because "mt1" is an identity matrix.
Skatebone
Posts: 15
Joined: Sat Sep 01, 2012 8:23 pm

Re: rotation functions

Post by Skatebone »

greenya wrote:If your question: why in next code "vec" doesn't get changed:

Code: Select all

            Vector3Df vec = new Vector3Df(0, 100, -100);
            Matrix mt1 = new Matrix();
            mt1.TransformVector(ref vec);
            // now vec == (0, 100, -100)
then answer is: because "mt1" is an identity matrix.
Yes I realised! Im trying to fill it in with the driver's transform martrix but its not working.

Any idea why? Thanks
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: rotation functions

Post by greenya »

You wrote:

Code: Select all

        driver.SetTransform(TransformState, New Matrix())
        Dim mt1 As Matrix = driver.GetTransform(TransformState)
What do you expect to be mt1?
Skatebone
Posts: 15
Joined: Sat Sep 01, 2012 8:23 pm

Re: rotation functions

Post by Skatebone »

greenya wrote:You wrote:

Code: Select all

        driver.SetTransform(TransformState, New Matrix())
        Dim mt1 As Matrix = driver.GetTransform(TransformState)
What do you expect to be mt1?
I expected to be the matrix which transforms the line!

When i draw the line it orks perfectly, the problem is that i cant get the translated coordinates.

Because when a texture rotates, the matrix transforms the vectors accordingly(thats the case of the line)
Post Reply