polygon_idx is only supported by some objects. Not all. On what kind
of mesh object are you trying this?
Greetings,
On 2/20/06, Amir Taaki <[EMAIL PROTECTED]> wrote:
> Hi,
>
> 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 ();
> start = rt.Other2ThisRelative (start);
> end = rt.Other2ThisRelative (end);
> csHitBeamResult res = world_mesh->GetMesh ()->HitBeamObject (start, end);
>
>
> As above I'm converting the start and end to the mesh which I'm testing on
> into its local co-ordinates.
>
> 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
>
--
Project Manager of Crystal Space (http://www.crystalspace3d.org)
and CEL (http://cel.crystalspace3d.org)
Support Crystal Space. Donate at
https://sourceforge.net/donate/index.php?group_id=649
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid3432&bid#0486&dat1642
_______________________________________________
Crystal-main mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/crystal-main
Unsubscribe: mailto:[EMAIL PROTECTED]