Thanks for code snippet explaining rotation of objects using mouse events.
my specific questions are:
#1 - when creating a world and then a camera, what is the default position of camera in the world?
#2 - when loading an .obj mesh, does jPCT place the model in its default position which was used while creating the model? (whilst designing the model, it could have a desired distance from 0,0,0)
#3 - why do we have to use third line in the below code?
Camera cam=world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEUP, distance);
--> cam.rotateCameraX((float)Math.PI/2f);
================code for roatting object using mouse========
import com.threed.jpct.*;
import com.threed.jpct.util.*;
import org.lwjgl.opengl.*;
import org.lwjgl.input.*;
/**
* A Simple demo for mouse-powered object viewing.
* It offers two modes: Camera around object (default) and object "around" camera.
*/
public class GoogleCube {
private static float distance=50;
// If true, the object transforms related to the camera. If false, the camera to the object.
private static boolean affectObject=false;
public static void main(String[] args) throws Exception {
World world=new World();
FrameBuffer buffer=new FrameBuffer(640, 480, FrameBuffer.SAMPLINGMODE_HARDWARE_ONLY);
buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
buffer.enableRenderer(IRenderer.RENDERER_OPENGL);
Object3D cube=Primitives.getSphere(15);
world.addObject(cube);
cube.build();
Camera cam=world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEUP, distance);
cam.rotateCameraX((float)Math.PI/2f);
world.setAmbientLight(100, 100, 100);
Light light=new Light(world);
light.setIntensity(0, 0, 255);
light.setPosition(new SimpleVector(-100, 0, 0));
Mouse.create();
while (!Display.isCloseRequested() && !Mouse.isButtonDown(1)) {
buffer.clear();
world.renderScene(buffer);
world.draw(buffer);
buffer.update();
buffer.displayGLOnly();
int x=Mouse.getDX();
int y=Mouse.getDY();
int w=Mouse.getDWheel();
if (Mouse.isButtonDown(0)) {
SimpleVector line=new SimpleVector(x, 0, y);
Matrix m=line.normalize().getRotationMatrix();
if (affectObject) {
// Object "around" camera
cube.rotateAxis(m.getXAxis(), line.length() / 200f);
} else {
// Camera around object
m.rotateAxis(m.getXAxis(), (float) -Math.PI/2f);
cam.moveCamera(Camera.CAMERA_MOVEIN, distance);
cam.rotateAxis(m.invert3x3().getXAxis(), line.length() / 200f);
cam.moveCamera(Camera.CAMERA_MOVEOUT, distance);
}
}
if (w!=0) {
float d=w/200f;
if (affectObject) {
cube.translate(0, -d, 0);
} else {
distance-=d;
cam.moveCamera(Camera.CAMERA_MOVEIN, d);
}
}
Thread.sleep(10);
}
Mouse.setGrabbed(false);
Mouse.destroy();
buffer.disableRenderer(IRenderer.RENDERER_OPENGL);
buffer.dispose();
}
}
==========================================