views:

173

answers:

3

Hello,

I'm developing a interactive eye follower. I want to rotate 2 spheres according to mouse movement. These spheres are representing the eyeballs.What is the best way to do this? I need to find the vector which points to the direction of the mouse current position, but i don't know how to find the rotation matrix for ball rotation. I am using silverlight+kit3d, but this is not relevant.. it could be opengl, directx or anything.. Thanks,

A: 

Do you really want to implement it or just use it. I have one similar one as a gadget in igoogle. you can search igoogle for one if you want.

ckv
Hey thanks, but I've prefer doing it myself. Thanks anyway : )
jose
+1  A: 

Ok i think this should work

picture at imagebin.ca/img/Bz7zhY.png

30 is the distance of the mouse cursor from the centre of the screen (or the centre of the eye on the screen if you want them to move independently).

25 is the distance of the eye from the screen (Z axis)

This is only for one axis (X or Y) you need todo this for each axis

tm1rbrt
But the mouse and the model have different coordinate systems..
jose
Not necessarily, you can think of the 2d screen plane as a plane in your 3d world and size/position the eyeballs relative to that. That way it saves you another layer of math/transforms converting screen space into world space.
tm1rbrt
@tm1rbrt - I think the problem with the image was the "http:" in the alt text
ChrisF
+1  A: 

There is a paper by Möller and Hughes from the Journal of Graphics Tools called "Efficiently Building a Matrix to Rotate One Vector to Another" that is exactly what you want. There is also example code available.

Given your specific problem, you can probably simplify things a bit from the exact procedure suggested in the paper.

comingstorm
That's exactly what i need. great answer.
jose