我将在 Andengine 中创建具有指定顶点的独特主体
我已经用这些顶点制作了一个网格,但是在将身体注册到网格时遇到了问题
Eclispe 将这段代码的最后一行红色下划线:
Mesh UniqueBodyMesh = new Mesh(0, 0, MeshTriangles,UniqueBodyVerticesTriangulated.size(), DrawMode.TRIANGLES,this.getVertexBufferObjectManager());
UniqueBodyMesh.setColor(1f, 0f, 0f);
mScene.attachChild(UniqueBodyMesh);
FixtureDef uniqueBodyFixtureDef = PhysicsFactory.createFixtureDef(20f,0.5f, 0.5f);
Body uniqueBody = PhysicsFactory.createTrianglulatedBody(mPhysicsWorld,UniqueBodyMesh, UniqueBodyVerticesTriangulated,BodyType.DynamicBody, uniqueBodyFixtureDef);
mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(UniqueBodyMesh, uniqueBody));
我尝试编写一个扩展 Mesh 并实现 IAreaShape 并使用我自己的算法计算形状的宽度和高度的类,但它似乎完全错误并且不起作用
class myMesh extends Mesh implements IAreaShape
{
private float mWidth;
private float mHeight;
float[] mBufferData;
public myMesh(float pX, float pY, float[] pBufferData,
int pVertexCount, DrawMode pDrawMode,
VertexBufferObjectManager pVertexBufferObjectManager) {
super(pX, pY, pBufferData, pVertexCount, pDrawMode, pVertexBufferObjectManager);
mBufferData = pBufferData;
}
@Override
public float getWidth() {
float minX = 100000;
float maxX = -100000;
for(int i=0;i<mBufferData.length;i+=3)
{
if(mBufferData[i] < minX)
{
minX = mBufferData[i];
}
if(mBufferData[i] > maxX)
{
maxX = mBufferData[i];
}
}
System.out.println("Width : " + (maxX - minX));
mWidth = maxX - minX;
return mWidth;
}
@Override
public float getHeight() {
float minY = 100000;
float maxY = -100000;
for(int i=1;i<mBufferData.length;i+=3)
{
if(mBufferData[i] < minY)
{
minY = mBufferData[i];
}
if(mBufferData[i] > maxY)
{
maxY = mBufferData[i];
}
}
this.mHeight = maxY - minY;
return mHeight;
}
@Override
public float getWidthScaled() {
return getWidth();
}
@Override
public float getHeightScaled() {
return getHeight();
}
@Override
public void setHeight(float pHeight) {
this.mHeight = pHeight;
}
@Override
public void setWidth(float pWidth) {
this.mWidth = pWidth;
}
@Override
public void setSize(float pWidth, float pHeight) {
setWidth(pWidth);
setHeight(pHeight);
}
}
}