|
From: <tre...@us...> - 2007-11-04 18:07:01
|
Revision: 559
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=559&view=rev
Author: trevorolio
Date: 2007-11-04 10:07:05 -0800 (Sun, 04 Nov 2007)
Log Message:
-----------
Dead simple collision detection for avatars so that they stop walking through walls.
Modified Paths:
--------------
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DPicker.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DRenderer.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DUserRenderable.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/RenderableMotionInterpolator.java
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DPicker.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DPicker.java 2007-11-03 23:37:13 UTC (rev 558)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DPicker.java 2007-11-04 18:07:05 UTC (rev 559)
@@ -32,16 +32,17 @@
private Point3d intersectionPoint = new Point3d();
private Renderable currentClosest = null;
+
private Point3d currentIntersection = new Point3d();
-
+
public Renderable pickRay(Point3d position, Vector3d direction) {
return pickRay(position, direction, intersectionPoint);
}
-
+
public Renderable pickRayClosest(Point3d position, Vector3d direction, Point3d intersectionPoint) {
currentClosest = null;
currentIntersection.set(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);
-
+
rayPick.set(position, direction);
SceneGraphPath[] boundsColliders = renderer.getWorldGroup().pickAllSorted(rayPick);
if (boundsColliders == null) {
@@ -52,37 +53,37 @@
try {
intersects = intersectsRay((Shape3D) boundsColliders[i].getObject(), boundsColliders[i].getTransform(), position, direction, intersectionPoint);
} catch (Exception e) { //TODO track down whether this exception is our fault or QuarArray's. Arrgh
- if(boundsColliders[i].getObject() instanceof J3DPageRenderable.BrowserScreen) {
+ if (boundsColliders[i].getObject() instanceof J3DPageRenderable.BrowserScreen) {
intersects = true;
}
}
if (intersects) {
- if(currentClosest == null) {
+ if (currentClosest == null) {
currentClosest = convertToRenderable(boundsColliders[i].getObject());
currentIntersection.set(intersectionPoint);
- } else if(position.distance(intersectionPoint) < position.distance(currentIntersection)) {
+ } else if (position.distance(intersectionPoint) < position.distance(currentIntersection)) {
currentClosest = convertToRenderable(boundsColliders[i].getObject());
currentIntersection.set(intersectionPoint);
}
}
}
- if(currentClosest != null) {
+ if (currentClosest != null) {
intersectionPoint.set(currentIntersection);
}
return currentClosest;
}
-
+
private Renderable convertToRenderable(Object obj) {
- if(obj instanceof Renderable) {
+ if (obj instanceof Renderable) {
return (Renderable) obj;
}
- if(obj instanceof J3DShapeRenderable.InnerShape) {
- return ((J3DShapeRenderable.InnerShape)obj).getRenderable();
+ if (obj instanceof J3DShapeRenderable.InnerShape) {
+ return ((J3DShapeRenderable.InnerShape) obj).getRenderable();
}
return null;
}
-
+
public Renderable pickRay(Point3d position, Vector3d direction, Point3d intersectionPoint) {
rayPick.set(position, direction);
SceneGraphPath[] boundsColliders = renderer.getWorldGroup().pickAllSorted(rayPick);
@@ -94,17 +95,17 @@
try {
intersects = intersectsRay((Shape3D) boundsColliders[i].getObject(), boundsColliders[i].getTransform(), position, direction, intersectionPoint);
} catch (Exception e) { //TODO track down whether this exception is our fault or QuarArray's. Arrgh
- if(boundsColliders[i].getObject() instanceof J3DPageRenderable.BrowserScreen) {
+ if (boundsColliders[i].getObject() instanceof J3DPageRenderable.BrowserScreen) {
intersects = true;
}
}
if (intersects) {
Object obj = boundsColliders[i].getObject();
- if(obj instanceof Renderable) {
+ if (obj instanceof Renderable) {
return (Renderable) obj;
}
- if(obj instanceof J3DShapeRenderable.InnerShape) {
- return ((J3DShapeRenderable.InnerShape)obj).getRenderable();
+ if (obj instanceof J3DShapeRenderable.InnerShape) {
+ return ((J3DShapeRenderable.InnerShape) obj).getRenderable();
}
}
}
@@ -119,7 +120,13 @@
}
for (int i = 0; i < boundsColliders.length; i++) {
if (intersectsSegment((Shape3D) boundsColliders[i].getObject(), boundsColliders[i].getTransform(), startPoint, endPoint)) {
- return (Renderable) boundsColliders[i].getObject();
+ Object obj = boundsColliders[i].getObject();
+ if (obj instanceof Renderable) {
+ return (Renderable) obj;
+ }
+ if (obj instanceof J3DShapeRenderable.InnerShape) {
+ return ((J3DShapeRenderable.InnerShape) obj).getRenderable();
+ }
}
}
return null;
@@ -148,8 +155,11 @@
if (geometry == null) {
continue;
}
- if (intersectionUtils.rayUnknownGeometry(startPoint, getDirectionVector(startPoint, endPoint), (float) getDistance(startPoint, endPoint), geometry, localTransform, intersectionPoint, false)) {
- return true;
+ try {
+ if (intersectionUtils.rayUnknownGeometry(startPoint, getDirectionVector(startPoint, endPoint), (float) getDistance(startPoint, endPoint), geometry, localTransform, intersectionPoint, false)) {
+ return true;
+ }
+ } catch (Exception e) { //believe this is the same problem with the browser screen as pickRay, ignoring
}
}
return false;
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DRenderer.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DRenderer.java 2007-11-03 23:37:13 UTC (rev 558)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DRenderer.java 2007-11-04 18:07:05 UTC (rev 559)
@@ -689,7 +689,7 @@
if (isLocalUser) {
float cameraHeight = (float) (renderable.getHeight() - renderable.getHeight() / 5);
- Vector3f defaultCameraLocation = new Vector3f(0f, cameraHeight, 0f);
+ Vector3f defaultCameraLocation = new Vector3f(0f, cameraHeight, 3f);
camera.setDefaultLocation(defaultCameraLocation);
camera.setLocation(defaultCameraLocation);
@@ -795,6 +795,10 @@
return worldGroup;
}
+ public J3DPicker getPicker(){
+ return picker;
+ }
+
private final static Vector3d DOWN_VEC = new Vector3d(0.0, -1.0, 0.0);
public class LandHeightMonitor {
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DUserRenderable.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DUserRenderable.java 2007-11-03 23:37:13 UTC (rev 558)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DUserRenderable.java 2007-11-04 18:07:05 UTC (rev 559)
@@ -95,7 +95,6 @@
}
public void initBody(J3DBodyData bodyData, BufferedImage customSkin) {
- System.out.println("INIT BODY: " + user + " bodyData: " + bodyData + " skin " + customSkin);
bodyGroup.removeAllChildren();
this.bodyData = bodyData;
skin = new SkinLoader(bodyData, user.getBodyConfiguration(), customSkin).generateSkin();
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/RenderableMotionInterpolator.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/RenderableMotionInterpolator.java 2007-11-03 23:37:13 UTC (rev 558)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/RenderableMotionInterpolator.java 2007-11-04 18:07:05 UTC (rev 559)
@@ -44,7 +44,7 @@
Vector3d newLocation = new Vector3d();
double newY = 0;
-
+
Transform3D currentPosition = new Transform3D();
Vector3d currentLocation = new Vector3d();
@@ -87,10 +87,10 @@
transformGroup.getTransform(newPosition);
newPosition.get(newLocation);
- if(path.followsPlatform()) {
+ if (path.followsPlatform()) {
newLocation.y = landHeightMonitor.getLandHeight(newLocation.x, newLocation.z, currentLocation.y + renderable.getHeight() / 2) + path.getDistanceFromPlatform();
}
- if (false && isColliding(newLocation)) {
+ if (isColliding(newLocation)) {
renderable.setPosition(currentPosition);
cleanup();
} else {
@@ -99,76 +99,39 @@
}
}
- PickCylinderSegment collisionPick = new PickCylinderSegment();
-
Point3d headPoint = new Point3d();
Point3d kneePoint = new Point3d();
- J3DIntersectionUtils intersectionUtils = new J3DIntersectionUtils();
+ Point3d frontPoint = new Point3d();
- Vector3d yVector = new Vector3d(0, -1, 0);
+ Renderable hitRenderable = null;
- Vector3d zVector = new Vector3d(0, 0, -1);
+ double bodyRadius = 0.1;
- Vector3d xVector = new Vector3d(-1, 0, 0);
-
- Transform3D local_tx = new Transform3D();
-
- Point3d wkPoint = new Point3d();
-
- Point3d locationPoint = new Point3d();
-
private boolean isColliding(Vector3d location) {
- headPoint.set(location.x, location.y + renderable.getHeight(), location.z);
+ headPoint.set(location.x, location.y + renderable.getHeight(), location.z + bodyRadius);
kneePoint.set(location.x, location.y + (renderable.getHeight() * 0.75), location.z);
- //System.out.println(headPoint + "\t" + kneePoint);
- collisionPick.set(headPoint, kneePoint, 0.01);
- SceneGraphPath[] boundsColliders = renderer.getWorldGroup().pickAllSorted(collisionPick);
- if (boundsColliders == null) {
- return false;
+ hitRenderable = renderer.getPicker().pickSegment(headPoint, kneePoint);
+ if (hitRenderable != null) {
+ return true;
}
- for (int i = 0; i < boundsColliders.length; i++) {
- Object userData = boundsColliders[i].getObject().getUserData();
- if (userData == null || ((String) userData).startsWith(J3DRenderer.USER_ID_PREFIX)) {
- continue;
- }
- local_tx = boundsColliders[i].getTransform();
- if (isReallyColliding((Shape3D) boundsColliders[i].getObject(), 0.5f)) {
- //System.out.println("Collided: " + boundsColliders[i].getObject().getUserData());
- return true;
- }
+ headPoint.set(headPoint.x, headPoint.y, headPoint.z - (2 * bodyRadius));
+ hitRenderable = renderer.getPicker().pickSegment(headPoint, kneePoint);
+ if (hitRenderable != null) {
+ return true;
}
- return false;
- }
-
- private boolean isReallyColliding(Shape3D i_shape, float pickingDistance) {
- Enumeration geom_list = i_shape.getAllGeometries();
-
- while (geom_list.hasMoreElements()) {
- GeometryArray geom = (GeometryArray) geom_list.nextElement();
-
- if (geom == null) {
- continue;
- }
- locationPoint.set(kneePoint.x, kneePoint.y, kneePoint.z);
- boolean intersect = intersectionUtils.rayUnknownGeometry(locationPoint, yVector, pickingDistance, geom, local_tx, wkPoint, false);
- if (!intersect) {
- locationPoint.z += pickingDistance / 2f;
- intersect = intersectionUtils.rayUnknownGeometry(locationPoint, zVector, pickingDistance, geom, local_tx, wkPoint, false);
- locationPoint.z -= pickingDistance / 2f;
- if (!intersect) {
- locationPoint.x += pickingDistance / 2f;
- intersect = intersectionUtils.rayUnknownGeometry(locationPoint, xVector, pickingDistance, geom, local_tx, wkPoint, false);
- locationPoint.x -= pickingDistance / 2f;
- }
- }
- if (intersect) {
- Log.info("wk " + wkPoint);
- return true;
- }
+ headPoint.set(headPoint.x - bodyRadius, headPoint.y, headPoint.z + bodyRadius);
+ hitRenderable = renderer.getPicker().pickSegment(headPoint, kneePoint);
+ if (hitRenderable != null) {
+ return true;
}
- return false;
+ headPoint.set(headPoint.x + (2 * bodyRadius), headPoint.y, headPoint.z);
+ hitRenderable = renderer.getPicker().pickSegment(headPoint, kneePoint);
+ if (hitRenderable != null) {
+ return true;
+ }
+ return hitRenderable != null;
}
public boolean isComplete() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|