} else if (spatial instanceof TerrainPatch) { TerrainPatch terrain = (TerrainPatch) spatial; return new HeightfieldCollisionShape(terrain.getHeightMap(), terrain.getLocalScale()); } else if (spatial instanceof Geometry) { return createSingleMeshShape((Geometry) spatial, spatial);
@Override public TerrainPatch clone() { TerrainPatch clone = new TerrainPatch(); clone.name = name.toString(); clone.size = size; clone.totalSize = totalSize; clone.quadrant = quadrant; clone.stepScale = stepScale.clone(); clone.offset = offset.clone(); clone.offsetAmount = offsetAmount; //clone.lodCalculator = lodCalculator.clone(); //clone.lodCalculator.setTerrainPatch(clone); //clone.setLodCalculator(lodCalculatorFactory.clone()); clone.geomap = new LODGeomap(size, geomap.getHeightArray()); clone.setLocalTranslation(getLocalTranslation().clone()); Mesh m = clone.geomap.createMesh(clone.stepScale, Vector2f.UNIT_XY, clone.offset, clone.offsetAmount, clone.totalSize, false); clone.setMesh(m); clone.setMaterial(material.clone()); return clone; }
int s = this.getSize()-1; rootPoint.set(0, this.getHeightmapHeight(s,i), 0); leftPoint.set(-1, this.getHeightmapHeight(s-1,i), 0); rightPoint.set(1, right.getHeightmapHeight(1,i), 0); bottomPoint.set(0, this.getHeightmapHeight(s,i+1), 1); averageNormalsTangents(null, rootPoint, leftPoint, bottomPoint, rightPoint, normal, tangent, binormal); setInBuffer(this.getMesh(), s, normal, tangent, binormal); setInBuffer(right.getMesh(), 0, normal, tangent, binormal); } else { topPoint.set(0, top.getHeightmapHeight(s,s-1), -1); averageNormalsTangents(topPoint, rootPoint, leftPoint, bottomPoint, rightPoint,normal, tangent, binormal); setInBuffer(this.getMesh(), s, normal, tangent, binormal); setInBuffer(right.getMesh(), 0, normal, tangent, binormal); setInBuffer(top.getMesh(), (s+1)*(s+1)-1, normal, tangent, binormal); topPoint.set(0, this.getHeightmapHeight(s,s-1), -1); averageNormalsTangents(topPoint, rootPoint, leftPoint, null, rightPoint, normal, tangent, binormal); setInBuffer(this.getMesh(), (s+1)*(s+1)-1, normal, tangent, binormal); setInBuffer(right.getMesh(), (s+1)*(s), normal, tangent, binormal); } else { bottomPoint.set(0, bottom.getHeightmapHeight(s,1), 1); averageNormalsTangents(topPoint, rootPoint, leftPoint, bottomPoint, rightPoint, normal, tangent, binormal); setInBuffer(this.getMesh(), (s+1)*(s+1)-1, normal, tangent, binormal); setInBuffer(right.getMesh(), (s+1)*s, normal, tangent, binormal);
@Override public int collideWith(Collidable other, CollisionResults results) throws UnsupportedCollisionException { if (refreshFlags != 0) throw new IllegalStateException("Scene graph must be updated" + " before checking collision"); if (other instanceof BoundingVolume) if (!getWorldBound().intersects((BoundingVolume)other)) return 0; if(other instanceof Ray) return collideWithRay((Ray)other, results); else if (other instanceof BoundingVolume) return collideWithBoundingVolume((BoundingVolume)other, results); else { throw new UnsupportedCollisionException("TerrainPatch cannnot collide with "+other.getClass().getName()); } }
if ( ((TerrainPatch)s).getQuadrant() == 1) ul = ((TerrainPatch)s).getHeightMap(); else if(((TerrainPatch) s).getQuadrant() == 2) bl = ((TerrainPatch)s).getHeightMap(); else if(((TerrainPatch) s).getQuadrant() == 3) ur = ((TerrainPatch)s).getHeightMap(); else if(((TerrainPatch) s).getQuadrant() == 4) br = ((TerrainPatch)s).getHeightMap();
TerrainPatch patch1 = new TerrainPatch(getName() + "Patch1", split, stepScale, heightBlock1, origin1, totalSize, tempOffset1, offsetAmount); patch1.setQuadrant((short) 1); this.attachChild(patch1); patch1.setModelBound(new BoundingBox()); patch1.updateModelBound(); TerrainPatch patch2 = new TerrainPatch(getName() + "Patch2", split, stepScale, heightBlock2, origin2, totalSize, tempOffset2, offsetAmount); patch2.setQuadrant((short) 2); this.attachChild(patch2); patch2.setModelBound(new BoundingBox()); patch2.updateModelBound(); TerrainPatch patch3 = new TerrainPatch(getName() + "Patch3", split, stepScale, heightBlock3, origin3, totalSize, tempOffset3, offsetAmount); patch3.setQuadrant((short) 3); this.attachChild(patch3); patch3.setModelBound(new BoundingBox()); patch3.updateModelBound(); TerrainPatch patch4 = new TerrainPatch(getName() + "Patch4", split, stepScale, heightBlock4, origin4, totalSize, tempOffset4, offsetAmount); patch4.setQuadrant((short) 4); this.attachChild(patch4);
Vector3f binormal) Vector3f scale = getWorldScale(); n1.set(calculateNormal(topPoint.mult(scale), rootPoint.mult(scale), leftPoint.mult(scale))); n2.set(calculateNormal(leftPoint.mult(scale), rootPoint.mult(scale), bottomPoint.mult(scale))); n3.set(calculateNormal(bottomPoint.mult(scale), rootPoint.mult(scale), rightPoint.mult(scale))); n4.set(calculateNormal(rightPoint.mult(scale), rootPoint.mult(scale), topPoint.mult(scale)));
private int collideWithBoundingVolume(BoundingVolume boundingVolume, CollisionResults results) { if (boundingVolume instanceof BoundingBox) return collideWithBoundingBox((BoundingBox)boundingVolume, results); else if(boundingVolume instanceof BoundingSphere) { BoundingSphere sphere = (BoundingSphere) boundingVolume; BoundingBox bbox = new BoundingBox(boundingVolume.getCenter().clone(), sphere.getRadius(), sphere.getRadius(), sphere.getRadius()); return collideWithBoundingBox(bbox, results); } return 0; }
/** * Caches the transforms (except rotation) so the LOD calculator, * which runs on a separate thread, can access them safely. */ protected void cacheTerrainTransforms() { for (int i = children.size(); --i >= 0;) { Spatial child = children.get(i); if (child instanceof TerrainQuad) { ((TerrainQuad) child).cacheTerrainTransforms(); } else if (child instanceof TerrainPatch) { ((TerrainPatch) child).cacheTerrainTransforms(); } } }
/** * Removes any cached references this terrain is holding, in particular * the TerrainPatch's neighbour references. * This is called automatically when the root terrainQuad is detached from * its parent or if setParent(null) is called. */ public void clearCaches() { if (children != null) { for (int i = children.size(); --i >= 0;) { Spatial child = children.get(i); if (child instanceof TerrainQuad) { ((TerrainQuad) child).clearCaches(); } else if (child instanceof TerrainPatch) { ((TerrainPatch) child).clearCaches(); } } } }
if ( ((TerrainPatch)s).getQuadrant() == 1) ul = ((TerrainPatch)s).getHeightMap(); else if(((TerrainPatch) s).getQuadrant() == 2) bl = ((TerrainPatch)s).getHeightMap(); else if(((TerrainPatch) s).getQuadrant() == 3) ur = ((TerrainPatch)s).getHeightMap(); else if(((TerrainPatch) s).getQuadrant() == 4) br = ((TerrainPatch)s).getHeightMap();
TerrainPatch patch1 = new TerrainPatch(getName() + "Patch1", split, stepScale, heightBlock1, origin1, totalSize, tempOffset1, offsetAmount); patch1.setQuadrant((short) 1); this.attachChild(patch1); patch1.setModelBound(new BoundingBox()); patch1.updateModelBound(); TerrainPatch patch2 = new TerrainPatch(getName() + "Patch2", split, stepScale, heightBlock2, origin2, totalSize, tempOffset2, offsetAmount); patch2.setQuadrant((short) 2); this.attachChild(patch2); patch2.setModelBound(new BoundingBox()); patch2.updateModelBound(); TerrainPatch patch3 = new TerrainPatch(getName() + "Patch3", split, stepScale, heightBlock3, origin3, totalSize, tempOffset3, offsetAmount); patch3.setQuadrant((short) 3); this.attachChild(patch3); patch3.setModelBound(new BoundingBox()); patch3.updateModelBound(); TerrainPatch patch4 = new TerrainPatch(getName() + "Patch4", split, stepScale, heightBlock4, origin4, totalSize, tempOffset4, offsetAmount); patch4.setQuadrant((short) 4); this.attachChild(patch4);
@Override public int collideWith(Collidable other, CollisionResults results) throws UnsupportedCollisionException { if (refreshFlags != 0) throw new IllegalStateException("Scene graph must be updated" + " before checking collision"); if (other instanceof BoundingVolume) if (!getWorldBound().intersects((BoundingVolume)other)) return 0; if(other instanceof Ray) return collideWithRay((Ray)other, results); else if (other instanceof BoundingVolume) return collideWithBoundingVolume((BoundingVolume)other, results); else { throw new UnsupportedCollisionException("TerrainPatch cannnot collide with "+other.getClass().getName()); } }
Vector3f binormal) Vector3f scale = getWorldScale(); n1.set(calculateNormal(topPoint.mult(scale), rootPoint.mult(scale), leftPoint.mult(scale))); n2.set(calculateNormal(leftPoint.mult(scale), rootPoint.mult(scale), bottomPoint.mult(scale))); n3.set(calculateNormal(bottomPoint.mult(scale), rootPoint.mult(scale), rightPoint.mult(scale))); n4.set(calculateNormal(rightPoint.mult(scale), rootPoint.mult(scale), topPoint.mult(scale)));
private int collideWithBoundingVolume(BoundingVolume boundingVolume, CollisionResults results) { if (boundingVolume instanceof BoundingBox) return collideWithBoundingBox((BoundingBox)boundingVolume, results); else if(boundingVolume instanceof BoundingSphere) { BoundingSphere sphere = (BoundingSphere) boundingVolume; BoundingBox bbox = new BoundingBox(boundingVolume.getCenter().clone(), sphere.getRadius(), sphere.getRadius(), sphere.getRadius()); return collideWithBoundingBox(bbox, results); } return 0; }
/** * Caches the transforms (except rotation) so the LOD calculator, * which runs on a separate thread, can access them safely. */ protected void cacheTerrainTransforms() { for (int i = children.size(); --i >= 0;) { Spatial child = children.get(i); if (child instanceof TerrainQuad) { ((TerrainQuad) child).cacheTerrainTransforms(); } else if (child instanceof TerrainPatch) { ((TerrainPatch) child).cacheTerrainTransforms(); } } }
/** * Removes any cached references this terrain is holding, in particular * the TerrainPatch's neighbour references. * This is called automatically when the root terrainQuad is detached from * its parent or if setParent(null) is called. */ public void clearCaches() { if (children != null) { for (int i = children.size(); --i >= 0;) { Spatial child = children.get(i); if (child instanceof TerrainQuad) { ((TerrainQuad) child).clearCaches(); } else if (child instanceof TerrainPatch) { ((TerrainPatch) child).clearCaches(); } } } }
} else if (spatial instanceof TerrainPatch) { TerrainPatch terrain = (TerrainPatch) spatial; return new HeightfieldCollisionShape(terrain.getHeightMap(), terrain.getLocalScale()); } else if (spatial instanceof Geometry) { return createSingleMeshShape((Geometry) spatial, spatial);
@Override public TerrainPatch clone() { TerrainPatch clone = new TerrainPatch(); clone.name = name.toString(); clone.size = size; clone.totalSize = totalSize; clone.quadrant = quadrant; clone.stepScale = stepScale.clone(); clone.offset = offset.clone(); clone.offsetAmount = offsetAmount; //clone.lodCalculator = lodCalculator.clone(); //clone.lodCalculator.setTerrainPatch(clone); //clone.setLodCalculator(lodCalculatorFactory.clone()); clone.geomap = new LODGeomap(size, geomap.getHeightArray()); clone.setLocalTranslation(getLocalTranslation().clone()); Mesh m = clone.geomap.createMesh(clone.stepScale, Vector2f.UNIT_XY, clone.offset, clone.offsetAmount, clone.totalSize, false); clone.setMesh(m); clone.setMaterial(material.clone()); return clone; }
int s = this.getSize()-1; rootPoint.set(0, this.getHeightmapHeight(s,i), 0); leftPoint.set(-1, this.getHeightmapHeight(s-1,i), 0); rightPoint.set(1, right.getHeightmapHeight(1,i), 0); bottomPoint.set(0, this.getHeightmapHeight(s,i+1), 1); averageNormalsTangents(null, rootPoint, leftPoint, bottomPoint, rightPoint, normal, tangent, binormal); setInBuffer(this.getMesh(), s, normal, tangent, binormal); setInBuffer(right.getMesh(), 0, normal, tangent, binormal); } else { topPoint.set(0, top.getHeightmapHeight(s,s-1), -1); averageNormalsTangents(topPoint, rootPoint, leftPoint, bottomPoint, rightPoint,normal, tangent, binormal); setInBuffer(this.getMesh(), s, normal, tangent, binormal); setInBuffer(right.getMesh(), 0, normal, tangent, binormal); setInBuffer(top.getMesh(), (s+1)*(s+1)-1, normal, tangent, binormal); topPoint.set(0, this.getHeightmapHeight(s,s-1), -1); averageNormalsTangents(topPoint, rootPoint, leftPoint, null, rightPoint, normal, tangent, binormal); setInBuffer(this.getMesh(), (s+1)*(s+1)-1, normal, tangent, binormal); setInBuffer(right.getMesh(), (s+1)*(s), normal, tangent, binormal); } else { bottomPoint.set(0, bottom.getHeightmapHeight(s,1), 1); averageNormalsTangents(topPoint, rootPoint, leftPoint, bottomPoint, rightPoint, normal, tangent, binormal); setInBuffer(this.getMesh(), (s+1)*(s+1)-1, normal, tangent, binormal); setInBuffer(right.getMesh(), (s+1)*s, normal, tangent, binormal);