Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


[java] Quake style Mouse Behaviour

This topic is 6260 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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[i]; 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)); } }

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!