[java] Quake style Mouse Behaviour
Hi,
Has anybody ever done a Quake style Mouse Behaviour? (MouseLook)
I am currently trying. And I just cant get it to animate smoothly. If somebody has achieved this, please give me a hint.
Here is my solution. I have also tried it different: Using the mousebehavior to update mouse data and a Wakeuponelapsedframes for updating the Viewport, but same outcome.
The robot is a Robot class I use for positioning the mouse back to the center, when it is being moved. I checkd on this, the Robot.mouseMove take only about 0.1 ms to execute, so that shouldnt be the problem.
public class SimpleMouse extends Behavior
{
public boolean isInitialized = false;
public Point mousePosition = null;
private WakeupOnAWTEvent wakeUpEvent = null;
TransformGroup vp = null;
Frame f = null;
Transform3D rotX = null, rotY = null;
public SimpleMouse(SimpleUniverse u, Frame f)
{
super();
this.vp = u.getViewingPlatform().getViewPlatformTransform();
this.f = f;
rotX = new Transform3D();
rotY = new Transform3D();
f.setCursor(Cursor.CROSSHAIR_CURSOR);
}
public void initialize()
{
rotX.set(Transform3D.IDENTITY);
rotY.set(Transform3D.IDENTITY);
wakeUpEvent = new WakeupOnAWTEvent(MouseEvent.MOUSE_MOVED);
setSchedulingBounds(new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 1000d));
wakeupOn(wakeUpEvent);
isInitialized = true;
}
public void processStimulus(Enumeration e)
{
while (e.hasMoreElements())
{
//WakeupOnAWTEvent ev = (WakeupOnAWTEvent);
if (e.nextElement() != wakeUpEvent)
continue;
AWTEvent[] events = wakeUpEvent.getAWTEvent();
for (int i = 0; i < events.length; i++)
{
if (events instanceof MouseEvent)
{
MouseEvent me = (MouseEvent)events;
mousePosition = me.getPoint();
processMouse();
}
}
}
wakeupOn(wakeUpEvent);
}
private void processMouse()
{
Transform3D temp = new Transform3D();
//temp.set(Transform3D.IDENTITY);
temp.rotX((f.getHeight() / 2 - mousePosition.y) * 0.0006d);
rotX.mul(temp);
//temp.set(Transform3D.IDENTITY);
temp.rotY((f.getWidth() / 2 - mousePosition.x) * 0.0006d);
rotY.mul(temp);
//rotY.mul(rotX);
Transform3D t = new Transform3D();
//vp.getTransform(t);
//t.set(Transform3D.IDENTITY);
t.mul(rotY);
t.mul(rotX);
vp.setTransform(t);
MoveTest.robot.mouseMove(f.getX() + (f.getWidth() / 2), f.getY() + (f.getHeight() / 2));
}
}
</i>
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement