About Store Forum Documentation Contact
Donations:
158$/mo



Post Reply 
continous object rotation
Author Message
DoerrSt Offline
Member

Post: #1
continous object rotation
Hello,

I created my own object class derrived from Game.Chr.

The only thing this should doing is to rotate at Y axis. As I am just beginning with Esenthel it looks like I have to insert the code into the update-function:

float rot = 1;


bool update()
{
super::update();
rot++;
if(rot>360) rot=0.0;

Matrix m = T.matrix();
m.rotateY(DegToRad(rot));
T.matrix(m);
return true;
}


If I use this code it looks like the object is moved away. With rotateZ I see it moving very fast away from the position instead of rotating.

What I am doing wrong? And - is there a basic guide about programming for Esenthel?

Thanks!
02-13-2014 01:16 AM
Find all posts by this user Quote this message in a reply
Rubeus Offline
Member

Post: #2
RE: continous object rotation
For tutorials, there's a few user-created tutorial videos on this forum. There's also a bunch of them included with EE in the Tutorials project.

As for the code, keep in mind that you are calling update each frame, so the first frame you are rotating by 1', then by 2', then by 3', etc. If you just rotate by 1, you will continue rotating by 1 each frame. Rotate by Time.d() * a_speed to have a framerate independent rotation.

Also, if you are using a class that uses a physics object, you want to modify it via applying forces, such as T.actor.addAngVel(Vec(0, 1, 0)); (or .ctrl.actor ).
02-13-2014 04:40 AM
Find all posts by this user Quote this message in a reply
DoerrSt Offline
Member

Post: #3
RE: continous object rotation
Hello Rubeus,

thank you for your explanation. Now it's clear what I am doing wrong.

After changing the speed I can now see that the object moves into a direction instead of the expected rotation. Any explanation for this?

Stefan
02-13-2014 11:30 AM
Find all posts by this user Quote this message in a reply
Rubeus Offline
Member

Post: #4
RE: continous object rotation
Is it moving in a straight line, or in a circle?

If it's moving in a straight line, somewhere along the way, the position is getting modified.
If it's moving in a circle, then the rotation is probably multiplying by the translation matrix. I'm working from memory here, but isn't there something like m.orn().rotateY that you can try? Or maybe it's something like m.rotateL(Vec(0,DegToRad(rot),0));
02-13-2014 03:17 PM
Find all posts by this user Quote this message in a reply
DoerrSt Offline
Member

Post: #5
RE: continous object rotation
Thanks Rubeus!

I just got it to work, also if I don't understand what's the difference between the both codes:

This one works:

bool update()
{
Matrix m = T.matrix();
m.orn().rotateY(Time.d()*1);
T.matrix(m);
return true;
}

and this code causes that I don't see the object at all:

bool update()
{
Matrix m = T.matrix().orn();
m.rotateY(Time.d()*1);
T.matrix(m);
return true;
}

From my point of view it should have the identical result, or?
02-13-2014 05:13 PM
Find all posts by this user Quote this message in a reply
Rubeus Offline
Member

Post: #6
RE: continous object rotation
Matrix m = T.matrix().orn();

Matrix is a 4x4 matrix(16 elms). Orn is the transformation matrix, a 3x3 matrix(9 elms) that holds everything but the position. Basically, the reason you don't see the object is because its position is an uninitialized vector. smile
02-13-2014 08:37 PM
Find all posts by this user Quote this message in a reply
xzessmedia Offline
Member

Post: #7
RE: continous object rotation
rubeus your anwers are always very interesting for me they are very clear and understandable and a source of information. thank you smile
02-13-2014 08:44 PM
Find all posts by this user Quote this message in a reply
DoerrSt Offline
Member

Post: #8
RE: continous object rotation
Thank you for you explanation. I need to confirm that not only the engine looks good, also the community is nice!
02-13-2014 10:42 PM
Find all posts by this user Quote this message in a reply
Rubeus Offline
Member

Post: #9
RE: continous object rotation
Aw shucks. Glad to help.
02-14-2014 05:13 PM
Find all posts by this user Quote this message in a reply
Post Reply