Source Code Cross Referenced for VPDriveCollision.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/VPDriveCollision.java,v 1.1 2005/04/20 21:05:15 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 javax.media.j3d.Transform3D;
021:        import javax.vecmath.Vector3f;
022:        import javax.vecmath.Vector3d;
023:        import javax.vecmath.Point3d;
024:        import com.sun.j3d.utils.picking.PickResult;
025:
026:        /**
027:         * A collision implementation that places the view a set distance above
028:         * the 'floor' and then applies collision detection.
029:         *
030:         * The floor is determined as the first geometry that intersects the ray
031:         * (0,large +ve, 0) -> ( 0, -1, 0 )
032:         *
033:         * @author  Paul Byrne
034:         * @version 1.4 01/18/02
035:         */
036:        public class VPDriveCollision extends VPDefaultCollision {
037:
038:            private Point3d rayStart = new Point3d(0, 1000, 0);
039:            private static final Vector3d rayVec = new Vector3d(0, -1, 0);
040:            private Vector3f pos = new Vector3f();
041:            private float height = 1.2f;
042:
043:            /** Creates new VPDriveCollision */
044:            public VPDriveCollision(int mode) {
045:                super (mode);
046:            }
047:
048:            /** Creates new VPDriveCollision */
049:            public VPDriveCollision() {
050:                super ();
051:            }
052:
053:            /**
054:             * Set the height the viewer will be placed above the floor
055:             */
056:            public void setHeight(float height) {
057:                this .height = height;
058:            }
059:
060:            /**
061:             * Get the height the viewer is from the floor
062:             */
063:            public float getHeight() {
064:                return height;
065:            }
066:
067:            /**
068:             * Check for collision when casting the swept bounds from currentLocation to
069:             * nextLocation. The orientation of the swept bounds is set to the orientation at
070:             * nextLocation.
071:             *
072:             * Also force the view to be the specified height above the floor.
073:             *
074:             * This implementation only processes the first ray in each direction. It
075:             * also requires that a ray exists in each direction.
076:             *
077:             * @param currentLocation The current location of the view
078:             * @param nextLocation Will contain the next non collision location of the view on return
079:             * @param velocity The current velocity vector for the view
080:             * @param roll The change in roll for this frame
081:             * @param pitch The change in pitch for this frame
082:             * @param yaw The change in yaw for this frame
083:             */
084:            public SweptVolumeCollision getCollisions(
085:                    Transform3D currentLocation, Transform3D nextLocation,
086:                    Vector3f velocity, float roll, float pitch, float yaw) {
087:
088:                boolean collision = false;
089:                SweptVolumeCollision ret = new SweptVolumeCollision();
090:
091:                Transform3D yawT = new Transform3D();
092:                Transform3D pitchT = new Transform3D();
093:                Transform3D rollT = new Transform3D();
094:                Transform3D velocityT = new Transform3D();
095:                Transform3D destination = new Transform3D();
096:
097:                yawT.rotY(yaw);
098:                pitchT.rotX(pitch);
099:                rollT.rotZ(roll);
100:
101:                velocityT.set(velocity);
102:                velocityT.mul(yawT);
103:                velocityT.mul(pitchT);
104:                velocityT.mul(rollT);
105:
106:                destination.set(currentLocation);
107:
108:                destination.mul(yawT);
109:                destination.mul(pitchT);
110:                destination.mul(rollT);
111:                destination.mul(velocityT);
112:
113:                // Find the floor
114:                destination.get(pos);
115:                rayStart.x = pos.x;
116:                rayStart.z = pos.z;
117:                rayStart.y = 100000;
118:
119:                pickTool.setShapeRay(rayStart, rayVec);
120:                PickResult floor = pickTool.pickClosest();
121:                if (floor != null) {
122:                    pos.y = (float) floor.getIntersection(0)
123:                            .getPointCoordinates().y
124:                            + height;
125:                    destination.setTranslation(pos);
126:                }
127:
128:                collision |= checkZDirection(currentLocation, destination,
129:                        velocity, ret);
130:                collision |= checkXDirection(currentLocation, destination,
131:                        velocity, ret);
132:                collision |= checkYDirection(currentLocation, destination,
133:                        velocity, ret);
134:
135:                // In many cases the checkYDirection call can be omitted. However it is 
136:                // included in this general class to check for collision above the
137:                // view position.
138:
139:                // If the volume is in collision return the original transform, ie
140:                // don't move.
141:                // An alternative approach would be to calculate the 'best' move from
142:                // the current location, ie move as far as possible without causing
143:                // collision.
144:                if (collision) {
145:                    nextLocation.set(currentLocation);
146:                    return null;
147:                } else {
148:                    nextLocation.set(destination);
149:                    return ret;
150:                }
151:            }
152:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.