Revision: 16275
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16275
Author:   ben2610
Date:     2008-08-27 21:34:19 +0200 (Wed, 27 Aug 2008)

Log Message:
-----------
BGE patch: KX_GameObject::rayCast() improvements to have X-Ray option, return 
true face normal and hit polygon information.

rayCast(to,from,dist,prop,face,xray,poly):

The face paremeter determines the orientation of the normal: 
  0 or omitted => hit normal is always oriented towards the ray origin (as if 
you casted the ray from outside)
  1 => hit normal is the real face normal (only for mesh object, otherwise face 
has no effect)
The ray has X-Ray capability if xray parameter is 1, otherwise the first object 
hit (other than self object) stops the ray.
The prop and xray parameters interact as follow:
    prop off, xray off: return closest hit or no hit if there is no object on 
the full extend of the ray.
    prop off, xray on : idem.
    prop on,  xray off: return closest hit if it matches prop, no hit otherwise.
    prop on,  xray on : return closest hit matching prop or no hit if there is 
no object matching prop on the full extend of the ray.
if poly is 0 or omitted, returns a 3-tuple with object reference, hit point and 
hit normal or (None,None,None) if no hit.
if poly is 1, returns a 4-tuple with in addition a KX_PolyProxy as 4th element.

The KX_PolyProxy object holds information on the polygon hit by the ray: the 
index of the vertex forming the poylgon, material, etc.

Attributes (read-only):
 matname: The name of polygon material, empty if no material.
 material: The material of the polygon
 texture: The texture name of the polygon.
 matid: The material index of the polygon, use this to retrieve vertex proxy 
from mesh proxy
 v1: vertex index of the first vertex of the polygon, use this to retrieve 
vertex proxy from mesh proxy
 v2: vertex index of the second vertex of the polygon, use this to retrieve 
vertex proxy from mesh proxy
 v3: vertex index of the third vertex of the polygon, use this to retrieve 
vertex proxy from mesh proxy
 v4: vertex index of the fourth vertex of the polygon, 0 if polygon has only 3 
vertex
     use this to retrieve vertex proxy from mesh proxy
 visible: visible state of the polygon: 1=visible, 0=invisible
 collide: collide state of the polygon: 1=receives collision, 0=collision free.
Methods:
 getMaterialName(): Returns the polygon material name with MA prefix
 getMaterial(): Returns the polygon material
 getTextureName(): Returns the polygon texture name
 getMaterialIndex(): Returns the material bucket index of the polygon. 
 getNumVertex(): Returns the number of vertex of the polygon.
 isVisible(): Returns whether the polygon is visible or not
 isCollider(): Returns whether the polygon is receives collision or not
 getVertexIndex(vertex): Returns the mesh vertex index of a polygon vertex
 getMesh(): Returns a mesh proxy

New methods of KX_MeshProxy have been implemented to retrieve KX_PolyProxy 
objects:
 getNumPolygons(): Returns the number of polygon in the mesh.
 getPolygon(index): Gets the specified polygon from the mesh.

More details in PyDoc.

Modified Paths:
--------------
    trunk/blender/projectfiles_vc7/gameengine/ketsji/KX_ketsji.vcproj
    trunk/blender/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp
    trunk/blender/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h
    trunk/blender/source/gameengine/Expressions/PyObjectPlus.h
    trunk/blender/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp
    trunk/blender/source/gameengine/GamePlayer/common/GPC_RenderTools.h
    trunk/blender/source/gameengine/Ketsji/KX_ConstraintActuator.cpp
    trunk/blender/source/gameengine/Ketsji/KX_ConstraintActuator.h
    trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
    trunk/blender/source/gameengine/Ketsji/KX_GameObject.h
    trunk/blender/source/gameengine/Ketsji/KX_MeshProxy.cpp
    trunk/blender/source/gameengine/Ketsji/KX_MeshProxy.h
    trunk/blender/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp
    trunk/blender/source/gameengine/Ketsji/KX_MouseFocusSensor.h
    trunk/blender/source/gameengine/Ketsji/KX_RayCast.cpp
    trunk/blender/source/gameengine/Ketsji/KX_RayCast.h
    trunk/blender/source/gameengine/Ketsji/KX_RaySensor.cpp
    trunk/blender/source/gameengine/Ketsji/KX_RaySensor.h
    trunk/blender/source/gameengine/Physics/BlOde/OdePhysicsEnvironment.cpp
    trunk/blender/source/gameengine/Physics/BlOde/OdePhysicsEnvironment.h
    trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
    trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.h
    trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
    trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h
    trunk/blender/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.cpp
    trunk/blender/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h
    trunk/blender/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.cpp
    trunk/blender/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.h
    trunk/blender/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h
    trunk/blender/source/gameengine/PyDoc/KX_GameObject.py
    trunk/blender/source/gameengine/PyDoc/KX_MeshProxy.py
    trunk/blender/source/gameengine/Rasterizer/RAS_MeshObject.cpp
    trunk/blender/source/gameengine/Rasterizer/RAS_MeshObject.h

