This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts Menu
public SimpleVector rotateRespect2Cam(float rotX, float rotY)
{
SimpleVector dir = theCamera.getDirection();
dir.rotateX(rotX);
dir.rotateY(rotY);
return dir.calcSub(theCamera.getDirection());
}
SimpleVector rotate = rotateRespect2Cam(delta.x * -camRotSpeed, delta.y * -camRotSpeed);
object.rotateX(rotate.x); // rx rz ry to avoid gimbal lock.
object.rotateZ(rotate.z);
object.rotateY(rotate.y);
Quote from: Hrolf on October 29, 2007, 02:13:51 AM
A tutorial would be good! Can't we wiki it somehow? Then we could all help out...
Quote from: hthth on October 28, 2007, 04:42:16 PM
EDIT: This, of course, does not depend on the user actually grabbing the sphere. If that's an issue then you could use Interact2D to check if the user is actually clicking on the sphere or not, and then calculating the distance from that point to the center of the sphere (instead of calculating the distance from the click and to the center of the screen).
QuoteThe main idea is to think in terms of arc intervals. If we have two arbitrary points A and B on the surface of a unit sphere, the most natural way to get from A to B is to rotate the sphere so that A follows the shortest path (or geodesic) from A to B. Thus the rotation occurs in the plane of the geodesic. If a = (xa, ya, za) and b = (xb,yb,zb) are the position vectors of the points, the axis of rotation is given by a 5 b. The angle of the rotation can be obtained from cos-1 (a × b).
How do we get from 2D mouse coordinates to 3D rotations? We construct a pseudo-3D coordinate space as follows. (This is essentially the method of Shoemake in Graphic Gems IV, p. 176.) Superimpose an imaginary sphere on our 3D object such that the center of the sphere is at the position vector c = (screen_x, screen_y, 0), where screen_x and screen_y are the local screen coordinates of the center of the object. We assume that any mouse-downs will happen on the surface of our imaginary sphere, which has a radius of r pixels.
Quote from: hthth on October 28, 2007, 03:12:52 PM
You'd just calculate the X/Y deltas of the mouse-drags and feed those distances into the rotation methods. The other thing you could do is keep the object still and rotate the camera around the object instead (in that case look at the Camera class documentation for rotation).
private void drawLine(FrameBuffer fb, Graphics2D g, SimpleVector v1, SimpleVector v2)
{
SimpleVector point1 = Interact2D.project3D2D(theWorld.getCamera(), fb, v1);
SimpleVector point2 = Interact2D.project3D2D(theWorld.getCamera(), fb, v2);
if(point1 != null && point2 != null)
{
g.drawLine((int)point1.x, (int)point1.y, (int)point2.x, (int)point2.y);
} // if
}
Page created in 0.026 seconds with 13 queries.