diff options
author | Scott Barta <sbarta@google.com> | 2012-03-01 12:35:35 -0800 |
---|---|---|
committer | Scott Barta <sbarta@google.com> | 2012-03-01 12:40:08 -0800 |
commit | 59b2e6871c65f58fdad78cd7229c292f6a177578 (patch) | |
tree | 2d4e7bfc05b93f40b34675d77e403dd1c25efafd /engine/src/core/com/jme3/scene/debug | |
parent | f9b30489e75ac1eabc365064959804e99534f7ab (diff) | |
download | jmonkeyengine-59b2e6871c65f58fdad78cd7229c292f6a177578.tar.gz |
Adds the jMonkeyEngine library to the build.
Adds the jMonkeyEngine open source 3D game engine to the build. This
is built as a static library and is only used by the Finsky client.
Change-Id: I06a3f054df7b8a67757267d884854f70c5a16ca0
Diffstat (limited to 'engine/src/core/com/jme3/scene/debug')
-rw-r--r-- | engine/src/core/com/jme3/scene/debug/Arrow.java | 142 | ||||
-rw-r--r-- | engine/src/core/com/jme3/scene/debug/Grid.java | 105 | ||||
-rw-r--r-- | engine/src/core/com/jme3/scene/debug/SkeletonDebugger.java | 80 | ||||
-rw-r--r-- | engine/src/core/com/jme3/scene/debug/SkeletonPoints.java | 80 | ||||
-rw-r--r-- | engine/src/core/com/jme3/scene/debug/SkeletonWire.java | 109 | ||||
-rw-r--r-- | engine/src/core/com/jme3/scene/debug/WireBox.java | 108 | ||||
-rw-r--r-- | engine/src/core/com/jme3/scene/debug/WireFrustum.java | 88 | ||||
-rw-r--r-- | engine/src/core/com/jme3/scene/debug/WireSphere.java | 159 |
8 files changed, 871 insertions, 0 deletions
diff --git a/engine/src/core/com/jme3/scene/debug/Arrow.java b/engine/src/core/com/jme3/scene/debug/Arrow.java new file mode 100644 index 0000000..1c3dd94 --- /dev/null +++ b/engine/src/core/com/jme3/scene/debug/Arrow.java @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2009-2010 jMonkeyEngine + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'jMonkeyEngine' nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.jme3.scene.debug; + +import com.jme3.math.Quaternion; +import com.jme3.math.Vector3f; +import com.jme3.scene.Mesh; +import com.jme3.scene.VertexBuffer; +import com.jme3.scene.VertexBuffer.Type; +import java.nio.FloatBuffer; + +/** + * The <code>Arrow</code> debug shape represents an arrow. + * An arrow is simply a line going from the original toward an extent + * and at the tip there will be triangle-like shape. + * + * @author Kirill Vainer + */ +public class Arrow extends Mesh { + + private Quaternion tempQuat = new Quaternion(); + private Vector3f tempVec = new Vector3f(); + + private static final float[] positions = new float[]{ + 0, 0, 0, + 0, 0, 1, // tip + 0.05f, 0, 0.9f, // tip right + -0.05f, 0, 0.9f, // tip left + 0, 0.05f, 0.9f, // tip top + 0, -0.05f, 0.9f, // tip buttom + }; + + /** + * Serialization only. Do not use. + */ + public Arrow() { + } + + /** + * Creates an arrow mesh with the given extent. + * The arrow will start at the origin (0,0,0) and finish + * at the given extent. + * + * @param extent Extent of the arrow from origin + */ + public Arrow(Vector3f extent) { + float len = extent.length(); + Vector3f dir = extent.normalize(); + + tempQuat.lookAt(dir, Vector3f.UNIT_Y); + tempQuat.normalizeLocal(); + + float[] newPositions = new float[positions.length]; + for (int i = 0; i < positions.length; i += 3) { + Vector3f vec = tempVec.set(positions[i], + positions[i + 1], + positions[i + 2]); + vec.multLocal(len); + tempQuat.mult(vec, vec); + + newPositions[i] = vec.getX(); + newPositions[i + 1] = vec.getY(); + newPositions[i + 2] = vec.getZ(); + } + + setBuffer(Type.Position, 3, newPositions); + setBuffer(Type.Index, 2, + new short[]{ + 0, 1, + 1, 2, + 1, 3, + 1, 4, + 1, 5,}); + setMode(Mode.Lines); + + updateBound(); + updateCounts(); + } + + /** + * Sets the arrow's extent. + * This will modify the buffers on the mesh. + * + * @param extent the arrow's extent. + */ + public void setArrowExtent(Vector3f extent) { + float len = extent.length(); +// Vector3f dir = extent.normalize(); + + tempQuat.lookAt(extent, Vector3f.UNIT_Y); + tempQuat.normalizeLocal(); + + VertexBuffer pvb = getBuffer(Type.Position); + FloatBuffer buffer = (FloatBuffer)pvb.getData(); + buffer.rewind(); + for (int i = 0; i < positions.length; i += 3) { + Vector3f vec = tempVec.set(positions[i], + positions[i + 1], + positions[i + 2]); + vec.multLocal(len); + tempQuat.mult(vec, vec); + + buffer.put(vec.x); + buffer.put(vec.y); + buffer.put(vec.z); + } + + pvb.updateData(buffer); + + updateBound(); + updateCounts(); + } +} diff --git a/engine/src/core/com/jme3/scene/debug/Grid.java b/engine/src/core/com/jme3/scene/debug/Grid.java new file mode 100644 index 0000000..ea6225c --- /dev/null +++ b/engine/src/core/com/jme3/scene/debug/Grid.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2009-2010 jMonkeyEngine + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'jMonkeyEngine' nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.jme3.scene.debug; + +import com.jme3.scene.Mesh; +import com.jme3.scene.Mesh.Mode; +import com.jme3.scene.VertexBuffer.Type; +import com.jme3.util.BufferUtils; +import java.nio.FloatBuffer; +import java.nio.ShortBuffer; + +/** + * Simple grid shape. + * + * @author Kirill Vainer + */ +public class Grid extends Mesh { + + /** + * Creates a grid debug shape. + * @param xLines + * @param yLines + * @param lineDist + */ + public Grid(int xLines, int yLines, float lineDist){ + xLines -= 2; + yLines -= 2; + int lineCount = xLines + yLines + 4; + + FloatBuffer fpb = BufferUtils.createFloatBuffer(6 * lineCount); + ShortBuffer sib = BufferUtils.createShortBuffer(2 * lineCount); + + float xLineLen = (yLines + 1) * lineDist; + float yLineLen = (xLines + 1) * lineDist; + int curIndex = 0; + + // add lines along X + for (int i = 0; i < xLines + 2; i++){ + float y = (i) * lineDist; + + // positions + fpb.put(0) .put(0).put(y); + fpb.put(xLineLen).put(0).put(y); + + // indices + sib.put( (short) (curIndex++) ); + sib.put( (short) (curIndex++) ); + } + + // add lines along Y + for (int i = 0; i < yLines + 2; i++){ + float x = (i) * lineDist; + + // positions + fpb.put(x).put(0).put(0); + fpb.put(x).put(0).put(yLineLen); + + // indices + sib.put( (short) (curIndex++) ); + sib.put( (short) (curIndex++) ); + } + + fpb.flip(); + sib.flip(); + + setBuffer(Type.Position, 3, fpb); + setBuffer(Type.Index, 2, sib); + + setMode(Mode.Lines); + + updateBound(); + updateCounts(); + } + +} diff --git a/engine/src/core/com/jme3/scene/debug/SkeletonDebugger.java b/engine/src/core/com/jme3/scene/debug/SkeletonDebugger.java new file mode 100644 index 0000000..07efdc9 --- /dev/null +++ b/engine/src/core/com/jme3/scene/debug/SkeletonDebugger.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2009-2010 jMonkeyEngine + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'jMonkeyEngine' nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.jme3.scene.debug; + +import com.jme3.animation.Skeleton; +import com.jme3.renderer.queue.RenderQueue.Bucket; +import com.jme3.scene.Geometry; +import com.jme3.scene.Node; + +public class SkeletonDebugger extends Node { + + private SkeletonWire wires; + private SkeletonPoints points; + private Skeleton skeleton; + + public SkeletonDebugger(String name, Skeleton skeleton){ + super(name); + + this.skeleton = skeleton; + wires = new SkeletonWire(skeleton); + points = new SkeletonPoints(skeleton); + + attachChild(new Geometry(name+"_wires", wires)); + attachChild(new Geometry(name+"_points", points)); + + setQueueBucket(Bucket.Transparent); + } + + public SkeletonDebugger(){ + } + + @Override + public void updateLogicalState(float tpf){ + super.updateLogicalState(tpf); + +// skeleton.resetAndUpdate(); + wires.updateGeometry(); + points.updateGeometry(); + } + + public SkeletonPoints getPoints() { + return points; + } + + public SkeletonWire getWires() { + return wires; + } + + +} diff --git a/engine/src/core/com/jme3/scene/debug/SkeletonPoints.java b/engine/src/core/com/jme3/scene/debug/SkeletonPoints.java new file mode 100644 index 0000000..2e49ce5 --- /dev/null +++ b/engine/src/core/com/jme3/scene/debug/SkeletonPoints.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2009-2010 jMonkeyEngine + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'jMonkeyEngine' nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.jme3.scene.debug; + +import com.jme3.animation.Bone; +import com.jme3.animation.Skeleton; +import com.jme3.math.Vector3f; +import com.jme3.scene.Mesh; +import com.jme3.scene.VertexBuffer; +import com.jme3.scene.VertexBuffer.Format; +import com.jme3.scene.VertexBuffer.Type; +import com.jme3.scene.VertexBuffer.Usage; +import com.jme3.util.BufferUtils; +import java.nio.FloatBuffer; + +public class SkeletonPoints extends Mesh { + + private Skeleton skeleton; + + public SkeletonPoints(Skeleton skeleton){ + this.skeleton = skeleton; + + setMode(Mode.Points); + + VertexBuffer pb = new VertexBuffer(Type.Position); + FloatBuffer fpb = BufferUtils.createFloatBuffer(skeleton.getBoneCount() * 3); + pb.setupData(Usage.Stream, 3, Format.Float, fpb); + setBuffer(pb); + + setPointSize(7); + + updateCounts(); + } + + public void updateGeometry(){ + VertexBuffer vb = getBuffer(Type.Position); + FloatBuffer posBuf = getFloatBuffer(Type.Position); + posBuf.clear(); + for (int i = 0; i < skeleton.getBoneCount(); i++){ + Bone bone = skeleton.getBone(i); + Vector3f bonePos = bone.getModelSpacePosition(); + + posBuf.put(bonePos.getX()).put(bonePos.getY()).put(bonePos.getZ()); + } + posBuf.flip(); + vb.updateData(posBuf); + + updateBound(); + } +} diff --git a/engine/src/core/com/jme3/scene/debug/SkeletonWire.java b/engine/src/core/com/jme3/scene/debug/SkeletonWire.java new file mode 100644 index 0000000..0796334 --- /dev/null +++ b/engine/src/core/com/jme3/scene/debug/SkeletonWire.java @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2009-2010 jMonkeyEngine + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'jMonkeyEngine' nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.jme3.scene.debug; + +import com.jme3.animation.Bone; +import com.jme3.animation.Skeleton; +import com.jme3.math.Vector3f; +import com.jme3.scene.Mesh; +import com.jme3.scene.VertexBuffer; +import com.jme3.scene.VertexBuffer.Format; +import com.jme3.scene.VertexBuffer.Type; +import com.jme3.scene.VertexBuffer.Usage; +import com.jme3.util.BufferUtils; +import java.nio.FloatBuffer; +import java.nio.ShortBuffer; + +public class SkeletonWire extends Mesh { + + private int numConnections = 0; + private Skeleton skeleton; + + private void countConnections(Bone bone){ + for (Bone child : bone.getChildren()){ + numConnections ++; + countConnections(child); + } + } + + private void writeConnections(ShortBuffer indexBuf, Bone bone){ + for (Bone child : bone.getChildren()){ + // write myself + indexBuf.put( (short) skeleton.getBoneIndex(bone) ); + // write the child + indexBuf.put( (short) skeleton.getBoneIndex(child) ); + + writeConnections(indexBuf, child); + } + } + + public SkeletonWire(Skeleton skeleton){ + this.skeleton = skeleton; + for (Bone bone : skeleton.getRoots()) + countConnections(bone); + + setMode(Mode.Lines); + + VertexBuffer pb = new VertexBuffer(Type.Position); + FloatBuffer fpb = BufferUtils.createFloatBuffer(skeleton.getBoneCount() * 3); + pb.setupData(Usage.Stream, 3, Format.Float, fpb); + setBuffer(pb); + + VertexBuffer ib = new VertexBuffer(Type.Index); + ShortBuffer sib = BufferUtils.createShortBuffer(numConnections * 2); + ib.setupData(Usage.Static, 2, Format.UnsignedShort, sib); + setBuffer(ib); + + for (Bone bone : skeleton.getRoots()) + writeConnections(sib, bone); + sib.flip(); + + updateCounts(); + } + + public void updateGeometry(){ + VertexBuffer vb = getBuffer(Type.Position); + FloatBuffer posBuf = getFloatBuffer(Type.Position); + posBuf.clear(); + for (int i = 0; i < skeleton.getBoneCount(); i++){ + Bone bone = skeleton.getBone(i); + Vector3f bonePos = bone.getModelSpacePosition(); + + posBuf.put(bonePos.getX()).put(bonePos.getY()).put(bonePos.getZ()); + } + posBuf.flip(); + vb.updateData(posBuf); + + updateBound(); + } +} diff --git a/engine/src/core/com/jme3/scene/debug/WireBox.java b/engine/src/core/com/jme3/scene/debug/WireBox.java new file mode 100644 index 0000000..50af28a --- /dev/null +++ b/engine/src/core/com/jme3/scene/debug/WireBox.java @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2009-2010 jMonkeyEngine + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'jMonkeyEngine' nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.jme3.scene.debug; + +import com.jme3.bounding.BoundingBox; +import com.jme3.scene.Mesh; +import com.jme3.scene.VertexBuffer; +import com.jme3.scene.VertexBuffer.Format; +import com.jme3.scene.VertexBuffer.Type; +import com.jme3.scene.VertexBuffer.Usage; +import com.jme3.util.BufferUtils; +import java.nio.FloatBuffer; + +public class WireBox extends Mesh { + + public WireBox(){ + this(1,1,1); + } + + public WireBox(float xExt, float yExt, float zExt){ + updatePositions(xExt,yExt,zExt); + setBuffer(Type.Index, 2, + new short[]{ + 0, 1, + 1, 2, + 2, 3, + 3, 0, + + 4, 5, + 5, 6, + 6, 7, + 7, 4, + + 0, 4, + 1, 5, + 2, 6, + 3, 7, + } + ); + setMode(Mode.Lines); + + updateCounts(); + } + + public void updatePositions(float xExt, float yExt, float zExt){ + VertexBuffer pvb = getBuffer(Type.Position); + FloatBuffer pb; + if (pvb == null){ + pvb = new VertexBuffer(Type.Position); + pb = BufferUtils.createVector3Buffer(8); + pvb.setupData(Usage.Dynamic, 3, Format.Float, pb); + setBuffer(pvb); + }else{ + pb = (FloatBuffer) pvb.getData(); + pvb.updateData(pb); + } + pb.rewind(); + pb.put( + new float[]{ + -xExt, -yExt, zExt, + xExt, -yExt, zExt, + xExt, yExt, zExt, + -xExt, yExt, zExt, + + -xExt, -yExt, -zExt, + xExt, -yExt, -zExt, + xExt, yExt, -zExt, + -xExt, yExt, -zExt, + } + ); + updateBound(); + } + + public void fromBoundingBox(BoundingBox bbox){ + updatePositions(bbox.getXExtent(), bbox.getYExtent(), bbox.getZExtent()); + } + +} diff --git a/engine/src/core/com/jme3/scene/debug/WireFrustum.java b/engine/src/core/com/jme3/scene/debug/WireFrustum.java new file mode 100644 index 0000000..7a86d90 --- /dev/null +++ b/engine/src/core/com/jme3/scene/debug/WireFrustum.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2009-2010 jMonkeyEngine + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'jMonkeyEngine' nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.jme3.scene.debug; + +import com.jme3.math.Vector3f; +import com.jme3.scene.Mesh; +import com.jme3.scene.VertexBuffer; +import com.jme3.scene.VertexBuffer.Type; +import com.jme3.util.BufferUtils; +import java.nio.FloatBuffer; + +public class WireFrustum extends Mesh { + + public WireFrustum(Vector3f[] points){ + if (points != null) + setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(points)); + + setBuffer(Type.Index, 2, + new short[]{ + 0, 1, + 1, 2, + 2, 3, + 3, 0, + + 4, 5, + 5, 6, + 6, 7, + 7, 4, + + 0, 4, + 1, 5, + 2, 6, + 3, 7, + } + ); + setMode(Mode.Lines); + } + + public void update(Vector3f[] points){ + VertexBuffer vb = getBuffer(Type.Position); + if (vb == null){ + setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(points)); + return; + } + + FloatBuffer b = BufferUtils.createFloatBuffer(points); + FloatBuffer a = (FloatBuffer) vb.getData(); + b.rewind(); + a.rewind(); + a.put(b); + a.rewind(); + + vb.updateData(a); + + updateBound(); + } + +} diff --git a/engine/src/core/com/jme3/scene/debug/WireSphere.java b/engine/src/core/com/jme3/scene/debug/WireSphere.java new file mode 100644 index 0000000..df863e2 --- /dev/null +++ b/engine/src/core/com/jme3/scene/debug/WireSphere.java @@ -0,0 +1,159 @@ +/*
+ * Copyright (c) 2009-2010 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.jme3.scene.debug;
+
+import com.jme3.bounding.BoundingSphere;
+import com.jme3.math.FastMath;
+import com.jme3.scene.Mesh;
+import com.jme3.scene.Mesh.Mode;
+import com.jme3.scene.VertexBuffer;
+import com.jme3.scene.VertexBuffer.Format;
+import com.jme3.scene.VertexBuffer.Type;
+import com.jme3.scene.VertexBuffer.Usage;
+import com.jme3.util.BufferUtils;
+import java.nio.FloatBuffer;
+import java.nio.ShortBuffer;
+
+public class WireSphere extends Mesh {
+
+ private static final int samples = 30;
+ private static final int zSamples = 10;
+
+ public WireSphere() {
+ this(1);
+ }
+
+ public WireSphere(float radius) {
+ updatePositions(radius);
+ ShortBuffer ib = BufferUtils.createShortBuffer(samples * 2 * 2 + zSamples * samples * 2 /*+ 3 * 2*/);
+ setBuffer(Type.Index, 2, ib);
+
+// ib.put(new byte[]{
+// (byte) 0, (byte) 1,
+// (byte) 2, (byte) 3,
+// (byte) 4, (byte) 5,
+// });
+
+// int curNum = 3 * 2;
+ int curNum = 0;
+ for (int j = 0; j < 2 + zSamples; j++) {
+ for (int i = curNum; i < curNum + samples - 1; i++) {
+ ib.put((short) i).put((short) (i + 1));
+ }
+ ib.put((short) (curNum + samples - 1)).put((short) curNum);
+ curNum += samples;
+ }
+
+ setMode(Mode.Lines);
+
+ updateBound();
+ updateCounts();
+ }
+
+ public void updatePositions(float radius) {
+ VertexBuffer pvb = getBuffer(Type.Position);
+ FloatBuffer pb;
+
+ if (pvb == null) {
+ pvb = new VertexBuffer(Type.Position);
+ pb = BufferUtils.createVector3Buffer(samples * 2 + samples * zSamples /*+ 6 * 3*/);
+ pvb.setupData(Usage.Dynamic, 3, Format.Float, pb);
+ setBuffer(pvb);
+ } else {
+ pb = (FloatBuffer) pvb.getData();
+ }
+
+ pb.rewind();
+
+ // X axis
+// pb.put(radius).put(0).put(0);
+// pb.put(-radius).put(0).put(0);
+//
+// // Y axis
+// pb.put(0).put(radius).put(0);
+// pb.put(0).put(-radius).put(0);
+//
+// // Z axis
+// pb.put(0).put(0).put(radius);
+// pb.put(0).put(0).put(-radius);
+
+ float rate = FastMath.TWO_PI / (float) samples;
+ float angle = 0;
+ for (int i = 0; i < samples; i++) {
+ float x = radius * FastMath.cos(angle);
+ float y = radius * FastMath.sin(angle);
+ pb.put(x).put(y).put(0);
+ angle += rate;
+ }
+
+ angle = 0;
+ for (int i = 0; i < samples; i++) {
+ float x = radius * FastMath.cos(angle);
+ float y = radius * FastMath.sin(angle);
+ pb.put(0).put(x).put(y);
+ angle += rate;
+ }
+
+ float zRate = (radius * 2) / (float) (zSamples);
+ float zHeight = -radius + (zRate / 2f);
+
+
+ float rb = 1f / zSamples;
+ float b = rb / 2f;
+
+ for (int k = 0; k < zSamples; k++) {
+ angle = 0;
+ float scale = FastMath.sin(b * FastMath.PI);
+ for (int i = 0; i < samples; i++) {
+ float x = radius * FastMath.cos(angle);
+ float y = radius * FastMath.sin(angle);
+
+ pb.put(x * scale).put(zHeight).put(y * scale);
+
+ angle += rate;
+ }
+ zHeight += zRate;
+ b += rb;
+ }
+ }
+
+ /**
+ * Create a WireSphere from a BoundingSphere
+ *
+ * @param bsph
+ * BoundingSphere used to create the WireSphere
+ *
+ */
+ public void fromBoundingSphere(BoundingSphere bsph) {
+ updatePositions(bsph.getRadius());
+ }
+}
|