Home > Back-end >  Mouse and keyboard java3d linkage problems
Mouse and keyboard java3d linkage problems

Time:10-01

Strives for the big help, the younger brother grateful!

Recently has been stuck in one place, more than a week now,
Made a java3d, mouse and keyboard in linkage is something wrong with the above, I want to make "mouse, keyboard will continue movement according to the direction of the mouse after the rotation, but I my application results after rotating object is the mouse, keyboard and press down will return to its original position,
Feeling should be the object using the above make a mistake, but where is the specific error is can't find,
Now is to achieve the object related to place my card for a long time, there is multithreaded, mysql, redis, file operations, high concurrency, all want to use on the project, the graduation design all don't know when will it be ready, before the end of may be on June 10th will reply, I good food!!!

Why use java3d anything so old, I wrote a feeling: https://liu-endong.blog.csdn.net/article/details/104854301

 
The Main. Java
as followsPackage keyMouse;


The import com. Sun. J3d. Utils. Universe. *;
The import com. Sun. J3d. Utils. Applet. The MainFrame;
The import com. Sun. J3d. Utils. Geometry. The Box;
The import javax.mail. Media. J3d. *;
The import javax.mail. Vecmath. *;
. Import the Java applet. The applet;
Import the Java. The awt. *;

/*
* Simple Java 3 d example to display a rotating color cube.
*/
Public class Main extends the Applet {

//Constructor
The public the Main () {
//Setup a SimpleUniverse by referencing a Canvas3D
SetLayout (new BorderLayout ());
GraphicsConfiguration config=SimpleUniverse. GetPreferredConfiguration ();
Canvas3D c=new Canvas3D (config);
Add (" Center ", c);

//setting watchpoints
Viewer Viewer=new Viewer (c);
Vector3d viewPoint=new Vector3d (0.0, 1, 10.0);
The Transform3D t=new the Transform3D ();
T.s et (viewPoint);
ViewingPlatform v=new ViewingPlatform ();
V.g etViewPlatformTransform (.) setTransform (t);

BranchGroup scene=createSceneGraph ();
SimpleUniverse u=new SimpleUniverse (v, viewer); With 3 d canvas instance c//create a viewing platform and a local single observer object
U.g etViewingPlatform ();
U.a ddBranchGraph (scene);

}

//Create the content branch
Public BranchGroup createSceneGraph () {
//Create the root node of the content of branch
BranchGroup objRoot=new BranchGroup ();

//Create the TransformGroup node, which is writable to support
//animation, and add it under the root
The Transform3D t3d=new the Transform3D ();
T3d. SetScale (0.1);

The Appearance app=new Appearance ();
Material Material=new Material ();
Material. SetEmissiveColor (1 f, 0 f, 0 f);
App. SetMaterial (material);
Box cubeBox=new Box (5 f, 1 f, 5 f, app);//(long, wide, high, appearance)
//group. The addChild (cubeBox);

TransformGroup objScale=new TransformGroup (t3d);
ObjScale. SetCapability (TransformGroup. ALLOW_TRANSFORM_WRITE);
ObjScale. SetCapability (TransformGroup. ALLOW_TRANSFORM_READ);
ObjScale. AddChild (cubeBox);

BoundingSphere bound=new BoundingSphere (new Point3d (1.0, 2.0, 3.0), 1.0);

//define the event object
Key myBehavior=new Key (objScale objRoot, bound).
MyBehavior. SetSchedulingBounds (bound);
ObjScale. AddChild (myBehavior);

//mouse
//MouseRotate MouseRotate=new MouseRotate ();
//mouseRotate setTransformGroup (objScale);
//objRoot addChild (mouseRotate);
//mouseRotate setSchedulingBounds (bound);


//the Compile to perform optimizations on this content branch.
ObjRoot. AddChild (objScale);
ObjRoot.com from running ();
Return objRoot;
}

//Entry the main method to invoke the constructor on the eventdispatcher thread.
Public static void main (String args []) {

//Java awt. EventQueue. InvokeLater (new Runnable () {
//public void the run () {
//KeyMoveT2 liFangTi=new KeyMoveT2 ();
//}
//});
New MainFrame (new Main (), 800, 800);

}

}


Key. Java
as follows
 
Package keyMouse;

Import the Java. The awt. AWTEvent;
Import the Java. The awt. Event. KeyEvent;
Import the Java. Util. Enumeration;
The import javax.mail. Media. J3d. Behaviors;
The import javax.mail. Media. J3d. BoundingSphere;
The import javax.mail. Media. J3d. BranchGroup;
The import javax.mail. Media. J3d. The Transform3D;
The import javax.mail. Media. J3d. TransformGroup;
The import javax.mail. Media. J3d. WakeupCriterion;
The import javax.mail. Media. J3d. WakeupOnAWTEvent;
The import javax.mail. Vecmath. Vector3f;
The import com. Sun. J3d. Utils. Behaviors. Mouse. MouseRotate;

The class Key extends behaviors {
//set the related objects
Private TransformGroup targetTG;
Private the Transform3D transform=new the Transform3D ();
Private float x, y, z;

The public Key (TransformGroup targetTG BranchGroup BG, BoundingSphere BS) {
Enclosing targetTG=targetTG;
MouseRotate MouseRotate=new MouseRotate ();
MouseRotate. SetTransformGroup (targetTG);
BG. AddChild (mouseRotate);
MouseRotate. SetSchedulingBounds (BS);
}

@ Override
Public void the initialize () {
WakeupOn (new WakeupOnAWTEvent (KeyEvent. KEY_PRESSED));
}

@ Override
Public void processStimulus (Enumeration criteria) {
WakeupCriterion wakeup.
AWTEvent [] events;
Vector3f position=new Vector3f ();

//get the current event, judge whether the keyboard events
Wakeup=(WakeupCriterion) criteria. NextElement ();
If (wakeup instanceof WakeupOnAWTEvent) {
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related