Added Paths:
-----------
    trunk/blender/source/gameengine/Ketsji/KX_PolyProxy.cpp
    trunk/blender/source/gameengine/Ketsji/KX_PolyProxy.h
    trunk/blender/source/gameengine/PyDoc/KX_PolyProxy.py

Modified: trunk/blender/projectfiles_vc7/gameengine/ketsji/KX_ketsji.vcproj
===================================================================
--- trunk/blender/projectfiles_vc7/gameengine/ketsji/KX_ketsji.vcproj   
2008-08-27 19:16:21 UTC (rev 16274)
+++ trunk/blender/projectfiles_vc7/gameengine/ketsji/KX_ketsji.vcproj   
2008-08-27 19:34:19 UTC (rev 16275)
@@ -395,6 +395,9 @@
                                
RelativePath="..\..\..\source\gameengine\Ketsji\KX_PolygonMaterial.cpp">
                        </File>
                        <File
+                               
RelativePath="..\..\..\source\gameengine\Ketsji\KX_PolyProxy.cpp">
+                       </File>
+                       <File
                                
RelativePath="..\..\..\source\gameengine\Ketsji\KX_PyConstraintBinding.cpp">
                        </File>
                        <File
@@ -622,6 +625,9 @@
                                
RelativePath="..\..\..\source\gameengine\Ketsji\KX_PolygonMaterial.h">
                        </File>
                        <File
+                               
RelativePath="..\..\..\source\gameengine\Ketsji\KX_PolyProxy.h">
+                       </File>
+                       <File
                                
RelativePath="..\..\..\source\gameengine\Ketsji\KX_PyConstraintBinding.h">
                        </File>
                        <File

Modified: 
trunk/blender/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp
===================================================================
--- trunk/blender/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp   
2008-08-27 19:16:21 UTC (rev 16274)
+++ trunk/blender/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp   
2008-08-27 19:34:19 UTC (rev 16275)
@@ -131,11 +131,11 @@
        }
 }
 
