Cream
October 5, 2005, 9:01pm
1
private void doLineOfSightChase() {
Vector3f u = preypos.subtract(predpos).normalize();
float a = MathClass.radiansToDegrees(u.x);
float b = MathClass.radiansToDegrees(u.y);
float c = MathClass.radiansToDegrees(u.z);
System.out.println(a+" "+b+" "+c);
// Quaternion q = predator.getLocalRotation();
// q.toRotationMatrix().fromAxes(null,null,u);
/ predator.setLocalRotation(new Matrix3f(
1,0f,0f,
0f, FastMath.cos(FastMath.PI/180 a), -FastMath.sin(FastMath.PI/180a),
0f, FastMath.sin(FastMath.PI/180 a), FastMath.cos(FastMath.PI/180a)));////Y
/ predator.setLocalRotation(new Matrix3f(
FastMath.cos(FastMath.PI/180a),0f,FastMath.sin(FastMath.PI/180 a),
0f, 1f, 0f,
-FastMath.sin(FastMath.PI/180a), 0f, FastMath.cos(FastMath.PI/180 a)));//Z*/
predator.setLocalRotation(new Matrix3f(
FastMath.cos(FastMath.PI/180c),0f,FastMath.sin(FastMath.PI/180 c),
0f, 1f, 0f,
-FastMath.sin(FastMath.PI/180c), 0f, FastMath.cos(FastMath.PI/180 c)));//Z
predator.setLocalTranslation(predpos.add(u.mult(0.005f)));
predator.setLocalRotation(new Matrix3f(
FastMath.cos(FastMath.PI/180a),-FastMath.sin(FastMath.PI/180 a),0f,
FastMath.sin(FastMath.PI/180a), FastMath.cos(FastMath.PI/180 a), 0f,
0f, 0f, 1f));
// predator.setLocalRotation(q);
}
i want to rotate this predator to the direction found on top
as you can see i tried out different things, nothing worked.
As i am not the algebra guy i would be pleased if some guy can tell me how to rotate to something like (35

Paigan
October 6, 2005, 9:23pm
2
hehe
I had the same problem when starting with jME.
So let me try and help
Always use quaternions for rotation.
How do you create the right quaternion for your desired roation?
You have various options for this:
The three most intuitive, for my taste, are:
fromAxis() :
here you need the “direction”, “left” and “up” vectors
where “direction” would be the direction the model is facing,
“left” is the vector that points to the ‘left hand’ direction and
“top” is what would be a ‘vertical’ vector of a person standing on the ground
all three vectors stand right-angled to each other.
and all three vectors must have the length 1 (normalized)
The Camera is a good example for this.
Look at the getDirection(), getLeft() and getUp() methods in AbstractCamera
You get right-angled Vectors by using the .cross() method of Vector3f (smells like Maths here…)
Example :
fromAxis(new Vector3f(1,0,0), new Vector3f(0,1,0), new Vector3f(0,0,1));
fromAngleAxis() :
Specify the axis around which the object should be rotated and the angle (radien)
Example :
turn right by 90

Cream
October 6, 2005, 6:46pm
3
how do i rotate quaternion localrotation to vector u
thats my question

Cream
October 6, 2005, 6:56pm
4
private void doLineOfSightChase() {
Vector3f u = preypos.subtract(predpos).normalize();
predator.setLocalTranslation(predpos.add(u.mult(0.005f)));
float a = MathClass.radiansToDegrees(u.x);
float b = MathClass.radiansToDegrees(u.y);
float c = MathClass.radiansToDegrees(u.z);
Quaternion x = new Quaternion(a,1,0,0);
Quaternion y = new Quaternion(b,0,1,0);
Quaternion z = new Quaternion(c,0,0,1);
Quaternion ss = x.slerp(y,z,1f);
predator.setLocalRotation(ss);
}
does not do anything anyway
and until i fail on this rotation i can leave out to move on

Cream
October 6, 2005, 9:31pm
5
so i don't know which angle to rotate on
i don't know the degree what i want to rotate
i only know the ending direction vector i want to reach
thats vector u
as i can see none of these approaches let's me reach the goal i need.
I have to make the object face direct to vector u instead of the localRotation quaternion.
it would even be the easiest only to set this as the new rotation, while i don't need to keep time decisions in this approach into it, but even that can't be done without touching the quaternion.
Let me explain it once:
I have one object sitting somewhere in space.
He's noticing another object in space and begins to chase it.
So he runs after it.
That's really quite easy.
But in my nower implementation if the other object is on the upper left my object is running into the right direction facing its origin state, that looks quite a bit like a car race while all cars ride sideways at fullspeed, ride through those curves really close without any rotation.
these transformation work, but i have to face the direction u i am actually moving.
I don't know which angle it is nor which degree.
I only know the result vector in 3D space

Cream
October 6, 2005, 9:39pm
6
Quaternion quat = new Quaternion(0,u.x,u.y,u.z);
predator.getLocalRotation().slerp(quat,1f);
This is what i got now and the result does look quite well.
Any suggestion that this is wrong ?

Paigan
October 6, 2005, 9:53pm
7
I don't have experience with setting the four floats of a quaternion directly.
If this works for you, good
But simply leaving one of them zero looks a bit strange to me.
To the other three methods:
If you only have a vector to an object, then degrees won't help you, sure.
But you can't just make
"fromAxes(null,null,u);"
because of Math:
just one Vector is not enough information to define a rotation.
U could be the direction, okay. But then the object could be set to any degree around this vector
(think of a space shuttle "rolling" around its flight direction)
that is why you need the other right-angled vectors.
try something like that:
(direction = u)
left = u.cross(new Vector(0,1,0))
up = u.cross(left)
(plus normalize(), of course)
this let's an object face another object, when u is the difference vector between both objects.
I created a nice halo with this formula
(a plane with a shiny round circle that always faces the camera, so that it looks like it would be a glowing sphere)
By the way:
Try not to post every new thought in a seperate posting but edit your last one, if nobody has answered yet

Cream
October 6, 2005, 10:03pm
8
this really looks better !