Source Code Cross Referenced for HoverBehavior.java in  » 6.0-JDK-Modules » java-3d » org » jdesktop » j3dfly » utils » vpbehaviors » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » java 3d » org.jdesktop.j3dfly.utils.vpbehaviors 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  $Header: /cvs/j3dfly/J3dFly/src/org/jdesktop/j3dfly/utils/vpbehaviors/HoverBehavior.java,v 1.1 2005/04/20 21:05:13 paulby Exp $
003:         *
004:         *                         Sun Public License Notice
005:         *
006:         *  The contents of this file are subject to the Sun Public License Version
007:         *  1.0 (the "License"). You may not use this file except in compliance with
008:         *  the License. A copy of the License is available at http://www.sun.com/
009:         *  
010:         *  The Original Code is Java 3D(tm) Fly Through.
011:         *  The Initial Developer of the Original Code is Paul Byrne.
012:         *  Portions created by Paul Byrne are Copyright (C) 2002.
013:         *  All Rights Reserved.
014:         *  
015:         *  Contributor(s): Paul Byrne.
016:         *  
017:         **/
018:        package org.jdesktop.j3dfly.utils.vpbehaviors;
019:
020:        import java.awt.event.ComponentEvent;
021:        import java.awt.event.MouseEvent;
022:        import java.awt.event.KeyEvent;
023:        import java.awt.AWTEvent;
024:        import java.awt.Component;
025:        import java.awt.Cursor;
026:        import javax.swing.SwingUtilities;
027:
028:        import javax.media.j3d.WakeupOnAWTEvent;
029:        import javax.media.j3d.WakeupOnElapsedFrames;
030:        import javax.media.j3d.WakeupOr;
031:        import javax.media.j3d.WakeupCriterion;
032:        import javax.media.j3d.WakeupCondition;
033:        import javax.media.j3d.TransformGroup;
034:        import javax.media.j3d.Transform3D;
035:        import javax.media.j3d.View;
036:
037:        import javax.vecmath.Vector3f;
038:
039:        /**
040:         <P>This behavior will allow the user to move to any point in 3 space whilst 
041:         maintaining the orientation of -ve Y is down.</P>
042:         <P>All controls are provided by the mouse. Each mouse button
043:         generates a different type of motion while the button is pressed, the
044:         distance of the mouse cursor from the center of the canvas3D will
045:         control the speed of motion. The behavior of each button is described
046:         below with reference to the View coordinate system.</P>
047:         <P>Left Mouse Button - Moving the mouse up and down will move the
048:         view forward and backward. Moving the mouse left and right will yaw
049:         the view around the Y axis.</P>
050:         <P>Right Mouse Button - Moving the mouse up and down will move the
051:         view up and down the Y axis. Movig the mouse left and right will
052:         translate the view along the X axis.</P>
053:         *
054:         * Canvas3D size changes are tracked
055:         *
056:         * @author Paul Byrne
057:         * @version	1.15, 01/18/02
058:         */
059:        public class HoverBehavior extends J3dFlyMouseBehavior {
060:
061:            private Transform3D velocityTransform;
062:            private Transform3D transform;
063:            private Transform3D newTargetTransform = new Transform3D();
064:
065:            private Vector3f velocity = new Vector3f();
066:            private float yawAngle = 0f;
067:
068:            /**
069:             * @deprecated use HoverBehavior()
070:             */
071:            public HoverBehavior(View view) {
072:                super ();
073:            }
074:
075:            public HoverBehavior() {
076:                super ();
077:            }
078:
079:            public void initialize() {
080:                transform = new Transform3D();
081:                targetTransform = new Transform3D();
082:                velocityTransform = new Transform3D();
083:                super .initialize();
084:            }
085:
086:            protected void processAWTEvents(final java.awt.AWTEvent[] events) {
087:                for (int i = 0; i < events.length; i++)
088:                    if (events[i] instanceof  MouseEvent) {
089:                        if (((MouseEvent) events[i]).getID() == MouseEvent.MOUSE_RELEASED)
090:                            processMouseReleased((MouseEvent) events[i]);
091:                        else if (((MouseEvent) events[i]).getID() == MouseEvent.MOUSE_DRAGGED)
092:                            processMouseDragged((MouseEvent) events[i]);
093:                        else
094:                            processUnusedEvent(events[i]);
095:                    } else
096:                        processUnusedEvent(events[i]);
097:
098:            }
099:
100:            protected void processMouseReleased(final MouseEvent evt) {
101:                if (SwingUtilities.isLeftMouseButton(evt)) {
102:                    yawAngle = 0;
103:                    velocity.z = 0;
104:                    motion = false;
105:                } else if (SwingUtilities.isRightMouseButton(evt)) {
106:                    velocity.x = 0;
107:                    velocity.y = 0;
108:                    motion = false;
109:                } else if (SwingUtilities.isMiddleMouseButton(evt)) {
110:                    motion = false;
111:                } else {
112:                    yawAngle = 0f;
113:                    velocity.x = 0;
114:                    velocity.z = 0;
115:                    velocity.y = 0;
116:                    motion = false;
117:                }
118:            }
119:
120:            protected void processMouseDragged(final MouseEvent evt) {
121:                float offsetX = (evt.getX() - canvasCenter.x) / canvasCenter.x;
122:                float offsetY = (evt.getY() - canvasCenter.y) / canvasCenter.y;
123:                float factorX = 0f;
124:                float factorY = 0f;
125:
126:                motion = false;
127:
128:                if (Math.abs(offsetX) - deadXSize > 0f) {
129:                    factorX = (float) Math.pow(Math.abs(offsetX) - deadXSize,
130:                            2f);
131:                    motion = true;
132:                } else {
133:                    factorX = 0f;
134:                }
135:
136:                if (Math.abs(offsetY) - deadYSize > 0f) {
137:                    factorY = (float) Math.pow(Math.abs(offsetY) - deadYSize,
138:                            2f);
139:                    motion = true;
140:                } else {
141:                    factorY = 0f;
142:                }
143:
144:                if (offsetX > 0f)
145:                    factorX = -factorX;
146:
147:                if (offsetY < 0f)
148:                    factorY = -factorY;
149:
150:                if (SwingUtilities.isLeftMouseButton(evt)) {
151:                    //System.out.println( factorX +" "+factorY );
152:                    yawAngle = MAX_ANGLE * factorX;
153:                    velocity.z = MAX_VELOCITY * factorY;
154:                } else if (SwingUtilities.isRightMouseButton(evt)) {
155:                    velocity.x = MAX_VELOCITY * factorX;
156:                    velocity.y = MAX_VELOCITY * factorY;
157:                } else {
158:                    yawAngle = 0f;
159:                    velocity.x = 0;
160:                    velocity.z = 0;
161:                    velocity.y = 0;
162:                    motion = false;
163:                }
164:            }
165:
166:            protected void integrateTransforms() {
167:                if (!collisionEnabled()) {
168:                    transform.rotY(yawAngle);
169:
170:                    velocityTransform.set(velocity);
171:                    velocityTransform.mul(transform);
172:
173:                    targetTG.getTransform(targetTransform);
174:                    targetTransform.mul(transform);
175:                    targetTransform.mul(velocityTransform);
176:                    targetTG.setTransform(targetTransform);
177:                } else {
178:                    targetTG.getTransform(targetTransform);
179:                    SweptVolumeCollision collision = collisionControl
180:                            .getCollisions(targetTransform, newTargetTransform,
181:                                    velocity, 0f, 0f, yawAngle);
182:                    targetTG.setTransform(newTargetTransform);
183:                }
184:
185:            }
186:
187:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.