-bool KX_BlenderRenderTools::RayHit(KX_ClientObjectInfo* client, MT_Point3& 
hit_point, MT_Vector3& hit_normal, void * const data)
+bool KX_BlenderRenderTools::RayHit(KX_ClientObjectInfo* client, KX_RayCast* 
result, void * const data)
 {
        double* const oglmatrix = (double* const) data;
-       MT_Point3 resultpoint(hit_point);
-       MT_Vector3 resultnormal(hit_normal);
+       MT_Point3 resultpoint(result->m_hitPoint);
+       MT_Vector3 resultnormal(result->m_hitNormal);
        MT_Vector3 left(oglmatrix[0],oglmatrix[1],oglmatrix[2]);
        MT_Vector3 dir = -(left.cross(resultnormal)).safe_normalized();
        left = (dir.cross(resultnormal)).safe_normalized();
@@ -236,9 +236,7 @@
                        if (parent)
                                parent->Release();
                                
-                       MT_Point3 resultpoint;
-                       MT_Vector3 resultnormal;
-                       if (!KX_RayCast::RayTest(physics_controller, 
physics_environment, frompoint, topoint, resultpoint, resultnormal, 
KX_RayCast::Callback<KX_BlenderRenderTools>(this, oglmatrix)))
+                       if (!KX_RayCast::RayTest(physics_environment, 
frompoint, topoint, KX_RayCast::Callback<KX_BlenderRenderTools>(this, 
physics_controller, oglmatrix)))
                        {
                                // couldn't find something to cast the shadow 
on...
                                glMultMatrixd(oglmatrix);

Modified: 
trunk/blender/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h
===================================================================
--- trunk/blender/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h     
2008-08-27 19:16:21 UTC (rev 16274)
+++ trunk/blender/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h     
2008-08-27 19:34:19 UTC (rev 16275)
@@ -37,6 +37,7 @@
 #include "RAS_IRenderTools.h"
 
 struct KX_ClientObjectInfo;
+class KX_RayCast;
 
 /**
 BlenderRenderTools are a set of tools to apply 2D/3D graphics effects, which 
are not
@@ -97,7 +98,8 @@
                                                                        void* 
clientobject,
                                                                        void* 
tface);
        
-       bool RayHit(KX_ClientObjectInfo* client, MT_Point3& hit_point, 
MT_Vector3& hit_normal, void * const data);
+       bool RayHit(KX_ClientObjectInfo* client, class KX_RayCast* result, void 
* const data);
+       bool NeedRayCast(KX_ClientObjectInfo*) { return true; }
 
        virtual void MotionBlur(RAS_IRasterizer* rasterizer);
 

Modified: trunk/blender/source/gameengine/Expressions/PyObjectPlus.h
===================================================================
--- trunk/blender/source/gameengine/Expressions/PyObjectPlus.h  2008-08-27 
19:16:21 UTC (rev 16274)
+++ trunk/blender/source/gameengine/Expressions/PyObjectPlus.h  2008-08-27 
19:34:19 UTC (rev 16275)
@@ -156,6 +156,9 @@
 #define KX_PYMETHODTABLE(class_name, method_name) \
        {#method_name , (PyCFunction) class_name::sPy##method_name, 
METH_VARARGS, class_name::method_name##_doc}
 
+#define KX_PYMETHODTABLE_NOARG(class_name, method_name) \
+       {#method_name , (PyCFunction) class_name::sPy##method_name, 
METH_NOARGS, class_name::method_name##_doc}
+
 /**
  * Function implementation macro
  */
@@ -163,6 +166,9 @@
 char class_name::method_name##_doc[] = doc_string; \
 PyObject* class_name::Py##method_name(PyObject*, PyObject* args, PyObject*)
 
+#define KX_PYMETHODDEF_DOC_NOARG(class_name, method_name, doc_string) \
+char class_name::method_name##_doc[] = doc_string; \
+PyObject* class_name::Py##method_name(PyObject*)
 
 /*------------------------------
  * PyObjectPlus

Modified: trunk/blender/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp
===================================================================
--- trunk/blender/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp       
2008-08-27 19:16:21 UTC (rev 16274)
+++ trunk/blender/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp       
2008-08-27 19:34:19 UTC (rev 16275)
@@ -470,11 +470,11 @@
        }
 }
 
-bool GPC_RenderTools::RayHit(KX_ClientObjectInfo* client, MT_Point3& 
hit_point, MT_Vector3& hit_normal, void * const data)
+bool GPC_RenderTools::RayHit(KX_ClientObjectInfo* client, KX_RayCast* result, 
void * const data)
 {
        double* const oglmatrix = (double* const) data;
-       MT_Point3 resultpoint(hit_point);
-       MT_Vector3 resultnormal(hit_normal);
+       MT_Point3 resultpoint(result->m_hitPoint);
+       MT_Vector3 resultnormal(result->m_hitNormal);
        MT_Vector3 left(oglmatrix[0],oglmatrix[1],oglmatrix[2]);
        MT_Vector3 dir = -(left.cross(resultnormal)).safe_normalized();
        left = (dir.cross(resultnormal)).safe_normalized();
@@ -563,9 +563,7 @@
                        if (parent)
                                parent->Release();
                                
-                       MT_Point3 resultpoint;
-                       MT_Vector3 resultnormal;
-                       if (!KX_RayCast::RayTest(physics_controller, 
physics_environment, frompoint, topoint, resultpoint, resultnormal, 
KX_RayCast::Callback<GPC_RenderTools>(this, oglmatrix)))
+                       if (!KX_RayCast::RayTest(physics_environment, 
frompoint, topoint, KX_RayCast::Callback<GPC_RenderTools>(this, 
physics_controller, oglmatrix)))
                        {
                                // couldn't find something to cast the shadow 
on...
                                glMultMatrixd(oglmatrix);

Modified: trunk/blender/source/gameengine/GamePlayer/common/GPC_RenderTools.h
===================================================================
--- trunk/blender/source/gameengine/GamePlayer/common/GPC_RenderTools.h 
2008-08-27 19:16:21 UTC (rev 16274)
+++ trunk/blender/source/gameengine/GamePlayer/common/GPC_RenderTools.h 
2008-08-27 19:34:19 UTC (rev 16275)
@@ -41,8 +41,8 @@
 #include "BMF_Api.h"
 
 struct KX_ClientObjectInfo;
+class KX_RayCast;
 
-
 class GPC_RenderTools : public RAS_IRenderTools
 {
 public:
@@ -138,7 +138,8 @@
 
        int applyLights(int objectlayer);
 
-       bool RayHit(KX_ClientObjectInfo* client, MT_Point3& hit_point, 
MT_Vector3& hit_normal, void * const data);
+       bool RayHit(KX_ClientObjectInfo* client, KX_RayCast* result, void * 
const data);
+       bool NeedRayCast(KX_ClientObjectInfo* client) { return true; }
 
        virtual void MotionBlur(RAS_IRasterizer* rasterizer);
 

Modified: trunk/blender/source/gameengine/Ketsji/KX_ConstraintActuator.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_ConstraintActuator.cpp    
2008-08-27 19:16:21 UTC (rev 16274)
+++ trunk/blender/source/gameengine/Ketsji/KX_ConstraintActuator.cpp    
2008-08-27 19:34:19 UTC (rev 16275)
@@ -109,16 +109,11 @@
        // there's nothing to be done here, really....
 } /* end of destructor */
 
-bool KX_ConstraintActuator::RayHit(KX_ClientObjectInfo* client, MT_Point3& 
hit_point, MT_Vector3& hit_normal, void * const data)
+bool KX_ConstraintActuator::RayHit(KX_ClientObjectInfo* client, KX_RayCast* 
result, void * const data)
 {
 
        KX_GameObject* hitKXObj = client->m_gameobject;
        
-       if (client->m_type > KX_ClientObjectInfo::ACTOR)
-       {
-               // false hit
-               return false;
-       }
        bool bFound = false;
 
        if (m_property[0] == 0)
@@ -139,8 +134,26 @@
                        bFound = hitKXObj->GetProperty(m_property) != NULL;
                }
        }
+       // update the hit status
+       result->m_hitFound = bFound;
+       // stop looking
+       return true;
+}
 
