### Author Topic: obj.lookAt ()  (Read 4750 times)

#### Melssj5

• double
• Posts: 724
##### obj.lookAt ()
« on: June 21, 2006, 07:55:47 am »
Is there anyway to implement this method into the Object3D, it may be usefull, I need to make an object3D to look at (0, 0, 1), but I dont know its actual direction, of course I cant get the zAxis and calc a angle and the rotate it, but it will be kind of messy. If anyone have another idea, please post it. I have no another object to align with!

#### EgonOlsen

• Posts: 12244
##### obj.lookAt ()
« Reply #1 on: June 22, 2006, 01:11:37 am »
Subtract the object's center in world space from the (0,0,1) vector to get the vector pointing from the object to (0,0,1). Use SimpleVector.getRotationMatrix() on this vector and feed the resulting matrix back into the object as its new rotation matrix.

#### Melssj5

• double
• Posts: 724
##### obj.lookAt ()
« Reply #2 on: June 22, 2006, 05:35:07 am »
:cry:  :cry:

what? I am afraid I am a fool about this kind of things. I better look for another way to do it.

#### EgonOlsen

• Posts: 12244
##### obj.lookAt ()
« Reply #3 on: June 22, 2006, 08:41:17 am »
Code: [Select]
SimpleVector la=new SimpleVector(0,0,1);
la=la.calcSub(obj.getTransformedCenter());
obj.setRotationMatrix(la.getRotationMatrix());

#### mogli

• byte
• Posts: 38
##### obj.lookAt ()
« Reply #4 on: August 22, 2006, 03:33:25 am »
i have a similar problem.

i need an object that look at a point in the world.
but my problem is that this object needs to orientated at the camera direction.
this
Code: [Select]

SimpleVector la=world.getObjectByName("xx.3ds").getCenter();
la=la.calcSub(camera.getPosition());
obj.setRotationMatrix(la.getRotationMatrix());

points to the right in the world but it doesn't notice that camera has turned...

hope you could understand what i mean and help me...

#### EgonOlsen

• Posts: 12244
##### obj.lookAt ()
« Reply #5 on: August 22, 2006, 12:23:33 pm »
Quote from: "mogli"
hope you could understand what i mean and help me...
No, i don't really understand. You want the object to "look" at a point in world space but you want it to look into the camera's direction as well ?

#### Melssj5

• double
• Posts: 724
##### obj.lookAt ()
« Reply #6 on: August 23, 2006, 12:32:31 am »
Well, I guess that he needs that the object is aligned with the camera (direction only) and looking at the point on the world at the same time.