Apparently csHitBeam result stores the polygon index (polygon_idx) of the face that was hit. My goal is to get the normal vector of the face that has been hit by my csHitBeam test.
iPolygonMesh* wpolymesh = world_mesh->GetMesh ()->GetMeshObject ()->
GetObjectModel ()->GetPolygonMeshBase ();
csTriangle* wtris = wpolymesh->GetTriangles ();
csVector3* wverts = wpolymesh->GetVertices ();printf("index: %i\n",res.polygon_idx); if ((res.polygon_idx > 0) && (res.polygon_idx < wpolymesh->GetTriangleCount ())) { csTriangle tri = wtris [res.polygon_idx]; int vertc = wpolymesh->GetVertexCount (); if ((tri.a < vertc) && (tri.b < vertc) && (tri.c < vertc)) { csVector3 a = wverts [tri.a], b = wverts [tri.b], c = wverts [tri.c]; printf("(%f, %f, %f) (%f, %f, %f) (%f, %f, %f)\n",a.x,a.y,a.z,b.x,b.y, b.z,c.x,c.y,c.z); csPoly3D poly; poly.AddVertex (a); poly.AddVertex (b); poly.AddVertex (c); csVector3 upthrust = poly.ComputeNormal () * force; ship_mech->AddForceDuration(upthrust, false, csVector3 (0,0,0), 0.1f); //pcmechobj->AddForceOnce (csVector3 (0,force,0), false, csVector3 (0,0,0)); //pcmechobj->SetLinearVelocity (pcmechobj->GetLinearVelocity () + csVector3 (0,force,0)); } }Here I'm basically getting the triangles and using the index to get the triangle, and get the verts for that face, construct a csPoly3D then use the ComputeNormal function.
When I run it, I get some extreme negative value for res.polygon_idx!, so looking in the docs I see that polygon_idx is only valid for HitBeamObject (and not HitBeam for some strange reason).
csReversibleTransform rt = world_mesh->GetMesh ()->GetMovable ()->GetFullTransform ();As above I'm converting the start and end to the mesh which I'm testing on into its local co-ordinates.
start = rt.Other2ThisRelative (start);
end = rt.Other2ThisRelative (end);
csHitBeamResult res = world_mesh->GetMesh ()->HitBeamObject (start, end);
Re-running the first piece of code, and now I see that even though I have a valid res.r (the hitbeam is working), that now res.polygon_idx is always -1 ... What is going on here?
Is there an easy way I can get the normal vector of the face that the hitbeam has intersected on the mesh?
Thanks.
Amir Taaki