-       return bFound;
+/* this function is used to pre-filter the object before casting the ray on 
them.
+   This is useful for "X-Ray" option when we want to see "through" unwanted 
object.
+ */
+bool KX_ConstraintActuator::NeedRayCast(KX_ClientObjectInfo* client)
+{
+       if (client->m_type > KX_ClientObjectInfo::ACTOR)
+       {
+               // Unknown type of object, skip it.
+               // Should not occur as the sensor objects are filtered in 
RayTest()
+               printf("Invalid client type %d found in ray casting\n", 
client->m_type);
+               return false;
+       }
+       // no X-Ray function yet
+       return true;
 }
 
 bool KX_ConstraintActuator::Update(double curtime, bool frame)
@@ -287,8 +300,6 @@
                        direction.normalize();
                        {
                                MT_Point3 topoint = position + (m_maximumBound) 
* direction;
-                               MT_Point3 resultpoint;
-                               MT_Vector3 resultnormal;
                                PHY_IPhysicsEnvironment* pe = 
obj->GetPhysicsEnvironment();
                                KX_IPhysicsController *spc = 
obj->GetPhysicsController();
 
@@ -304,9 +315,10 @@
                                                parent->Release();
                                        }
                                }
-                               result = KX_RayCast::RayTest(spc, pe, position, 
topoint, resultpoint, resultnormal, 
KX_RayCast::Callback<KX_ConstraintActuator>(this));
-
+                               KX_RayCast::Callback<KX_ConstraintActuator> 
callback(this,spc);
+                               result = KX_RayCast::RayTest(pe, position, 
topoint, callback);
                                if (result)     {
+                                       MT_Vector3 newnormal = 
callback.m_hitNormal;
                                        // compute new position & orientation
                                        if ((m_option & 
(KX_ACT_CONSTRAINT_NORMAL|KX_ACT_CONSTRAINT_DISTANCE)) == 0) {
                                                // if none option is set, the 
actuator does nothing but detect ray 
@@ -316,27 +328,27 @@
                                        if (m_option & 
KX_ACT_CONSTRAINT_NORMAL) {
                                                // the new orientation must be 
so that the axis is parallel to normal
                                                if (sign)
-                                                       resultnormal = 
-resultnormal;
+                                                       newnormal = -newnormal;
                                                // apply damping on the 
direction
                                                if (m_rotDampTime) {
                                                        MT_Scalar rotFilter = 
1.0/(1.0+m_rotDampTime);
-                                                       resultnormal = 
(-m_rotDampTime*rotFilter)*direction + rotFilter*resultnormal;
+                                                       newnormal = 
(-m_rotDampTime*rotFilter)*direction + rotFilter*newnormal;
                                                } else if (m_posDampTime) {
-                                                       resultnormal = 
-filter*direction + (1.0-filter)*resultnormal;
+                                                       newnormal = 
-filter*direction + (1.0-filter)*newnormal;
                                                }
-                                               
obj->AlignAxisToVect(resultnormal, axis);

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to