source: GTP/trunk/App/Games/Jungle_Rumble/src/physic/physics/include/NxUserRaycastReport.h @ 1378

Revision 1378, 6.5 KB checked in by giegl, 18 years ago (diff)

GTPD - Jungle Rumble - integrate into GTP SVN structure

Line 
1#ifndef NX_PHYSICS_NXRAYCAST
2#define NX_PHYSICS_NXRAYCAST
3/** \addtogroup physics
4  @{
5*/
6
7#include "Nxp.h"
8class NxShape;
9
10
11/**
12Used to specify which types(static or dynamic) of shape to test against when used with raycasting and
13overlap test methods in #NxScene.
14
15@see NxScene NxScene.raycastAllBounds() NxScene.raycastAllShapes() NxScene.raycastClosestBounds()
16NxScene.raycastClosestShape() NxScene.raycastAnyBounds() NxScene.raycastAnyShape() NxScene.overlapSphereShapes()
17NxScene.overlapAABBShapes()
18*/
19enum NxShapesType
20        {
21        NX_STATIC_SHAPES                = (1<<0),                                                               //!< Hits static shapes
22        NX_DYNAMIC_SHAPES               = (1<<1),                                                               //!< Hits dynamic shapes
23        NX_ALL_SHAPES                   = NX_STATIC_SHAPES|NX_DYNAMIC_SHAPES    //!< Hits both static & dynamic shapes
24        };
25
26/**
27
28Specifies which members of #NxRaycastHit which should be generated(when used as hint flags for raycasting methods)
29or which members have been generated when checking the flags member of #NxRaycastHit.
30
31@see NxRaycastHit
32*/
33enum NxRaycastBit
34        {
35        NX_RAYCAST_SHAPE                = (1<<0),                                                               //!< "shape" member of #NxRaycastHit is valid
36        NX_RAYCAST_IMPACT               = (1<<1),                                                               //!< "worldImpact" member of #NxRaycastHit is valid
37        NX_RAYCAST_NORMAL               = (1<<2),                                                               //!< "worldNormal" member of #NxRaycastHit is valid
38        NX_RAYCAST_FACE_INDEX   = (1<<3),                                                               //!< "faceID" member of #NxRaycastHit is valid
39        NX_RAYCAST_DISTANCE             = (1<<4),                                                               //!< "distance" member of #NxRaycastHit is valid
40        NX_RAYCAST_UV                   = (1<<5),                                                               //!< "u" and "v" members of #NxRaycastHit are valid
41        NX_RAYCAST_FACE_NORMAL  = (1<<6),                                                               //!< Same as NX_RAYCAST_NORMAL but computes a non-smoothed normal
42        NX_RAYCAST_MATERIAL             = (1<<7),                                                               //!< "material" member of #NxRaycastHit is valid
43        };
44
45/**
46\brief This structure captures results for a single raycast query.
47
48All members of the NxRaycastHit structure are not always available. For example when the ray hits a sphere,
49the faceID member is not computed. Also, when raycasting against bounds (AABBs) instead of actual shapes,
50some members are not available either.
51
52Some members like barycentric coordinates are currently only computed for triangle meshes, but next versions
53might provide them in other cases. The client code should check #flags to make sure returned values are
54relevant.
55
56When used as hint flags in raycasting queries, those bits control what the user would like to see computed
57in the NxRaycastHit structure. For example, you might tell the SDK to compute impact normals using the
58NX_RAYCAST_NORMAL hint flag. It's usually faster to let the SDK do it, instead of fetching relevant data
59again in the client app. However all users may not need this information. In this case, just omit this flag
60and corresponding member of ::NxRaycastHit will not be computed internally - saving processing time.
61
62Note that NX_RAYCAST_NORMAL computes a smoothed normal, while NX_RAYCAST_FACE_NORMAL only returns the usual
63normal of a triangle (i.e. the normalized cross product of two edges).
64
65See #NxScene and #NxShape for raycasting methods.
66
67 <b>Threading:</b> It is not necessary to make this class thread safe as it will only be called in the context of the
68 user thread.
69
70
71@see NxScene.raycastAllBounds
72@see NxScene.raycastAllShapes
73@see NxScene.raycastClosestBounds
74@see NxScene.raycastClosestShape
75*/
76struct NxRaycastHit
77        {
78        /**
79        Touched shape (associated flags: NX_RAYCAST_SHAPE)
80
81        @see flags
82        */
83        NxShape*                shape;
84
85        /**
86        Impact point in world space (associated flags: NX_RAYCAST_IMPACT)
87
88        @see flags
89        */
90        NxVec3                  worldImpact;
91                                       
92        /**
93        Impact normal in world space (associated flags: NX_RAYCAST_NORMAL / NX_RAYCAST_FACE_NORMAL)
94
95        For #NxConvexShape and #NxTriangleMeshShape NX_RAYCAST_NORMAL generates a smooth normal. If a true
96        face normal is required use NX_RAYCAST_FACE_NORMAL instead when specifying hint flags to a raycast method.
97
98        @see flags
99        */
100        NxVec3                  worldNormal;
101
102        /**
103        Index of touched face (associated flags: NX_RAYCAST_FACE_INDEX)
104
105        The face index is for the mesh <b>before</b> cooking. During the cooking process faces are moved
106        around which changes there index. However the SDK stores a table which is used to map the index to the original
107        mesh before it is returned for a raycast hit.
108
109        @see flags internalFaceID
110        */
111        NxU32                   faceID;
112
113        /**
114        Index of touched face (associated flags: NX_RAYCAST_FACE_INDEX)
115
116        The face index is for the mesh after cooking. This corresponds to the face returned by saveToDesc() or otherwise
117        retrieved from the triangle mesh(which may differ from the face index before cooking as cooking can re-arrange face
118        indices).
119
120        @see flags faceID
121        */
122        NxU32                   internalFaceID;
123
124        /**
125        Distance from ray start to impact point (associated flags: NX_RAYCAST_DISTANCE)
126
127        @see flags
128        */
129        NxReal                  distance;
130       
131        /**
132        Impact barycentric coordinates (associated flags: NX_RAYCAST_UV)
133
134        @see flags
135        */
136        NxReal                  u,v;
137
138        /**
139        Index of touched material (associated flags: NX_RAYCAST_MATERIAL)
140
141        @see flags
142        */
143        NxMaterialIndex materialIndex;
144
145        /**
146        Combination of ::NxRaycastBit, when a corresponding flag is set, then the member is valid.
147
148        ::NxRaycastBit flags can be passed to raycasting functions, as an optimization, to cause Novodex to
149        only generate specific members of this structure.
150        */
151        NxU32                   flags;                                                                                 
152        };
153
154/**
155\brief The user needs to pass an instance of this class to several of the ray casting routines in
156NxScene.
157
158Its onHit method will be called for each shape that the ray intersects.
159
160Example:
161
162\include NxUserRaycastReport_Usage.cpp
163
164@see NxScene.raycastAllBounds
165@see NxScene.raycastAllShapes
166*/
167class NxUserRaycastReport
168        {
169        public:
170
171        /**
172        \brief This method is called for each shape hit by the raycast.
173       
174        If onHit returns true, it may be called again with the next shape that was stabbed.
175        If it returns false, no further shapes are returned, and the raycast is concluded.
176
177        \param[in] hits The data corresponding to the ray intersection. See #NxRaycastHit.
178        \return True to continue the raycast. False to abort.
179
180        <b>Platform:</b>
181        \li PC SW: Yes
182        \li PPU  : No
183        \li PS3  : Yes
184        \li XB360: Yes
185
186        @see NxScene.raycastAllBounds
187    @see NxScene.raycastAllShapes
188        */
189        virtual bool onHit(const NxRaycastHit& hits) = 0;
190        };
191
192/** @} */
193#endif
194
195
196//AGCOPYRIGHTBEGIN
197///////////////////////////////////////////////////////////////////////////
198// Copyright © 2005 AGEIA Technologies.
199// All rights reserved. www.ageia.com
200///////////////////////////////////////////////////////////////////////////
201//AGCOPYRIGHTEND
202
Note: See TracBrowser for help on using the repository browser.