View previous topic :: View next topic |
Author |
Message |
mike
Joined: 28 Dec 2008 Posts: 34
|
Posted: Sat Mar 21, 2009 11:02 am Post subject: Polygon worldVertices error? |
|
|
I kept getting object exception error whenever i made a call to worldVertices. I changed the code by adding one parameter to the function and it seemed to fix it but im not sure if its the correct way to do it.
Code: | bzVec2[] worldVertices(bzBody rBody) {
bzVec2[] worldVertices;
worldVertices.length = m_vertices.length;
bzXForm xf = rBody.xf; //I think i was getting the error here
for (int i = 0; i < m_vertices.length; i++) {
worldVertices[i] = bzMul(xf, m_vertices[i]);
}
return worldVertices;
} |
|
|
Back to top |
|
|
zzzzrrr
Joined: 17 Feb 2007 Posts: 139 Location: Washington, DC
|
Posted: Sat Mar 21, 2009 11:52 am Post subject: Re: Polygon worldVertices error? |
|
|
mike wrote: | I kept getting object exception error whenever i made a call to worldVertices. I changed the code by adding one parameter to the function and it seemed to fix it but im not sure if its the correct way to do it. |
Is your shape attached to a rigid body? If not, you should do it like so:
Code: |
auto rBody = world.createBody(bodyDef);
auto shape = cast(bzPolygon) rBody.createShape(shapeDef);
bzVec2[] worldVerts = shape.worldVertices;
|
|
|
Back to top |
|
|
mike
Joined: 28 Dec 2008 Posts: 34
|
Posted: Sat Mar 21, 2009 2:38 pm Post subject: |
|
|
I had rBody[0].createShape(shapeDef[0]); to have the shape attached to the body and then i had bzPolygon test1 = new bzPolygon(shapeDef[0]); and then i called the worldvertices.
I didn't know you had to cast the shape to a polygon.
Thanks for the help. It works properly now. |
|
Back to top |
|
|
zzzzrrr
Joined: 17 Feb 2007 Posts: 139 Location: Washington, DC
|
Posted: Sat Mar 21, 2009 3:01 pm Post subject: |
|
|
mike wrote: | then i had bzPolygon test1 = new bzPolygon(shapeDef[0]) |
I would not recommend creating shapes this way. The preferred method is:
Code: | rBody.createShape(shapeDef); |
Quote: | Thanks for the help. It works properly now. |
great, anytime! |
|
Back to top |
|
|
|