/*
|
* Java port of Bullet (c) 2008 Martin Dvorak <jezek2@advel.cz>
|
*
|
* Bullet Continuous Collision Detection and Physics Library
|
* Ragdoll Demo
|
* Copyright (c) 2007 Starbreeze Studios
|
*
|
* This software is provided 'as-is', without any express or implied warranty.
|
* In no event will the authors be held liable for any damages arising from
|
* the use of this software.
|
*
|
* Permission is granted to anyone to use this software for any purpose,
|
* including commercial applications, and to alter it and redistribute it
|
* freely, subject to the following restrictions:
|
*
|
* 1. The origin of this software must not be misrepresented; you must not
|
* claim that you wrote the original software. If you use this software
|
* in a product, an acknowledgment in the product documentation would be
|
* appreciated but is not required.
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
* misrepresented as being the original software.
|
* 3. This notice may not be removed or altered from any source distribution.
|
*
|
* Originally Written by: Marten Svanfeldt
|
* ReWritten by: Francisco Le�n
|
*/
|
|
//package com.bulletphysics.demos.genericjoint;
|
import com.bulletphysics.util.ObjectArrayList;
|
//import com.bulletphysics.demos.opengl.DemoApplication;
|
//import com.bulletphysics.demos.opengl.GLDebugDrawer;
|
//import com.bulletphysics.demos.opengl.IGL;
|
//import com.bulletphysics.demos.opengl.LWJGL;
|
import javax.media.opengl.GL;
|
import javax.media.opengl.glu.GLU;
|
import com.bulletphysics.linearmath.Transform;
|
import com.bulletphysics.util.ObjectPool;
|
import com.bulletphysics.util.IntArrayList;
|
import javax.vecmath.Vector3f;
|
import javax.vecmath.Vector3d;
|
import javax.vecmath.Color3f;
|
//import org.lwjgl.LWJGLException;
|
//import static com.bulletphysics.demos.opengl.IGL.*;
|
|
import com.bulletphysics.linearmath.MiscUtil;
|
//import com.bulletphysics.dynamics.constraintsolver.TypedConstraint;
|
import com.bulletphysics.dynamics.constraintsolver.Generic6DofConstraint;
|
|
import java.util.Map;
|
import java.util.HashMap;
|
|
//import org.lwjgl.util.glu.Cylinder;
|
//import org.lwjgl.util.glu.Disk;
|
//import org.lwjgl.util.glu.Sphere;
|
/**
|
*
|
* @author jezek2
|
*/
|
public class Merge extends Object3D // should be ShareNode
|
{
|
static final long serialVersionUID = 7607169702771805102L; // -2574299047421149815L;
|
|
Object3D object;
|
|
Object3D GetObject()
|
{
|
if (object != null)
|
{
|
assert(support == null);
|
|
support = object;
|
object = null;
|
}
|
|
return support;
|
}
|
|
boolean IsStatic()
|
{
|
return false;
|
}
|
|
public Merge(Object3D obj)
|
{
|
super("Sh:" + obj.name);
|
|
object = obj;
|
|
CreateMaterial();
|
|
link2master = true;
|
}
|
|
void resetMasterNode(boolean smooth)
|
{
|
// no support allowed (aout 2013)
|
}
|
|
void Reset()
|
{
|
GetObject().Reset();
|
|
// if (object instanceof Mocap)
|
// ((Mocap)object).SmoothAnimData();
|
}
|
|
void Step()
|
{
|
GetObject().Step();
|
}
|
|
void linkVerticesThis(Object3D other)
|
{
|
// object means support...
|
|
object = other;
|
|
String _name = "null";
|
|
if (GetObject() != null)
|
_name = GetObject().name;
|
|
name = "Merge:" + _name;
|
|
link2master = GetObject() != null;
|
|
bRep = null;
|
|
if (Link2Support())
|
renderme(); // null);
|
}
|
|
transient cVector minima = new cVector();
|
transient cVector maxima = new cVector();
|
|
// ObjectArrayList<Transform> initialmatrices;
|
transient boolean rendered = false;
|
|
void DrawNode(iCameraPane display, Object3D /*Composite*/ root, boolean selected) // ??
|
{
|
//if (support == null)
|
// System.err.println("DrawNode Merge # " + ((Mocap)object).frame);
|
|
if (bRep == null && GetObject() != null)
|
renderme(); // display); // only once
|
|
if (/*display.LIVE && live &&*/Link2Support()) // && display.drawMode == display.SHADOW) // SHADOW!!!
|
{
|
try
|
{
|
renderme(); // display);
|
}
|
catch(Exception e)
|
{
|
e.printStackTrace();
|
}
|
|
rendered = true;
|
}
|
|
super.DrawNode(display, root, selected);
|
|
// debug stuff
|
if (false) // bRep.averagepoints != null)
|
{
|
// javax.media.opengl.GL gl = display.GetGL();
|
//
|
// gl.glColor3f(1, 0, 0);
|
// //gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
|
// //gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
|
//
|
// for (int i=0; i<NumGeometries(GetObject()); i++)
|
// {
|
// int i3 = i*3;
|
//
|
// float off = 0.005f;
|
//
|
// gl.glBegin(gl.GL_LINES);
|
// gl.glVertex3d(bRep.averagepoints[i3]-off, bRep.averagepoints[i3+1], bRep.averagepoints[i3+2]);
|
// gl.glVertex3d(bRep.averagepoints[i3]+off, bRep.averagepoints[i3+1], bRep.averagepoints[i3+2]);
|
// gl.glVertex3d(bRep.averagepoints[i3], bRep.averagepoints[i3+1]-off, bRep.averagepoints[i3+2]);
|
// gl.glVertex3d(bRep.averagepoints[i3], bRep.averagepoints[i3+1]+off, bRep.averagepoints[i3+2]);
|
// gl.glVertex3d(bRep.averagepoints[i3], bRep.averagepoints[i3+1], bRep.averagepoints[i3+2]-off);
|
// gl.glVertex3d(bRep.averagepoints[i3], bRep.averagepoints[i3+1], bRep.averagepoints[i3+2]+off);
|
// gl.glEnd();
|
// }
|
}
|
}
|
|
// GL gl0;
|
private FontRender.GLFont font;
|
|
public void initFont(GL gl, GLU glu)
|
{
|
try
|
{
|
//font = FontRender.createFont("Dialog", 11, false, true);
|
font = new FontRender.GLFont(gl, Grafreed.class.getResourceAsStream("DejaVu_Sans_11.fnt"));
|
} catch (java.io.IOException e)
|
{
|
e.printStackTrace();
|
}
|
}
|
|
public void drawString(GL gl, GLU glu, CharSequence s, int x, int y, float red, float green, float blue)
|
{
|
if (font == null)
|
{
|
initFont(gl, glu);
|
}
|
//if (font != null)
|
{
|
FontRender.drawString(gl, font, s, x, y, red, green, blue);
|
}
|
}
|
|
public void drawString(GL gl, GLU glu, CharSequence s, int x, int y, Color3f color)
|
{
|
drawString(gl, glu, s, x, y, color.x, color.y, color.z);
|
}
|
|
transient private /*final*/ Transform m; // = new Transform();
|
transient private /*final*/ Transform m_1; // = new Transform();
|
transient private /*final*/ Transform temp;
|
private Vector3f wireColor = new Vector3f();
|
protected Color3f TEXT_COLOR = new Color3f(0f, 0f, 0f);
|
private StringBuilder buf = new StringBuilder();
|
protected int debugMode = 0;
|
|
public int getDebugMode()
|
{
|
return debugMode;
|
}
|
|
boolean buildrep;
|
int startvertex;
|
int currentobject;
|
|
public void renderme() // CameraPane display)
|
{
|
GL gl = null; // display!=null?display.getGL():null;
|
|
if (m == null)
|
{
|
m = new Transform();
|
m_1 = new Transform();
|
temp = new Transform();
|
m.setIdentity();
|
m_1.setIdentity();
|
}
|
|
|
// int numObjects = 0; // mysize; // dynamicsWorld.getNumCollisionObjects();
|
|
//Transform trans = new Transform();
|
|
buildrep = false;
|
startvertex = 0;
|
|
if (bRep == null)
|
{
|
bRep = new BoundaryRep();
|
bRep.startvertices = new int[NumGeometries(GetObject()) + 1];
|
bRep.averagepoints = new float[(bRep.startvertices.length-1) * 3];
|
bRep.extremepoints = new float[(bRep.startvertices.length-1) * 3];
|
bRep.supportminsize = new float[(bRep.startvertices.length-1)];
|
bRep.supportmaxsize = new float[(bRep.startvertices.length-1)];
|
buildrep = true;
|
|
// initialmatrices = new ObjectArrayList<Transform>();
|
|
// MiscUtil.resize(initialmatrices, numObjects, Transform.class);
|
}
|
|
currentobject = 0;
|
ParseObject(GetObject());
|
}
|
|
public int NumGeometries(Object3D obj)
|
{
|
int num = 0;
|
|
if (obj.bRep != null)
|
{
|
num += 1;
|
}
|
|
for (int i = 0; i < obj.size(); i++)
|
{
|
Object3D child = obj.reserve(i);
|
if (child == null)
|
continue;
|
num += NumGeometries(child);
|
obj.release(i);
|
}
|
|
return num;
|
}
|
|
|
public void ParseObject(Object3D obj)
|
{
|
if (obj.cache == null)
|
{
|
obj.cache = new Transform();
|
obj.cache_1 = new Transform();
|
}
|
|
obj.cache.set(m);
|
obj.cache_1.set(m_1);
|
|
if (obj.toParent != null)
|
{
|
temp.origin.x = (float)obj.toParent[3][0];
|
temp.origin.y = (float)obj.toParent[3][1];
|
temp.origin.z = (float)obj.toParent[3][2];
|
|
temp.basis.m00 = (float)obj.toParent[0][0];
|
temp.basis.m01 = (float)obj.toParent[1][0];
|
temp.basis.m02 = (float)obj.toParent[2][0];
|
temp.basis.m10 = (float)obj.toParent[0][1];
|
temp.basis.m11 = (float)obj.toParent[1][1];
|
temp.basis.m12 = (float)obj.toParent[2][1];
|
temp.basis.m20 = (float)obj.toParent[0][2];
|
temp.basis.m21 = (float)obj.toParent[1][2];
|
temp.basis.m22 = (float)obj.toParent[2][2];
|
|
for (int i=obj.GetTransformCount(); --i>=0;)
|
m.mul(temp);
|
|
temp.origin.x = (float)obj.fromParent[3][0];
|
temp.origin.y = (float)obj.fromParent[3][1];
|
temp.origin.z = (float)obj.fromParent[3][2];
|
|
temp.basis.m00 = (float)obj.fromParent[0][0];
|
temp.basis.m01 = (float)obj.fromParent[1][0];
|
temp.basis.m02 = (float)obj.fromParent[2][0];
|
temp.basis.m10 = (float)obj.fromParent[0][1];
|
temp.basis.m11 = (float)obj.fromParent[1][1];
|
temp.basis.m12 = (float)obj.fromParent[2][1];
|
temp.basis.m20 = (float)obj.fromParent[0][2];
|
temp.basis.m21 = (float)obj.fromParent[1][2];
|
temp.basis.m22 = (float)obj.fromParent[2][2];
|
|
for (int i=obj.GetTransformCount(); --i>=0;)
|
{
|
//temp.mul(m_1);
|
//m_1.set(temp);
|
m_1.mul(temp, m_1);
|
}
|
}
|
|
if (obj.bRep != null)
|
{
|
currentobject++;
|
|
m_1.basis.transpose(); // only for normal
|
UpdateVertices(obj.bRep, wireColor, getDebugMode());
|
m_1.basis.transpose(); // only for normal
|
}
|
|
for (int i = 0; i < obj.size(); i++)
|
{
|
Object3D child = obj.reserve(i);
|
if (child == null)
|
continue;
|
ParseObject(child);
|
obj.release(i);
|
}
|
|
m.set(obj.cache);
|
m_1.set(obj.cache_1);
|
|
// // for (currentobject = 1; currentobject < numObjects; currentobject++)
|
// {
|
// int i = currentobject;
|
// CollisionObject colObj = null; // GetDynamicsWorld().getCollisionObjectArray().getQuick(i);
|
// RigidBody body = RigidBody.upcast(colObj);
|
//
|
// if (body != null && body.getMotionState() != null)
|
// {
|
// DefaultMotionState myMotionState = (DefaultMotionState) body.getMotionState();
|
// m.set(myMotionState.graphicsWorldTrans);
|
//
|
// // Vector3f v = ragdolls.get(0).bodies[0].worldTransform.origin;
|
// // m.origin.x -= v.x; // uses tween instead!
|
// // m.origin.z -= v.z;
|
//
|
// if (buildrep)
|
// initialmatrices.getQuick(currentobject).set(m);
|
// } else
|
// {
|
// colObj.getWorldTransform(m);
|
// }
|
//
|
// /*GLShapeDrawer.*/
|
// // System.out.print("x");
|
// drawOpenGL(m, obj.bRep, wireColor, getDebugMode());
|
// }
|
|
}
|
|
public void drawCube(iCameraPane display, float extent)
|
{
|
GL gl = display.GetGL0();
|
|
extent = extent * 0.5f;
|
|
gl.glBegin(gl.GL_QUADS);
|
gl.glNormal3f(1f, 0f, 0f);
|
gl.glVertex3f(+extent, -extent, +extent);
|
gl.glVertex3f(+extent, -extent, -extent);
|
gl.glVertex3f(+extent, +extent, -extent);
|
gl.glVertex3f(+extent, +extent, +extent);
|
gl.glNormal3f(0f, 1f, 0f);
|
gl.glVertex3f(+extent, +extent, +extent);
|
gl.glVertex3f(+extent, +extent, -extent);
|
gl.glVertex3f(-extent, +extent, -extent);
|
gl.glVertex3f(-extent, +extent, +extent);
|
gl.glNormal3f(0f, 0f, 1f);
|
gl.glVertex3f(+extent, +extent, +extent);
|
gl.glVertex3f(-extent, +extent, +extent);
|
gl.glVertex3f(-extent, -extent, +extent);
|
gl.glVertex3f(+extent, -extent, +extent);
|
gl.glNormal3f(-1f, 0f, 0f);
|
gl.glVertex3f(-extent, -extent, +extent);
|
gl.glVertex3f(-extent, +extent, +extent);
|
gl.glVertex3f(-extent, +extent, -extent);
|
gl.glVertex3f(-extent, -extent, -extent);
|
gl.glNormal3f(0f, -1f, 0f);
|
gl.glVertex3f(-extent, -extent, +extent);
|
gl.glVertex3f(-extent, -extent, -extent);
|
gl.glVertex3f(+extent, -extent, -extent);
|
gl.glVertex3f(+extent, -extent, +extent);
|
gl.glNormal3f(0f, 0f, -1f);
|
gl.glVertex3f(-extent, -extent, -extent);
|
gl.glVertex3f(-extent, +extent, -extent);
|
gl.glVertex3f(+extent, +extent, -extent);
|
gl.glVertex3f(+extent, -extent, -extent);
|
gl.glEnd();
|
}
|
|
private /*static*/ float[] glMat = new float[16];
|
|
// was "drawOpenGL"
|
public void UpdateVertices(BoundaryRep shape, Vector3f color, int debugMode)
|
{
|
ObjectPool<Transform> transformsPool = ObjectPool.get(Transform.class);
|
ObjectPool<Vector3f> vectorsPool = ObjectPool.get(Vector3f.class);
|
|
//System.out.println("shape="+shape+" type="+BroadphaseNativeTypes.forValue(shape.getShapeType()));
|
|
//trans.getOpenGLMatrix(glMat);
|
//// display.PushMatrix(glMat);
|
// gl.glPushMatrix();
|
// gl.glMultMatrixf(glMat, 0);
|
|
// if (shape.getShapeType() == BroadphaseNativeTypes.UNIFORM_SCALING_SHAPE_PROXYTYPE.getValue())
|
// {
|
// const btUniformScalingShape* scalingShape = static_cast<const btUniformScalingShape*>(shape);
|
// const btConvexShape* convexShape = scalingShape->getChildShape();
|
// float scalingFactor = (float)scalingShape->getUniformScalingFactor();
|
// {
|
// btScalar tmpScaling[4][4]={{scalingFactor,0,0,0},
|
// {0,scalingFactor,0,0},
|
// {0,0,scalingFactor,0},
|
// {0,0,0,1}};
|
//
|
// drawOpenGL( (btScalar*)tmpScaling,convexShape,color,debugMode);
|
// }
|
// glPopMatrix();
|
// return;
|
// }
|
|
{
|
//drawCoordSystem();
|
|
//glPushMatrix();
|
|
// gl.glEnable(gl.GL_COLOR_MATERIAL);
|
// gl.glColor3f(color.x, color.y, color.z);
|
|
// boolean useWireframeFallback = true;
|
|
// if ((debugMode & DebugDrawModes.DRAW_WIREFRAME) == 0)
|
{
|
// you can comment out any of the specific cases, and use the default
|
// the benefit of 'default' is that it approximates the actual collision shape including collision margin
|
|
// switch (shape.getShapeType())
|
{
|
// default:
|
{
|
// if (shape.isConvex())
|
{
|
// ConvexShape convexShape = (ConvexShape) shape;
|
// if (shape.getUserPointer() == null)
|
// {
|
// // create a hull approximation
|
// ShapeHull hull = new ShapeHull(convexShape);
|
//
|
// // JAVA NOTE: not needed
|
// ///// cleanup memory
|
// //m_shapeHulls.push_back(hull);
|
//
|
// float margin = shape.getMargin();
|
// hull.buildHull(margin);
|
// convexShape.setUserPointer(hull);
|
//
|
// //printf("numTriangles = %d\n", hull->numTriangles ());
|
// //printf("numIndices = %d\n", hull->numIndices ());
|
// //printf("numVertices = %d\n", hull->numVertices ());
|
// }
|
//
|
// if (shape.getUserPointer() != null)
|
{
|
//glutSolidCube(1.0);
|
//ShapeHull hull = (ShapeHull) shape.getUserPointer();
|
BoundaryRep hull = shape;
|
|
// ObjectArrayList<Vector3f> vtx = null; // hull.getVertexPointer();
|
// ObjectArrayList<Vector3f> normals = null; // hull.getNormalPointer();
|
|
//Vector3f center = vectorsPool.get();
|
Vector3f tmp1 = vectorsPool.get();
|
// Vector3f normal = vectorsPool.get();
|
// Vector3f tmp2 = vectorsPool.get();
|
|
if (buildrep) // bRep == null || bRep.FaceCount() != hull.numTriangles())
|
{
|
// center.x = center.y = center.z = 0;
|
//
|
// for (int i = 0; i < hull.VertexCount(); i++)
|
// {
|
// Vertex v = vtx.getQuick(i);
|
//
|
// // tmp1.set(v);
|
// // trans.transform(tmp1);
|
//
|
// center.x += v.x;
|
// center.y += v.y;
|
// center.z += v.z;
|
// }
|
//
|
// center.x /= vtx.size();
|
// center.y /= vtx.size();
|
// center.z /= vtx.size();
|
//bRep = new BoundaryRep();
|
|
Vertex vert = new Vertex(true);
|
|
int totalvertices = 0;
|
|
int index = 0;
|
//IntArrayList idx = hull.getIndexPointer();
|
for (int i = 0; i < hull.FaceCount(); i++)
|
{
|
Face f = hull.GetFace(i);
|
|
if (f == null)
|
continue;
|
|
Vertex v1 = hull.GetVertex(f.p);
|
Vertex v2 = hull.GetVertex(f.q);
|
Vertex v3 = hull.GetVertex(f.r);
|
|
int qx;
|
int rx;
|
int px; // = qx = rx = -1;
|
|
//LA.vecCopy(p, vert/*.pos*/);
|
//LA.vecCopy(p.norm, vert.norm);
|
tmp1.set((float)v1.x,(float)v1.y,(float)v1.z);
|
//Vector3f normal = normals.getQuick(f.p);
|
cVector normal = v1.norm;
|
//normal.set(tmp1);
|
//normal.sub(center);
|
//normal.normalize();
|
m.transform(tmp1);
|
vert.x = tmp1.x;
|
vert.y = tmp1.y;
|
vert.z = tmp1.z;
|
tmp1.set((float)normal.x,(float)normal.y,(float)normal.z);
|
// m_1.basis.transpose();
|
m_1.basis.transform(tmp1);
|
// m_1.basis.transpose();
|
vert.norm.x = tmp1.x;
|
vert.norm.y = tmp1.y;
|
vert.norm.z = tmp1.z;
|
vert.norm.normalize();
|
vert.supportindex = f.p+startvertex;
|
Vertex in = bRep.GetCache(vert);
|
if (in != null)
|
{
|
px = in.index;
|
} else
|
{
|
totalvertices += 1;
|
Vertex vert2 = new Vertex(true);
|
LA.vecCopy(vert/*.pos*/, vert2/*.pos*/);
|
LA.vecCopy(vert.norm, vert2.norm);
|
px = bRep.VertexCount();
|
vert2.index = px;
|
vert2.supportindex = vert.supportindex;
|
//bRep.AddVertex(vert2);
|
bRep.Remember(vert2);
|
}
|
|
// LA.vecCopy(q, vert/*.pos*/);
|
// LA.vecCopy(q.norm, vert.norm);
|
tmp1.set((float)v2.x,(float)v2.y,(float)v2.z);
|
//normal = normals.getQuick(f.q);
|
normal = v2.norm;
|
//normal.set(tmp1);
|
//normal.sub(center);
|
//normal.normalize();
|
m.transform(tmp1);
|
vert.x = tmp1.x;
|
vert.y = tmp1.y;
|
vert.z = tmp1.z;
|
tmp1.set((float)normal.x,(float)normal.y,(float)normal.z);
|
// m_1.basis.transpose();
|
m_1.basis.transform(tmp1);
|
// m_1.basis.transpose();
|
vert.norm.x = tmp1.x;
|
vert.norm.y = tmp1.y;
|
vert.norm.z = tmp1.z;
|
vert.norm.normalize();
|
vert.supportindex = f.q+startvertex;
|
in = bRep.GetCache(vert);
|
if (in != null)
|
{
|
qx = in.index;
|
} else
|
{
|
totalvertices += 1;
|
Vertex vert2 = new Vertex(true);
|
LA.vecCopy(vert/*.pos*/, vert2/*.pos*/);
|
LA.vecCopy(vert.norm, vert2.norm);
|
qx = bRep.VertexCount(); // vertices.size();
|
vert2.index = qx;
|
vert2.supportindex = vert.supportindex;
|
//bRep.AddVertex(vert2);
|
bRep.Remember(vert2); // vertextable.put(vert2, vert2);
|
}
|
|
// LA.vecCopy(r, vert/*.pos*/);
|
// LA.vecCopy(r.norm, vert.norm);
|
tmp1.set((float)v3.x,(float)v3.y,(float)v3.z);
|
//normal = normals.getQuick(f.r);
|
normal = v3.norm;
|
//normal.set(tmp1);
|
//normal.sub(center);
|
//normal.normalize();
|
m.transform(tmp1);
|
vert.x = tmp1.x;
|
vert.y = tmp1.y;
|
vert.z = tmp1.z;
|
tmp1.set((float)normal.x,(float)normal.y,(float)normal.z);
|
// m_1.basis.transpose();
|
m_1.basis.transform(tmp1);
|
// m_1.basis.transpose();
|
vert.norm.x = tmp1.x;
|
vert.norm.y = tmp1.y;
|
vert.norm.z = tmp1.z;
|
vert.norm.normalize();
|
vert.supportindex = f.r+startvertex;
|
in = bRep.GetCache(vert);
|
if (in != null)
|
{
|
rx = in.index;
|
} else
|
{
|
totalvertices += 1;
|
Vertex vert2 = new Vertex(true);
|
LA.vecCopy(vert/*.pos*/, vert2/*.pos*/);
|
LA.vecCopy(vert.norm, vert2.norm);
|
rx = bRep.VertexCount();
|
vert2.index = rx;
|
vert2.supportindex = vert.supportindex;
|
//bRep.AddVertex(vert2);
|
bRep.Remember(vert2);
|
}
|
|
bRep.AddFace(px, qx, rx);
|
}
|
|
//startvertex += totalvertices;
|
bRep.startvertices[currentobject] = bRep.startvertices[currentobject-1] + totalvertices;
|
}
|
else
|
{
|
if (bRep.averagepoints == null || bRep.extremepoints == null || bRep.supportminsize == null || bRep.supportmaxsize == null)
|
{
|
bRep.averagepoints = new float[(bRep.startvertices.length-1) * 3];
|
bRep.extremepoints = new float[(bRep.startvertices.length-1) * 3];
|
bRep.supportminsize = new float[(bRep.startvertices.length-1)];
|
bRep.supportmaxsize = new float[(bRep.startvertices.length-1)];
|
}
|
|
float averagex = 0;
|
float averagey = 0;
|
float averagez = 0;
|
|
int count = 0;
|
|
for (int i=bRep.startvertices[currentobject-1]; i<bRep.startvertices[currentobject]; i++)
|
{
|
Vertex v = bRep.GetVertex(i);
|
//Vector3f v1 = vtx.getQuick(v.supportindex);
|
Vertex v1 = shape.GetVertex(v.supportindex);
|
//Vector3f normal = normals.getQuick(v.supportindex);
|
cVector normal = v1.norm;
|
|
tmp1.set((float)v1.x,(float)v1.y,(float)v1.z);
|
m.transform(tmp1);
|
|
v.x = tmp1.x;
|
v.y = tmp1.y;
|
v.z = tmp1.z;
|
|
averagex += v.x;
|
averagey += v.y;
|
averagez += v.z;
|
count++;
|
|
tmp1.set((float)normal.x,(float)normal.y,(float)normal.z);
|
// m_1.basis.transpose(); // hmmm...
|
m_1.basis.transform(tmp1);
|
// m_1.basis.transpose();
|
|
v.norm.x = tmp1.x;
|
v.norm.y = tmp1.y;
|
v.norm.z = tmp1.z;
|
|
v.norm.normalize();
|
}
|
|
if (!rendered)
|
{
|
int index3 = currentobject-1;
|
index3 *= 3;
|
|
bRep.averagepoints[index3] = averagex/count;
|
bRep.averagepoints[index3+1] = averagey/count;
|
bRep.averagepoints[index3+2] = averagez/count;
|
|
double mindist2 = 1E10f;
|
double maxdist2 = -1E10f;
|
|
for (int i=bRep.startvertices[currentobject-1]; i<bRep.startvertices[currentobject]; i++)
|
{
|
Vertex v = bRep.GetVertex(i);
|
|
double x = v.x - bRep.averagepoints[index3];
|
double y = v.y - bRep.averagepoints[index3+1];
|
double z = v.z - bRep.averagepoints[index3+2];
|
|
double dist2 = x*x + y*y + z*z;
|
|
if (mindist2 > dist2)
|
mindist2 = dist2;
|
|
if (maxdist2 < dist2)
|
{
|
maxdist2 = dist2;
|
bRep.extremepoints[index3] = (float)v.x;
|
bRep.extremepoints[index3+1] = (float)v.y;
|
bRep.extremepoints[index3+2] = (float)v.z;
|
}
|
}
|
|
bRep.supportminsize[currentobject-1] = (float)Math.sqrt(mindist2);
|
bRep.supportmaxsize[currentobject-1] = (float)Math.sqrt(maxdist2);
|
// for (int i = 0; i < hull.numVertices(); i++)
|
// {
|
//
|
// }
|
}
|
}
|
|
// if (hull.numTriangles() > 0)
|
// {
|
// int index = 0;
|
// IntArrayList idx = hull.getIndexPointer();
|
// ObjectArrayList<Vector3f> vtx = hull.getVertexPointer();
|
//
|
// gl.glBegin(gl.GL_TRIANGLES);
|
//
|
// for (int i = 0; i < hull.numTriangles(); i++)
|
// {
|
// int i1 = index++;
|
// int i2 = index++;
|
// int i3 = index++;
|
// assert (i1 < hull.numIndices() &&
|
// i2 < hull.numIndices() &&
|
// i3 < hull.numIndices());
|
//
|
// int index1 = idx.get(i1);
|
// int index2 = idx.get(i2);
|
// int index3 = idx.get(i3);
|
// assert (index1 < hull.numVertices() &&
|
// index2 < hull.numVertices() &&
|
// index3 < hull.numVertices());
|
//
|
// Vector3f v1 = vtx.getQuick(index1);
|
// Vector3f v2 = vtx.getQuick(index2);
|
// Vector3f v3 = vtx.getQuick(index3);
|
// tmp1.sub(v3, v1);
|
// tmp2.sub(v2, v1);
|
// normal.cross(tmp2, tmp1);
|
// normal.normalize();
|
//
|
// gl.glNormal3f(normal.x, normal.y, normal.z);
|
// gl.glVertex3f(v1.x, v1.y, v1.z);
|
// gl.glVertex3f(v2.x, v2.y, v2.z);
|
// gl.glVertex3f(v3.x, v3.y, v3.z);
|
//
|
// }
|
// gl.glEnd();
|
// }
|
|
// vectorsPool.release(normal);
|
vectorsPool.release(tmp1);
|
// vectorsPool.release(tmp2);
|
}
|
}
|
// else
|
// {
|
// // printf("unhandled drawing\n");
|
// }
|
}
|
|
}
|
|
}
|
}
|
}
|
|
}
|