Synchronise game engine with Tuhopuu2 tree.
authorKester Maddock <Christopher.Maddock.1@uni.massey.ac.nz>
Sat, 24 Apr 2004 06:40:15 +0000 (06:40 +0000)
committerKester Maddock <Christopher.Maddock.1@uni.massey.ac.nz>
Sat, 24 Apr 2004 06:40:15 +0000 (06:40 +0000)
28 files changed:
source/gameengine/Converter/BL_BlenderDataConversion.cpp
source/gameengine/Converter/BL_SkinMeshObject.cpp
source/gameengine/Converter/BL_SkinMeshObject.h
source/gameengine/Expressions/ListValue.cpp
source/gameengine/Expressions/Operator1Expr.h
source/gameengine/Expressions/Operator2Expr.cpp
source/gameengine/Expressions/Value.cpp
source/gameengine/Expressions/VoidValue.h
source/gameengine/GamePlayer/common/GPC_PolygonMaterial.cpp
source/gameengine/GamePlayer/ghost/GPG_Application.cpp
source/gameengine/Ketsji/KX_Camera.cpp
source/gameengine/Ketsji/KX_GameObject.h
source/gameengine/Ketsji/KX_IPhysicsController.cpp
source/gameengine/Ketsji/KX_KetsjiEngine.h
source/gameengine/Physics/Sumo/Fuzzics/include/SM_Object.h
source/gameengine/Physics/Sumo/Fuzzics/src/SM_Object.cpp
source/gameengine/Physics/Sumo/SumoPhysicsController.cpp
source/gameengine/Physics/Sumo/SumoPhysicsController.h
source/gameengine/Physics/common/PHY_IPhysicsController.h
source/gameengine/Rasterizer/RAS_IRasterizer.h
source/gameengine/Rasterizer/RAS_MeshObject.cpp
source/gameengine/Rasterizer/RAS_MeshObject.h
source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_GLExtensionManager.cpp
source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_GLExtensionManager.h
source/gameengine/Rasterizer/RAS_OpenGLRasterizer/mkglext.py
source/gameengine/SceneGraph/SG_Controller.cpp
source/gameengine/SceneGraph/SG_Controller.h
source/gameengine/SceneGraph/SG_Spatial.cpp

index 6f58198..4206b60 100644 (file)
@@ -181,7 +181,7 @@ static unsigned int KX_Mcol2uint_new(MCol col)
        return temp;
 }
 
-RAS_MeshObject* BL_ConvertMesh(Mesh* mesh,Object* blenderobj,RAS_IRenderTools* rendertools,KX_Scene* scene,KX_BlenderSceneConverter *converter)
+RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools* rendertools, KX_Scene* scene, KX_BlenderSceneConverter *converter)
 {
        RAS_MeshObject *meshobj;
        bool    skinMesh = false;
@@ -674,9 +674,7 @@ void BL_CreatePhysicsObjectNew(KX_GameObject* gameobj,
                                                 KX_BlenderSceneConverter *converter
                                                 )
                                        
-                                       {
-                                       
-                                       
+{
        SYS_SystemHandle syshandle = SYS_GetSystem();
        //int userigidbody = SYS_GetCommandLineInt(syshandle,"norigidbody",0);
        //bool bRigidBody = (userigidbody == 0);
@@ -759,36 +757,27 @@ void BL_CreatePhysicsObjectNew(KX_GameObject* gameobj,
        objprop.m_concave = (blenderobject->boundtype & 4) != 0;
        
        switch (physics_engine)
-               {
-                       case UseSumo:
-                               {
-
+       {
 #ifdef USE_SUMO_SOLID
-                                       KX_ConvertSumoObject(   gameobj,meshobj,kxscene,shapeprops,     smmaterial,     &objprop);
+               case UseSumo:
+                       KX_ConvertSumoObject(gameobj, meshobj, kxscene, shapeprops, smmaterial, &objprop);
+                       break;
 #endif
-                                       break;
-                               }
-                       case UseODE:
-                       {
-
+                       
 #ifdef USE_ODE
-                               KX_ConvertODEEngineObject(gameobj,meshobj,kxscene,shapeprops,   smmaterial,     &objprop);
+               case UseODE:
+                       KX_ConvertODEEngineObject(gameobj, meshobj, kxscene, shapeprops, smmaterial, &objprop);
+                       break;
 #endif //USE_ODE
 
-
-                               break;
-                       }
-                       case UseDynamo:
-                       {
-                               //KX_ConvertDynamoObject(gameobj,meshobj,kxscene,shapeprops,    smmaterial,     &objprop);
-                               break;
-                       }
-                       case UseNone:
-                       default:
-       {
+               case UseDynamo:
+                       //KX_ConvertDynamoObject(gameobj,meshobj,kxscene,shapeprops,    smmaterial,     &objprop);
+                       break;
+                       
+               case UseNone:
+               default:
+                       break;
        }
-       
-}
 
 }
 
index 2994f42..be85300 100644 (file)
@@ -59,14 +59,14 @@ void BL_SkinMeshObject::AddPolygon(RAS_Polygon* poly)
 #ifdef __NLA_OLDDEFORM
 int BL_SkinMeshObject::FindOrAddDeform(int vtxarray, struct MVert *mv, struct MDeformVert *dv, RAS_IPolyMaterial* mat)
 #else
-int BL_SkinMeshObject::FindOrAddDeform(int vtxarray, int mv, struct MDeformVert *dv, RAS_IPolyMaterial* mat)
+int BL_SkinMeshObject::FindOrAddDeform(unsigned int vtxarray, unsigned int mv, struct MDeformVert *dv, RAS_IPolyMaterial* mat)
 #endif
 {
        BL_SkinArrayOptimizer* ao = (BL_SkinArrayOptimizer*)GetArrayOptimizer(mat);//*(m_matVertexArrays[*mat]);
        int numvert = ao->m_MvertArrayCache1[vtxarray]->size();
        
        /* Check to see if this has already been pushed */
-       for (size_t i=0; i<ao->m_MvertArrayCache1[vtxarray]->size(); i++){
+       for (unsigned int i=0; i<ao->m_MvertArrayCache1[vtxarray]->size(); i++){
                if (mv == (*ao->m_MvertArrayCache1[vtxarray])[i])
                        return i;
        }
@@ -147,7 +147,7 @@ void BL_SkinMeshObject::Bucketize(double* oglmatrix,void* clientobj,bool useObje
 
                RAS_MaterialBucket* materialbucket = (*it);
 
-               KX_ArrayOptimizer* oa = GetArrayOptimizer(materialbucket->GetPolyMaterial());
+//             KX_ArrayOptimizer* oa = GetArrayOptimizer(materialbucket->GetPolyMaterial());
                materialbucket->SetMeshSlot(ms);
        }
 
index c81a667..13cd04d 100644 (file)
@@ -136,7 +136,7 @@ public:
        }
        
        void AddPolygon(RAS_Polygon* poly);
-       int FindOrAddDeform(int vtxarray, int mv, struct MDeformVert *dv, RAS_IPolyMaterial* mat);
+       int FindOrAddDeform(unsigned int vtxarray, unsigned int mv, struct MDeformVert *dv, RAS_IPolyMaterial* mat);
        int FindOrAddVertex(int vtxarray,const MT_Point3& xyz,
                const MT_Point2& uv,
                const unsigned int rgbacolor,
index 673dda5..380befa 100644 (file)
@@ -226,7 +226,7 @@ CListValue::~CListValue()
 {
 
        if (m_bReleaseContents) {
-               for (int i=0;i<m_pValueArray.size();i++) {
+               for (unsigned int i=0;i<m_pValueArray.size();i++) {
                        m_pValueArray[i]->Release();
                }
        }
@@ -261,7 +261,7 @@ CValue* CListValue::GetReplica() {
        replica->m_bReleaseContents=true; // for copy, complete array is copied for now...
        // copy all values
        int numelements = m_pValueArray.size();
-       int i=0;
+       unsigned int i=0;
        replica->m_pValueArray.resize(numelements);
        for (i=0;i<m_pValueArray.size();i++)
                replica->m_pValueArray[i] = m_pValueArray[i]->GetReplica();
@@ -297,7 +297,7 @@ void CListValue::Remove(int i)
 
 void CListValue::ReleaseAndRemoveAll()
 {
-       for (int i=0;i<m_pValueArray.size();i++)
+       for (unsigned int i=0;i<m_pValueArray.size();i++)
                m_pValueArray[i]->Release();
        m_pValueArray.clear();//.Clear();
 }
index eeb8e2b..4a1deb0 100644 (file)
@@ -26,7 +26,7 @@ class COperator1Expr : public CExpression
 
 public:
        virtual bool MergeExpression(CExpression* otherexpr);
-       void virtual BroadcastOperators(VALUE_OPERATOR op);
+       virtual void BroadcastOperators(VALUE_OPERATOR op);
 
        virtual unsigned char GetExpressionID() { return COPERATOR1EXPRESSIONID;};
        CExpression* CheckLink(std::vector<CBrokenLinkInfo*>& brokenlinks);
index 2bd3f07..da0a3e9 100644 (file)
 
 COperator2Expr::COperator2Expr(VALUE_OPERATOR op, CExpression *lhs, CExpression *rhs)
 :      
-m_cached_calculate(NULL),
-m_op(op),
+m_rhs(rhs),
 m_lhs(lhs),
-m_rhs(rhs)
+m_cached_calculate(NULL),
+m_op(op)
 /*
 pre:
 effect: constucts a COperator2Expr with op, lhs and rhs in it
@@ -43,9 +43,9 @@ effect: constucts a COperator2Expr with op, lhs and rhs in it
 }
 
 COperator2Expr::COperator2Expr():
-m_cached_calculate(NULL),
+m_rhs(NULL),
 m_lhs(NULL),
-m_rhs(NULL)
+m_cached_calculate(NULL)
 
 /*
 pre:
index ecbd2d9..58f0779 100644 (file)
@@ -179,8 +179,8 @@ CValue::CValue()
 : 
 #endif //NO_EXP_PYTHON_EMBEDDING
        
-m_refcount(1),
-m_pNamedPropertyArray(NULL)
+m_pNamedPropertyArray(NULL),
+m_refcount(1)
 /*
 pre: false
 effect: constucts a CValue
index bec611d..53fbd8b 100644 (file)
@@ -44,8 +44,8 @@ class CVoidValue : public CPropValue
 
 public:
        /// Construction/destruction
-       CVoidValue()                                                                                                                            : m_pAnything(NULL),    m_bDeleteOnDestruct(false) { }
-       CVoidValue(void * voidptr, bool bDeleteOnDestruct, AllocationTYPE alloctype)    : m_pAnything(voidptr), m_bDeleteOnDestruct(bDeleteOnDestruct) { if (alloctype == STACKVALUE) CValue::DisableRefCount(); }
+       CVoidValue()                                                                                                                            : m_bDeleteOnDestruct(false), m_pAnything(NULL)  { }
+       CVoidValue(void * voidptr, bool bDeleteOnDestruct, AllocationTYPE alloctype)    : m_bDeleteOnDestruct(bDeleteOnDestruct), m_pAnything(voidptr)  { if (alloctype == STACKVALUE) CValue::DisableRefCount(); }
        virtual                         ~CVoidValue();                                                                                  // Destruct void value, delete memory if we're owning it
 
        /// Value -> String or number
index 75286c4..76a61da 100644 (file)
@@ -37,6 +37,7 @@
 #include "GPC_PolygonMaterial.h"
 #include "MT_Vector3.h"
 #include "RAS_IRasterizer.h"
+#include "RAS_GLExtensionManager.h"
 
 /* This list includes only data type definitions */
 #include "DNA_object_types.h"
@@ -83,6 +84,7 @@ static int fDoMipMap = 1;
 static int fLinearMipMap=1;
 static int fAlphamode= -1;
 
+using namespace bgl;
        /* (n&(n-1)) zeros the least significant bit of n */
 static int is_pow2(int num) {
        return ((num)&(num-1))==0;
@@ -111,7 +113,7 @@ static void my_make_repbind(Image *ima)
 }
 
 
-int my_set_tpage(TFace *tface)
+static int my_set_tpage(TFace *tface)
 {      
        static TFace *lasttface= 0;
        Image *ima;
@@ -402,7 +404,7 @@ void GPC_PolygonMaterial::Activate(RAS_IRasterizer* rasty, TCachingInfo& caching
                        
                else
                {
-                       rasty->SetCullFace(true);;//glEnable(GL_CULL_FACE);
+                       rasty->SetCullFace(true);//glEnable(GL_CULL_FACE);
                        //else glDisable(GL_CULL_FACE);
                }
        }
index 68ff43f..c33114c 100644 (file)
@@ -69,6 +69,8 @@ extern "C"
 #include "SCA_IActuator.h"
 #include "RAS_MeshObject.h"
 #include "RAS_OpenGLRasterizer.h"
+#include "RAS_VAOpenGLRasterizer.h"
+#include "RAS_GLExtensionManager.h"
 #include "KX_PythonInit.h"
 #include "KX_PyConstraintBinding.h"
 
@@ -313,78 +315,102 @@ bool GPG_Application::initEngine(GHOST_IWindow* window, const int stereoMode)
 {
        if (!m_engineInitialized)
        {
+               bgl::InitExtensions(1);
+
                // get and set the preferences
                SYS_SystemHandle syshandle = SYS_GetSystem();
-               if (syshandle)
-               {
-                       // SYS_WriteCommandLineInt(syshandle, "fixedtime", 0);
-                       SYS_WriteCommandLineInt(syshandle, "vertexarrays",1);           
-                       //bool properties       = (SYS_GetCommandLineInt(syshandle, "show_properties", 0) != 0);
-                       //bool profile = (SYS_GetCommandLineInt(syshandle, "show_profile", 0) != 0);
-                       //bool frameRate = (SYS_GetCommandLineInt(syshandle, "show_framerate", 0) != 0);
+               if (!syshandle)
+                       return false;
+               
+               // SYS_WriteCommandLineInt(syshandle, "fixedtime", 0);
+               SYS_WriteCommandLineInt(syshandle, "vertexarrays",1);           
+               //bool properties       = (SYS_GetCommandLineInt(syshandle, "show_properties", 0) != 0);
+               //bool profile = (SYS_GetCommandLineInt(syshandle, "show_profile", 0) != 0);
+               bool frameRate = (SYS_GetCommandLineInt(syshandle, "show_framerate", 0) != 0);
+               bool useVertexArrays = SYS_GetCommandLineInt(syshandle,"vertexarrays",1) != 0;
+               // create the canvas, rasterizer and rendertools
+               m_canvas = new GPG_Canvas(window);
+               if (!m_canvas)
+                       return false;
+                               
+               m_canvas->Init();                               
+               m_rendertools = new GPC_RenderTools();
+               if (!m_rendertools)
+                       goto initFailed;
+                                       
+               if (useVertexArrays && bgl::QueryVersion(1, 1))
+                       m_rasterizer = new RAS_VAOpenGLRasterizer(m_canvas);
+               else
+                       m_rasterizer = new RAS_OpenGLRasterizer(m_canvas);
+               m_rasterizer->SetStereoMode(stereoMode);
+               if (!m_rasterizer)
+                       goto initFailed;
+                                               
+               // create the inputdevices
+               m_keyboard = new GPG_KeyboardDevice();
+               if (!m_keyboard)
+                       goto initFailed;
                        
-                       // create the canvas, rasterizer and rendertools
-                       m_canvas = new GPG_Canvas(window);
-                       if (m_canvas)
-                       {
-                               m_canvas->Init();                               
-                               m_rendertools = new GPC_RenderTools();
-                               if (m_rendertools)
-                               {
-                                       m_rasterizer = new RAS_OpenGLRasterizer(m_canvas);
-                                       m_rasterizer->SetStereoMode(stereoMode);
-                                       if (m_rasterizer)
-                                       {
-                                               // create the inputdevices
-                                               m_keyboard = new GPG_KeyboardDevice();
-                                               if (m_keyboard)
-                                               {
-                                                       m_mouse = new GPC_MouseDevice();
-                                                       if (m_mouse)
-                                                       {
-                                                               // create a networkdevice
-                                                               m_networkdevice = new NG_LoopBackNetworkDeviceInterface();
-                                                               if (m_networkdevice)
-                                                               {
-                                                                       // get an audiodevice
-                                                                       SND_DeviceManager::Subscribe();
-                                                                       m_audiodevice = SND_DeviceManager::Instance();
-                                                                       if (m_audiodevice)
-                                                                       {
-                                                                               m_audiodevice->UseCD();
-                                                                               // create a ketsjisystem (only needed for timing and stuff)
-                                                                               m_kxsystem = new GPG_System (m_system);
-                                                                               if (m_kxsystem)
-                                                                               {
-                                                                                       // create the ketsjiengine
-                                                                                       m_ketsjiengine = new KX_KetsjiEngine(m_kxsystem);
-                                                                                       
-                                                                                       // set the devices
-                                                                                       m_ketsjiengine->SetKeyboardDevice(m_keyboard);
-                                                                                       m_ketsjiengine->SetMouseDevice(m_mouse);
-                                                                                       m_ketsjiengine->SetNetworkDevice(m_networkdevice);
-                                                                                       m_ketsjiengine->SetCanvas(m_canvas);
-                                                                                       m_ketsjiengine->SetRenderTools(m_rendertools);
-                                                                                       m_ketsjiengine->SetRasterizer(m_rasterizer);
-                                                                                       m_ketsjiengine->SetNetworkDevice(m_networkdevice);
-                                                                                       m_ketsjiengine->SetAudioDevice(m_audiodevice);
-
-                                                                                       m_ketsjiengine->SetUseFixedTime(false);
-                                                                                       //m_ketsjiengine->SetTimingDisplay(frameRate, profile, properties);
-
-                                                                                       m_engineInitialized = true;
-                                                                               }
-                                                                       }
-                                                               }
-                                                       }
-                                               } 
-                                       }
-                               }
-                       }
-               }
+               m_mouse = new GPC_MouseDevice();
+               if (!m_mouse)
+                       goto initFailed;
+                       
+               // create a networkdevice
+               m_networkdevice = new NG_LoopBackNetworkDeviceInterface();
+               if (!m_networkdevice)
+                       goto initFailed;
+                       
+               // get an audiodevice
+               SND_DeviceManager::Subscribe();
+               m_audiodevice = SND_DeviceManager::Instance();
+               if (!m_audiodevice)
+                       goto initFailed;
+               m_audiodevice->UseCD();
+               
+               // create a ketsjisystem (only needed for timing and stuff)
+               m_kxsystem = new GPG_System (m_system);
+               if (!m_kxsystem)
+                       goto initFailed;
+               
+               // create the ketsjiengine
+               m_ketsjiengine = new KX_KetsjiEngine(m_kxsystem);
+               
+               // set the devices
+               m_ketsjiengine->SetKeyboardDevice(m_keyboard);
+               m_ketsjiengine->SetMouseDevice(m_mouse);
+               m_ketsjiengine->SetNetworkDevice(m_networkdevice);
+               m_ketsjiengine->SetCanvas(m_canvas);
+               m_ketsjiengine->SetRenderTools(m_rendertools);
+               m_ketsjiengine->SetRasterizer(m_rasterizer);
+               m_ketsjiengine->SetNetworkDevice(m_networkdevice);
+               m_ketsjiengine->SetAudioDevice(m_audiodevice);
+               m_ketsjiengine->SetTimingDisplay(frameRate, false, false);
+
+               m_ketsjiengine->SetUseFixedTime(false);
+               //m_ketsjiengine->SetTimingDisplay(frameRate, profile, properties);
+
+               m_engineInitialized = true;
        }
 
        return m_engineInitialized;
+initFailed:
+       delete m_kxsystem;
+       delete m_audiodevice;
+       delete m_networkdevice;
+       delete m_mouse;
+       delete m_keyboard;
+       delete m_rasterizer;
+       delete m_rendertools;
+       delete m_canvas;
+       m_canvas = NULL;
+       m_rendertools = NULL;
+       m_rasterizer = NULL;
+       m_keyboard = NULL;
+       m_mouse = NULL;
+       m_networkdevice = NULL;
+       m_audiodevice = NULL;
+       m_kxsystem = NULL;
+       return false;
 }
 
 
@@ -396,14 +422,14 @@ bool GPG_Application::startEngine(void)
        }
        
        // Temporary hack to disable banner display for NaN approved content.
-       
+       /*
        m_canvas->SetBannerDisplayEnabled(true);        
-/*     Camera* cam;
+       Camera* cam;
        cam = (Camera*)G.scene->camera->data;
        if (cam) {
-               if (((cam->flag) & 48)==48) {
-                       m_canvas->SetBannerDisplayEnabled(false);
-               }
+       if (((cam->flag) & 48)==48) {
+       m_canvas->SetBannerDisplayEnabled(false);
+       }
        }
        else {
        showError(CString("Camera data invalid."));
index 69bf4dd..c99e482 100644 (file)
@@ -41,11 +41,11 @@ KX_Camera::KX_Camera(void* sgReplicationInfo,
                                         SG_Callbacks callbacks,
                                         const RAS_CameraData& camdata)
                                        :
-                                       KX_GameObject(sgReplicationInfo,callbacks)
+                                       KX_GameObject(sgReplicationInfo,callbacks),
+                                       m_camdata(camdata)
 {
        // setting a name would be nice...
        m_name = "cam";
-       m_camdata = camdata;
        SetProperty("camera",new CIntValue(1));
 }
 
index 84ce077..e503f57 100644 (file)
@@ -59,29 +59,32 @@ class RAS_MeshObject;
 class KX_IPhysicsController;
 class SM_Object;
 
+/**
+ * KX_GameObject is the main class for dynamic objects.
+ */
 class KX_GameObject : public SCA_IObject
 {
        Py_Header;
 
-       bool                                    m_bDyna;
-       KX_ClientObjectInfo*                    m_pClient_info;
-       STR_String                              m_name;
-       STR_String                              m_text;
+       bool                                                            m_bDyna;
+       KX_ClientObjectInfo*                            m_pClient_info;
+       STR_String                                                      m_name;
+       STR_String                                                      m_text;
        std::vector<RAS_MeshObject*>            m_meshes;
        
-       bool                                    m_bSuspendDynamics;
-       bool                                    m_bUseObjectColor;
-       MT_Vector4                              m_objectColor;
+       bool                                                            m_bSuspendDynamics;
+       bool                                                            m_bUseObjectColor;
+       MT_Vector4                                                      m_objectColor;
 
        // Is this object set to be visible? Only useful for the
        // visibility subsystem right now.
-       bool                                    m_bVisible; 
+       bool       m_bVisible; 
 
-       KX_IPhysicsController*                  m_pPhysicsController1;
-       SG_Node*                                m_pSGNode;
+       KX_IPhysicsController*                          m_pPhysicsController1;
+       SG_Node*                                                        m_pSGNode;
 
 protected:
-       MT_CmMatrix4x4                          m_OpenGL_4x4Matrix;
+       MT_CmMatrix4x4                                          m_OpenGL_4x4Matrix;
        
 public:
        virtual void    /* This function should be virtual - derived classed override it */
index 475ae0d..9cc7764 100644 (file)
@@ -1,4 +1,5 @@
 /**
+ * @file KX_IPhysicsController.cpp
  * $Id$
  *
  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
index 4246bc2..83e0fe2 100644 (file)
@@ -60,6 +60,9 @@ enum KX_ExitRequestMode
        KX_EXIT_REQUEST_MAX
 };
 
+/**
+ * KX_KetsjiEngine is the core game engine class.
+ */
 class KX_KetsjiEngine
 {
 
index c90dfb7..a0475c3 100644 (file)
 
 class SM_FhObject;
 
-
-// Properties of dynamic objects
+/** Properties of dynamic objects */
 struct SM_ShapeProps {
-       MT_Scalar  m_mass;                  // Total mass
-       MT_Scalar  m_radius;                // Bound sphere size
-       MT_Vector3 m_inertia;               // Inertia, should be a tensor some time 
-       MT_Scalar  m_lin_drag;              // Linear drag (air, water) 0 = concrete, 1 = vacuum 
-       MT_Scalar  m_ang_drag;              // Angular drag
-       MT_Scalar  m_friction_scaling[3];   // Scaling for anisotropic friction. Component in range [0, 1]   
-       bool       m_do_anisotropic;        // Should I do anisotropic friction? 
-       bool       m_do_fh;                 // Should the object have a linear Fh spring?
-       bool       m_do_rot_fh;             // Should the object have an angular Fh spring?
+       MT_Scalar  m_mass;                  ///< Total mass
+       MT_Scalar  m_radius;                ///< Bound sphere size
+       MT_Vector3 m_inertia;               ///< Inertia, should be a tensor some time 
+       MT_Scalar  m_lin_drag;              ///< Linear drag (air, water) 0 = concrete, 1 = vacuum 
+       MT_Scalar  m_ang_drag;              ///< Angular drag
+       MT_Scalar  m_friction_scaling[3];   ///< Scaling for anisotropic friction. Component in range [0, 1]   
+       bool       m_do_anisotropic;        ///< Should I do anisotropic friction? 
+       bool       m_do_fh;                 ///< Should the object have a linear Fh spring?
+       bool       m_do_rot_fh;             ///< Should the object have an angular Fh spring?
 };
 
 
-// Properties of collidable objects (non-ghost objects)
+/** Properties of collidable objects (non-ghost objects) */
 struct SM_MaterialProps {
-       MT_Scalar m_restitution;           // restitution of energie after a collision 0 = inelastic, 1 = elastic
-       MT_Scalar m_friction;              // Coulomb friction (= ratio between the normal en maximum friction force)
-       MT_Scalar m_fh_spring;             // Spring constant (both linear and angular)
-       MT_Scalar m_fh_damping;            // Damping factor (linear and angular) in range [0, 1]
-       MT_Scalar m_fh_distance;           // The range above the surface where Fh is active.    
-       bool      m_fh_normal;             // Should the object slide off slopes?
+       MT_Scalar m_restitution;           ///< restitution of energy after a collision 0 = inelastic, 1 = elastic
+       MT_Scalar m_friction;              ///< Coulomb friction (= ratio between the normal en maximum friction force)
+       MT_Scalar m_fh_spring;             ///< Spring constant (both linear and angular)
+       MT_Scalar m_fh_damping;            ///< Damping factor (linear and angular) in range [0, 1]
+       MT_Scalar m_fh_distance;           ///< The range above the surface where Fh is active.    
+       bool      m_fh_normal;             ///< Should the object slide off slopes?
 };
 
 
-
+/**
+ * SM_Object is an internal part of the Sumo physics engine.
+ *
+ * It encapsulates an object in the physics scene, and is responsible
+ * for calculating the collision response of objects.
+ */
 class SM_Object : public SM_MotionState {
 public:
        SM_Object() ;
@@ -140,13 +144,10 @@ public:
         * this external velocity. This velocity is not subject to 
         * friction or damping.
         */
-
-
        void setExternalLinearVelocity(const MT_Vector3& lin_vel) ;
        void addExternalLinearVelocity(const MT_Vector3& lin_vel) ;
 
        /** Override the physics velocity */
-
        void addLinearVelocity(const MT_Vector3& lin_vel);
        void setLinearVelocity(const MT_Vector3& lin_vel);
 
@@ -156,24 +157,20 @@ public:
         * your responsibility to clear this velocity. This velocity
         * is not subject to friction or damping.
         */
-
        void setExternalAngularVelocity(const MT_Vector3& ang_vel) ;
        void addExternalAngularVelocity(const MT_Vector3& ang_vel);
 
        /** Override the physics angular velocity */
-
        void addAngularVelocity(const MT_Vector3& ang_vel);
        void setAngularVelocity(const MT_Vector3& ang_vel);
 
        /** Clear the external velocities */
-
        void clearCombinedVelocities();
 
        /** 
         * Tell the physics system to combine the external velocity
         * with the physics velocity. 
         */
-
        void resolveCombinedVelocities(
                const MT_Vector3 & lin_vel,
                const MT_Vector3 & ang_vel
@@ -193,10 +190,21 @@ public:
        
        void applyTorque(const MT_Vector3& torque) ;
        
+       /**
+        * Apply an impulse to the object.  The impulse will be split into
+        * angular and linear components.
+        * @param attach point to apply the impulse to (in world coordinates)
+        */
        void applyImpulse(const MT_Point3& attach, const MT_Vector3& impulse) ;
        
+       /**
+        * Applies an impulse through the centre of this object. (ie the angular
+        * velocity will not change.
+        */
        void applyCenterImpulse(const MT_Vector3& impulse);
-       
+       /**
+        * Applies an angular impulse.
+        */
        void applyAngularImpulse(const MT_Vector3& impulse);
        
        MT_Point3 getWorldCoord(const MT_Point3& local) const;
index f6b0f50..9751a4c 100644 (file)
@@ -168,6 +168,17 @@ integrateMomentum(
        }
 }
 
+/**
+ * dynamicCollision computes the response to a collision.
+ *
+ * @param local2 the contact point in local coordinates.
+ * @param normal the contact normal.
+ * @param dist the penetration depth of the contact. (unused)
+ * @param rel_vel the relative velocity of the objects
+ * @param restitution the amount of momentum conserved in the collision. Range: 0.0 - 1.0
+ * @param friction_factor the amount of friction between the two surfaces.
+ * @param invMass the inverse mass of the collision objects (1.0 / mass)
+ */
 void SM_Object::dynamicCollision(const MT_Point3 &local2, 
        const MT_Vector3 &normal, 
        MT_Scalar dist, 
@@ -177,10 +188,19 @@ void SM_Object::dynamicCollision(const MT_Point3 &local2,
        MT_Scalar invMass
 )
 {
-       // This should look familiar....
+       /**
+        * rel_vel_normal is the relative velocity in the contact normal direction.
+        */
        MT_Scalar  rel_vel_normal = normal.dot(rel_vel);
                        
-       if (rel_vel_normal < -MT_EPSILON) {
+       /**
+        * if rel_vel_normal > 0, the objects are moving apart! 
+        */
+       if (rel_vel_normal < 0.) {
+               /**
+                * if rel_vel_normal < ImpulseThreshold, scale the restitution down.
+                * This should improve the simulation where the object is stacked.
+                */
                restitution *= MT_min(MT_Scalar(1.0), rel_vel_normal/ImpulseThreshold);
                                
                MT_Scalar impulse = -(1.0 + restitution) * rel_vel_normal;
@@ -189,18 +209,20 @@ void SM_Object::dynamicCollision(const MT_Point3 &local2,
                {
                        MT_Vector3 temp = getInvInertiaTensor() * local2.cross(normal);
                        impulse /= invMass + normal.dot(temp.cross(local2));
+                       
+                       /**
+                        * Apply impulse at the collision point.
+                        * Take rotational inertia into account.
+                        */
                        applyImpulse(local2 + m_pos, impulse * normal);
                } else {
+                       /**
+                        * Apply impulse through object centre. (no rotation.)
+                        */
                        impulse /= invMass;
                        applyCenterImpulse( impulse * normal ); 
                }
                
-               // The friction part starts here!!!!!!!!
-
-               // Compute the lateral component of the relative velocity
-               // lateral actually points in the opposite direction, i.e.,
-               // into the direction of the friction force.
-
 #if 0
                // test - only do friction on the physics part of the 
                // velocity.
@@ -211,30 +233,37 @@ void SM_Object::dynamicCollision(const MT_Point3 &local2,
                rel_vel        = vel2 - vel1;
                rel_vel_normal = normal.dot(rel_vel);
 #endif
-                               
+               /**
+                * The friction part starts here!!!!!!!!
+                 *
+                * Compute the lateral component of the relative velocity
+                * lateral actually points in the opposite direction, i.e.,
+                * into the direction of the friction force.
+                */
                MT_Vector3 lateral =  rel_vel - normal * rel_vel_normal;
-               //printf("                 lateral = { %0.5f, %0.5f, %0.5f } (%0.5f)\n",
-               //      lateral[0], lateral[1], lateral[2], lateral.length());
-                       
-               //const SM_ShapeProps *shapeProps = obj2->getShapeProps();
-
                if (m_shapeProps->m_do_anisotropic) {
 
-                       // For anisotropic friction we scale the lateral component,
-                       // rather than compute a direction-dependent fricition 
-                       // factor. For this the lateral component is transformed to
-                       // local coordinates.
+                       /**
+                        * For anisotropic friction we scale the lateral component,
+                        * rather than compute a direction-dependent fricition 
+                        * factor. For this the lateral component is transformed to
+                        * local coordinates.
+                        */
 
                        MT_Matrix3x3 lcs(m_orn);
-                       // We cannot use m_xform.getBasis() for the matrix, since 
-                       // it might contain a non-uniform scaling. 
-                       // OPT: it's a bit daft to compute the matrix since the 
-                       // quaternion itself can be used to do the transformation.
-
+                       
+                       /**
+                        * We cannot use m_xform.getBasis() for the matrix, since 
+                        * it might contain a non-uniform scaling. 
+                        * OPT: it's a bit daft to compute the matrix since the 
+                        * quaternion itself can be used to do the transformation.
+                        */
                        MT_Vector3 loc_lateral = lateral * lcs;
-                       // lcs is orthogonal so lcs.inversed() == lcs.transposed(),
-                       // and lcs.transposed() * lateral == lateral * lcs.
-
+                       
+                       /**
+                        * lcs is orthogonal so lcs.inversed() == lcs.transposed(),
+                        * and lcs.transposed() * lateral == lateral * lcs.
+                        */
                        const MT_Vector3& friction_scaling = 
                                m_shapeProps->m_friction_scaling; 
 
@@ -246,23 +275,23 @@ void SM_Object::dynamicCollision(const MT_Point3 &local2,
                        lateral = lcs * loc_lateral;
                }
                        
-               // A tiny Coulomb friction primer:
-               // The Coulomb friction law states that the magnitude of the
-               // maximum possible friction force depends linearly on the 
-               // magnitude of the normal force.
-               //
-               // F_max_friction = friction_factor * F_normal 
-               //
-               // (NB: independent of the contact area!!)
-               //
-               // The friction factor depends on the material. 
-               // We use impulses rather than forces but let us not be 
-               // bothered by this. 
-
-
+               /**
+                * A tiny Coulomb friction primer:
+                * The Coulomb friction law states that the magnitude of the
+                * maximum possible friction force depends linearly on the 
+                * magnitude of the normal force.
+                *
+                * \f[
+                    F_max_friction = friction_factor * F_normal 
+                  \f]
+                *
+                * (NB: independent of the contact area!!)
+                *
+                * The friction factor depends on the material. 
+                * We use impulses rather than forces but let us not be 
+                * bothered by this. 
+                */
                MT_Scalar  rel_vel_lateral = lateral.length();
-               //printf("rel_vel = { %0.05f, %0.05f, %0.05f}\n", rel_vel[0], rel_vel[1], rel_vel[2]);
-               //printf("n.l = %0.15f\n", normal.dot(lateral)); /* Should be 0.0 */
 
                if (rel_vel_lateral > MT_EPSILON) {
                        lateral /= rel_vel_lateral;
@@ -275,17 +304,21 @@ void SM_Object::dynamicCollision(const MT_Point3 &local2,
 
                        assert(impulse >= 0.0);
 
-                       // Here's the trick. We compute the impulse to make the
-                       // lateral velocity zero. (Make the objects stick together
-                       // at the contact point. If this impulse is larger than
-                       // the maximum possible friction impulse, then shrink its
-                       // magnitude to the maximum friction.
+                       /**
+                        * Here's the trick. We compute the impulse to make the
+                        * lateral velocity zero. (Make the objects stick together
+                        * at the contact point. If this impulse is larger than
+                        * the maximum possible friction impulse, then shrink its
+                        * magnitude to the maximum friction.
+                        */
 
                        if (isRigidBody()) {
                                        
-                               // For rigid bodies we take the inertia into account, 
-                               // since the friction impulse is going to change the
-                               // angular momentum as well.
+                               /**
+                                * For rigid bodies we take the inertia into account, 
+                                * since the friction impulse is going to change the
+                                * angular momentum as well.
+                                */
                                MT_Vector3 temp = getInvInertiaTensor() * local2.cross(lateral);
                                MT_Scalar impulse_lateral = rel_vel_lateral /
                                        (invMass + lateral.dot(temp.cross(local2)));
@@ -303,8 +336,8 @@ void SM_Object::dynamicCollision(const MT_Point3 &local2,
 
                }       
 
-               calcXform();
-               notifyClient();
+               //calcXform();
+               //notifyClient();
 
        }
 }
@@ -353,7 +386,8 @@ DT_Bool SM_Object::boing(
        if (dist < MT_EPSILON)
                return DT_CONTINUE;
        
-       local1 -= obj1->m_pos, local2 -= obj2->m_pos;
+       local1 -= obj1->m_pos;
+       local2 -= obj2->m_pos;
        
        // Calculate collision parameters
        MT_Vector3 rel_vel        = obj1->getVelocity(local1) - obj2->getVelocity(local2);
@@ -377,8 +411,6 @@ DT_Bool SM_Object::boing(
        if (obj2->isDynamic())
                obj2->dynamicCollision(local2, -normal, dist, -rel_vel, restitution, friction_factor, invMass);
        
-       //fix(client_data, (void*) obj1, (void*) obj2, coll_data);
-       
        return DT_CONTINUE;
 }
 
@@ -428,26 +460,26 @@ DT_Bool SM_Object::fix(
                obj2->m_error -= error;
                // Remove the velocity component in the normal direction
                // Calculate collision parameters
-               MT_Vector3 rel_vel = obj1->getLinearVelocity() - obj2->getLinearVelocity();
+               /*MT_Vector3 rel_vel = obj1->getLinearVelocity() - obj2->getLinearVelocity();
                if (normal.length() > FixThreshold && rel_vel.length() < FixVelocity) {
                        normal.normalize();
                        MT_Scalar  rel_vel_normal = 0.49*(normal.dot(rel_vel));
 
                        obj1->addLinearVelocity(-rel_vel_normal*normal);
                        obj2->addLinearVelocity(rel_vel_normal*normal);
-               }
+               }*/
        }
        else {
                // Same again but now obj1 is non-dynamic
                obj2->m_error -= normal;
-               MT_Vector3 rel_vel = obj2->getLinearVelocity();
+               /*MT_Vector3 rel_vel = obj2->getLinearVelocity();
                if (normal.length() > FixThreshold && rel_vel.length() < FixVelocity) {
                        // Calculate collision parameters
                        normal.normalize();
                        MT_Scalar  rel_vel_normal = -0.99*(normal.dot(rel_vel));
 
                        obj2->addLinearVelocity(rel_vel_normal*normal);
-               } 
+               }*/ 
        }
        
        return DT_CONTINUE;
@@ -496,7 +528,6 @@ SM_Object::SM_Object() :
        m_fh_object(0) 
 {
        // warning no initialization of variables done by moto.
-       std::cout << "SM_Object::SM_Object()" << std::endl;
 }
 
 SM_Object::
index a48ef01..26ff526 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * $Id$
+ * @file $Id$
  *
  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
  *
 #include "SM_Callback.h"
 
 /**
-       Sumo Physics Controller, a special kind of a PhysicsController.
-       A Physics Controller is a special kind of Scene Graph Transformation Controller.
-       Each time the scene graph get's updated, the controller get's a chance
-       in the 'Update' method to reflect changes.
-*/
-
+ *     Sumo Physics Controller, a special kind of a PhysicsController.
+ *     A Physics Controller is a special kind of Scene Graph Transformation Controller.
+ *     Each time the scene graph get's updated, the controller get's a chance
+ *     in the 'Update' method to reflect changes.
+ *     
+ *     Sumo uses the SOLID library for collision detection.
+ */
 class SumoPhysicsController : public PHY_IPhysicsController , public SM_Callback
 
                                                         
@@ -58,15 +59,26 @@ public:
 
        virtual ~SumoPhysicsController();
        
-               // kinematic methods
+       /** 
+        * @name Kinematic Methods.
+        */
+       /*@{*/
        virtual void            RelativeTranslate(float dlocX,float dlocY,float dlocZ,bool local);
+       /**
+        * @param drot a 3x4 matrix.  This will treated as a 3x3 rotation matrix.
+        * @warning RelativeRotate expects a 3x4 matrix.  The fourth column is padding.
+        */
        virtual void            RelativeRotate(const float drot[12],bool local);
        virtual void            getOrientation(float &quatImag0,float &quatImag1,float &quatImag2,float &quatReal);
        virtual void            setOrientation(float quatImag0,float quatImag1,float quatImag2,float quatReal);
        virtual void            setPosition(float posX,float posY,float posZ);
        virtual void            setScaling(float scaleX,float scaleY,float scaleZ);
+       /*@}*/
        
-       // physics methods
+       /**
+        * @name Physics Methods
+        */
+       /*@{*/
        virtual void            ApplyTorque(float torqueX,float torqueY,float torqueZ,bool local);
        virtual void            ApplyForce(float forceX,float forceY,float forceZ,bool local);
        virtual void            SetAngularVelocity(float ang_velX,float ang_velY,float ang_velZ,bool local);
@@ -76,15 +88,16 @@ public:
        virtual void            SetActive(bool active){};
        virtual void            SuspendDynamics();
        virtual void            RestoreDynamics();
+       /*@}*/
 
 
        /**  
-               reading out information from physics
-       */
+        *      reading out information from physics
+        */
        virtual void            GetLinearVelocity(float& linvX,float& linvY,float& linvZ);
        /** 
-               GetVelocity parameters are in geometric coordinates (Origin is not center of mass!).
-       */
+        *      GetVelocity parameters are in geometric coordinates (Origin is not center of mass!).
+        */
        virtual void            GetVelocity(const float posX,const float posY,const float posZ,float& linvX,float& linvY,float& linvZ); 
        virtual float           getMass();
        virtual void            getReactionForce(float& forceX,float& forceY,float& forceZ);
@@ -93,28 +106,27 @@ public:
        
        virtual void            PostProcessReplica(class PHY_IMotionState* motionstate,class PHY_IPhysicsController* parentctrl);
        
-       // todo: remove next line !
+       // TODO: remove next line !
        virtual void                    SetSimulatedTime(float time);
        
-
        virtual void            WriteDynamicsToMotionState() {};
        virtual void    WriteMotionStateToDynamics(bool nondynaonly);
 
        /** 
-               call from Scene Graph Node to 'update'.
-       */
+        *      call from Scene Graph Node to 'update'.
+        */
        virtual bool    SynchronizeMotionStates(float time);
 
-               // clientinfo for raycasts for example
+       // clientinfo for raycasts for example
        virtual void*                           getClientInfo() { return m_clientInfo;}
        virtual void                            setClientInfo(void* clientinfo) {m_clientInfo = clientinfo;};
-       void*                                           m_clientInfo;
-
 
        float   getFriction() { return m_friction;}
        float   getRestitution() { return m_restitution;}
 
-       // sumo callback
+       /**
+        * Sumo callback
+        */
        virtual void do_me();
 
        class SM_Object*        GetSumoObject ()
@@ -161,6 +173,9 @@ private:
 
        class   PHY_IMotionState*       m_MotionState;
        
+       void*                           m_clientInfo;
+
+       
 };
 
 #endif //__SUMO_PHYSICSCONTROLLER_H
index 8c94083..f517abc 100644 (file)
@@ -61,7 +61,7 @@ class PHY_IPhysicsController
 
                // kinematic methods
                virtual void            RelativeTranslate(float dlocX,float dlocY,float dlocZ,bool local)=0;
-               virtual void            RelativeRotate(const float drot[9],bool local)=0;
+               virtual void            RelativeRotate(const float drot[12],bool local)=0;
                virtual void            getOrientation(float &quatImag0,float &quatImag1,float &quatImag2,float &quatReal)=0;
                virtual void            setOrientation(float quatImag0,float quatImag1,float quatImag2,float quatReal)=0;
                virtual void            setPosition(float posX,float posY,float posZ)=0;
index 9871c0b..4482383 100644 (file)
@@ -46,7 +46,6 @@ class RAS_IPolyMaterial;
 /**
  * 3D rendering device context interface. 
  */
-
 class RAS_IRasterizer
 {
 
@@ -54,9 +53,14 @@ public:
 
        RAS_IRasterizer(RAS_ICanvas* canv){};
        virtual ~RAS_IRasterizer(){};
+       /**
+        */
        enum    {
                        RAS_RENDER_3DPOLYGON_TEXT = 16384
        };
+       /**
+        * Drawing types
+        */
        enum    {
                        KX_BOUNDINGBOX = 1,
                        KX_WIREFRAME,
@@ -65,47 +69,101 @@ public:
                        KX_TEXTURED 
        };
 
+       /**
+        * Valid SetDepthMask parameters
+        */
        enum    {
                        KX_DEPTHMASK_ENABLED =1,
                        KX_DEPTHMASK_DISABLED
        };
 
+       /**
+        */
        enum    {        
                        KX_TWOSIDE = 512,        
                        KX_LINES = 32768         
        };
 
+       /**
+        * Stereo mode types
+        */
        enum    {
                        RAS_STEREO_NOSTEREO = 1,
                        RAS_STEREO_QUADBUFFERED,
                        RAS_STEREO_ABOVEBELOW,
                        RAS_STEREO_INTERLACED
        };
+       /**
+        * Render pass identifiers for stereo.
+        */
        enum    {
                        RAS_STEREO_LEFTEYE = 1,
                        RAS_STEREO_RIGHTEYE
        };
 
+       /**
+        * SetDepthMask enables or disables writing a fragment's depth value
+        * to the Z buffer.
+        */
        virtual void    SetDepthMask(int depthmask)=0;
+       /**
+        * SetMaterial sets the material settings for subsequent primitives
+        * to be rendered with.
+        * The material will be cached.
+        */
        virtual void    SetMaterial(const RAS_IPolyMaterial& mat)=0;
+       /**
+        * Init initialises the renderer.
+        */
        virtual bool    Init()=0;
+       /**
+        * Exit cleans up the renderer.
+        */
        virtual void    Exit()=0;
+       /**
+        * BeginFrame is called at the start of each frame.
+        */
        virtual bool    BeginFrame(int drawingmode, double time)=0;
+       /**
+        * ClearDepthBuffer clears the depth buffer.
+        */
        virtual void    ClearDepthBuffer()=0;
+       /**
+        * ClearCachingInfo clears the currently cached material.
+        */
        virtual void    ClearCachingInfo(void)=0;
+       /**
+        * EndFrame is called at the end of each frame.
+        */
        virtual void    EndFrame()=0;
        /**
-        * SetRenderArea sets the render area in the 2d canvas
+        * SetRenderArea sets the render area from the 2d canvas
         */
        virtual void    SetRenderArea()=0;
 
        // Stereo Functions
+       /**
+        * SetStereoMode will set the stereo mode
+        */
        virtual void    SetStereoMode(const int stereomode)=0;
+       /**
+        * Stereo can be used to query if the rasterizer is in stereo mode.
+        * @return true if stereo mode is enabled.
+        */
        virtual bool    Stereo()=0;
+       /**
+        * Sets which eye buffer subsequent primitives will be rendered to.
+        */
        virtual void    SetEye(const int eye)=0;
+       /**
+        */
        virtual void    SetEyeSeparation(const float eyeseparation)=0;
+       /**
+        */
        virtual void    SetFocalLength(const float focallength)=0;
-
+       /**
+        * SwapBuffers swaps the back buffer with the front buffer.
+        */
        virtual void    SwapBuffers()=0;
        
        // Drawing Functions
@@ -129,7 +187,7 @@ public:
                                                        bool useObjectColor,
                                                        const MT_Vector4& rgbacolor)=0;
        /**
-        * IndexPrimitivesEx: See IndexPrimitives.
+        * @copydoc IndexPrimitives
         * IndexPrimitivesEx will renormalize faces if @param vertexarrays[i].getFlag() & TV_CALCFACENORMAL
         */
        virtual void    IndexPrimitives_Ex( const vecVertexArray& vertexarrays,
@@ -159,13 +217,21 @@ public:
         * @param mat The projection matrix.
         */
        virtual void    SetProjectionMatrix(MT_Matrix4x4 & mat)=0;
+       /**
+        * Sets the modelview matrix.
+        */
        virtual void    SetViewMatrix(const MT_Matrix4x4 & mat,
                                                const MT_Vector3& campos,
                                                const MT_Point3 &camLoc,
                                                const MT_Quaternion &camOrientQuat)=0;
+       /**
+        */
        virtual const   MT_Point3& GetCameraPosition()=0;
+       /**
+        */
        virtual void    LoadViewMatrix()=0;
-       
+       /**
+        */
        virtual void    SetFog(float start,
                                                   float dist,
                                                   float r,
@@ -177,9 +243,14 @@ public:
                                                                float b)=0;
 
        virtual void    SetFogStart(float start)=0;
+       /**
+        */
        virtual void    SetFogEnd(float end)=0;
-
+       /**
+        */
        virtual void    DisplayFog()=0;
+       /**
+        */
        virtual void    DisableFog()=0;
 
        virtual void    SetBackColor(float red,
@@ -191,18 +262,34 @@ public:
         * @param drawingmode = KX_BOUNDINGBOX, KX_WIREFRAME, KX_SOLID, KX_SHADED or KX_TEXTURED.
         */
        virtual void    SetDrawingMode(int drawingmode)=0;
-       virtual int             GetDrawingMode()=0;
-
+       /**
+        * @return the current drawing mode: KX_BOUNDINGBOX, KX_WIREFRAME, KX_SOLID, KX_SHADED or KX_TEXTURED.
+        */
+       virtual int     GetDrawingMode()=0;
+       /**
+        */
        virtual void    EnableTextures(bool enable)=0;
-       
+       /**
+        * Sets face culling
+        */     
        virtual void    SetCullFace(bool enable)=0;
        /**
         * Sets wireframe mode.
         */
        virtual void    SetLines(bool enable)=0;
-
+       /**
+        */
        virtual double  GetTime()=0;
-
+       /**
+        * Generates a projection matrix from the specified frustum.
+        * @param left the left clipping plane
+        * @param right the right clipping plane
+        * @param bottom the bottom clipping plane
+        * @param top the top clipping plane
+        * @param frustnear the near clipping plane
+        * @param frustfar the far clipping plane
+        * @return a 4x4 matrix representing the projection transform.
+        */
        virtual MT_Matrix4x4 GetFrustumMatrix(
                float left,
                float right,
index ce86d52..79ec632 100644 (file)
@@ -43,16 +43,14 @@ STR_String RAS_MeshObject::s_emptyname = "";
 
 KX_ArrayOptimizer::~KX_ArrayOptimizer()
 {
-       int i = 0;
-       
        for (vector<KX_VertexArray*>::iterator itv = m_VertexArrayCache1.begin();
-       !(itv == m_VertexArrayCache1.end());itv++)
+       !(itv == m_VertexArrayCache1.end());++itv)
        {
                delete (*itv);
        }
 
        for (vector<KX_IndexArray*>::iterator iti = m_IndexArrayCache1.begin();
-       !(iti == m_IndexArrayCache1.end());iti++)
+       !(iti == m_IndexArrayCache1.end());++iti)
        {
                delete (*iti);
        }
@@ -99,43 +97,23 @@ int RAS_MeshObject::NumMaterials()
        return m_materials.size();
 }
 
-       
-       
 const STR_String& RAS_MeshObject::GetMaterialName(unsigned int matid)
 { 
-       if (m_materials.size() > 0 && (matid < m_materials.size()))
-       {
-               BucketMaterialSet::iterator it = m_materials.begin();
-
-               for (unsigned int i = 1; i < m_materials.size(); i++)
-               {
-                       it++;
-               }
-               return (*it)->GetPolyMaterial()->GetMaterialName();
-       }
-
-       return s_emptyname;
+       RAS_MaterialBucket* bucket = GetMaterialBucket(matid);
+       
+       return bucket?bucket->GetPolyMaterial()->GetMaterialName():s_emptyname;
 }
 
-
-
 RAS_MaterialBucket* RAS_MeshObject::GetMaterialBucket(unsigned int matid)
 {
-       RAS_MaterialBucket* bucket = NULL;
-       
        if (m_materials.size() > 0 && (matid < m_materials.size()))
        {
-               BucketMaterialSet::iterator it = m_materials.begin();
-               int i = matid;
-               while (i > 0)
-               {
-                       i--;
-                       it++;
-               }
-               bucket = *it;
+               BucketMaterialSet::const_iterator it = m_materials.begin();
+               while (matid--) ++it;
+               return *it;
        }
 
-       return bucket;
+       return NULL;
 }
 
 
@@ -184,18 +162,9 @@ const STR_String& RAS_MeshObject::GetName()
 
 const STR_String& RAS_MeshObject::GetTextureName(unsigned int matid)
 { 
-       if (m_materials.size() > 0 && (matid < m_materials.size()))
-       {
-               BucketMaterialSet::iterator it = m_materials.begin();
-               for (unsigned int i = 1; i < m_materials.size(); i++)
-               {
-                       it++;
-               }
-
-               return (*it)->GetPolyMaterial()->GetTextureName();
-       }
-
-       return s_emptyname;
+       RAS_MaterialBucket* bucket = GetMaterialBucket(matid);
+       
+       return bucket?bucket->GetPolyMaterial()->GetTextureName():s_emptyname;
 }
 
 
@@ -232,7 +201,6 @@ void RAS_MeshObject::SchedulePoly(const KX_VertexIndex& idx,
                                                                  RAS_IPolyMaterial* mat)
 {
        //int indexpos = m_IndexArrayCount[idx.m_vtxarray];
-       int indexidx = 0;
        //m_IndexArrayCount[idx.m_vtxarray] = indexpos + 3;
        
        KX_ArrayOptimizer* ao = GetArrayOptimizer(mat);
@@ -345,7 +313,7 @@ int RAS_MeshObject::GetVertexArrayLength(RAS_IPolyMaterial* mat)
        const vecVertexArray & vertexvec = GetVertexCache(mat);
        vector<KX_VertexArray*>::const_iterator it = vertexvec.begin();
        
-       for (; it != vertexvec.end(); it++)
+       for (; it != vertexvec.end(); ++it)
        {
                len += (*it)->size();
        }
@@ -369,7 +337,7 @@ RAS_TexVert* RAS_MeshObject::GetVertex(unsigned int matid,
                        const vecVertexArray & vertexvec = GetVertexCache(mat);
                        vector<KX_VertexArray*>::const_iterator it = vertexvec.begin();
                        
-                       for (unsigned int len = 0; it != vertexvec.end(); it++)
+                       for (unsigned int len = 0; it != vertexvec.end(); ++it)
                        {
                                if (index < len + (*it)->size())
                                {
@@ -428,12 +396,11 @@ void RAS_MeshObject::Bucketize(double* oglmatrix,
        ms.m_bObjectColor = useObjectColor;
        ms.m_RGBAcolor = rgbavec;
        
-       int i=0;
-       for (BucketMaterialSet::iterator it = m_materials.begin();it!=m_materials.end();it++)
+       for (BucketMaterialSet::iterator it = m_materials.begin();it!=m_materials.end();++it)
        {
                RAS_MaterialBucket* bucket = *it;
                bucket->SchedulePolygons(0);
-               KX_ArrayOptimizer* oa = GetArrayOptimizer(bucket->GetPolyMaterial());
+//             KX_ArrayOptimizer* oa = GetArrayOptimizer(bucket->GetPolyMaterial());
                bucket->SetMeshSlot(ms);
        }
 
@@ -454,11 +421,11 @@ void RAS_MeshObject::MarkVisible(double* oglmatrix,
        ms.m_RGBAcolor = rgbavec;
        ms.m_bObjectColor= useObjectColor;
 
-       for (BucketMaterialSet::iterator it = m_materials.begin();it!=m_materials.end();it++)
+       for (BucketMaterialSet::iterator it = m_materials.begin();it!=m_materials.end();++it)
        {
                RAS_MaterialBucket* bucket = *it;
                bucket->SchedulePolygons(0);
-               KX_ArrayOptimizer* oa = GetArrayOptimizer(bucket->GetPolyMaterial());
+//             KX_ArrayOptimizer* oa = GetArrayOptimizer(bucket->GetPolyMaterial());
                bucket->MarkVisibleMeshSlot(ms,visible,useObjectColor,rgbavec);
        }
 }
@@ -473,10 +440,10 @@ void RAS_MeshObject::RemoveFromBuckets(double* oglmatrix,
        ms.m_mesh = this;
        ms.m_OpenGLMatrix = oglmatrix;
 
-       for (BucketMaterialSet::iterator it = m_materials.begin();it!=m_materials.end();it++)
+       for (BucketMaterialSet::iterator it = m_materials.begin();it!=m_materials.end();++it)
        {
                RAS_MaterialBucket* bucket = *it;
-               RAS_IPolyMaterial* polymat = bucket->GetPolyMaterial();
+//             RAS_IPolyMaterial* polymat = bucket->GetPolyMaterial();
                bucket->SchedulePolygons(0);
                //KX_ArrayOptimizer* oa = GetArrayOptimizer(polymat);
                bucket->RemoveMeshSlot(ms);
@@ -502,8 +469,9 @@ RAS_TexVert* RAS_MeshObject::GetVertex(short array,
 
 void RAS_MeshObject::ClearArrayData()
 {
-       for (int i=0;i<m_matVertexArrayS.size();i++)
-       {       KX_ArrayOptimizer** ao = m_matVertexArrayS.at(i);
+       for (unsigned int i=0;i<m_matVertexArrayS.size();i++)
+       {
+               KX_ArrayOptimizer** ao = m_matVertexArrayS.at(i);
                if (ao)
                        delete *ao;
        }
@@ -517,7 +485,7 @@ void RAS_MeshObject::ClearArrayData()
 int    RAS_MeshObject::FindVertexArray(int numverts,
                                                                        RAS_IPolyMaterial* polymat)
 {
-       bool found=false;
+//     bool found=false;
        int array=-1;
        
        KX_ArrayOptimizer* ao = GetArrayOptimizer(polymat);
@@ -577,26 +545,24 @@ void RAS_MeshObject::RelativeTransform(const MT_Vector3& vec)
 void RAS_MeshObject::UpdateMaterialList()
 {
        m_materials.clear();
-       int numpolys = m_Polygons.size();
+       unsigned int numpolys = m_Polygons.size();
        // for all polygons, find out which material they use, and add it to the set of materials
-       for (int i=0;i<numpolys;i++)
+       for (unsigned int i=0;i<numpolys;i++)
        {
                m_materials.insert(m_Polygons[i]->GetMaterial());
        }
-       int nummaterials = m_materials.size();
-
 }
 
 
 
 void RAS_MeshObject::SchedulePolygons(int drawingmode,RAS_IRasterizer* rasty)
 {
-       int nummaterials = m_materials.size();
+//     int nummaterials = m_materials.size();
        int i;
 
        if (m_bModified)
        {
-               for (BucketMaterialSet::iterator it = m_materials.begin();it!=m_materials.end();it++)
+               for (BucketMaterialSet::iterator it = m_materials.begin();it!=m_materials.end();++it)
                {
                        RAS_MaterialBucket* bucket = *it;
 
index e26715e..87a5e6b 100644 (file)
@@ -100,7 +100,9 @@ inline  bool operator <( const RAS_MatArrayIndex& rhs,const RAS_MatArrayIndex& l
        return ( rhs.Less(lhs));
 }
 
-
+/**
+ * RAS_MeshObject stores mesh data for the renderer.
+ */
 class RAS_MeshObject
 {
        
@@ -176,8 +178,8 @@ public:
 
        void                            ClearArrayData();
        
-       set<RAS_MaterialBucket*>::iterator GetFirstMaterial();
-       set<RAS_MaterialBucket*>::iterator GetLastMaterial();
+       BucketMaterialSet::iterator GetFirstMaterial();
+       BucketMaterialSet::iterator GetLastMaterial();
        
        virtual RAS_TexVert*    GetVertex(
                                                                short array,
index 134c3ca..eaed233 100644 (file)
        the GL function entry
 
 */
-#ifdef __APPLE__
+#if defined(BGL_NO_EXTENSIONS)
+static void bglInitEntryPoints (void) {}
+static void bglDeallocEntryPoints (void) {}
+
+static void *bglGetProcAddress(const GLubyte* entry)
+{
+       /* No Extensions! */
+       return NULL;
+}
+#elif defined(__APPLE__)
 /* http://developer.apple.com/qa/qa2001/qa1188.html */
 CFBundleRef gBundleRefOpenGL = NULL;
 
@@ -207,11 +216,11 @@ static void *bglGetProcAddress(const GLubyte* entry)
 
    GL Extension Manager.
 */
-static std::vector<STR_String> extensions;
-/* Bit array of available extensions */
+       /* Bit array of available extensions */
 static unsigned int enabled_extensions[(bgl::NUM_EXTENSIONS + 8*sizeof(unsigned int) - 1)/(8*sizeof(unsigned int))];
+static std::vector<STR_String> extensions;
 static int m_debug;
-
+       
 static void LinkExtensions();
 
 static void EnableExtension(bgl::ExtensionName name)
@@ -259,15 +268,12 @@ bool QueryVersion(int major, int minor)
                int i = gl_version.Find('.');
                gl_major = gl_version.Left(i).ToInt();
                gl_minor = gl_version.Mid(i+1, gl_version.FindOneOf(". ", i+1) - i - 1).ToInt();
-               
-               if (m_debug)
+       
+               static bool doQueryVersion = m_debug;
+               if (doQueryVersion)
                {
-                       static bool doQueryVersion = true;
-                       if (doQueryVersion)
-                       {
-                               doQueryVersion = false;
-                               std::cout << "GL_VERSION: " << gl_major << "." << gl_minor << " (" << gl_version << ")" << std::endl;
-                       }
+                       doQueryVersion = false;
+                       std::cout << "GL_VERSION: " << gl_major << "." << gl_minor << " (" << gl_version << ")" << std::endl;
                }
        }
        
@@ -317,7 +323,7 @@ Use EnableExtension(_GL_EXT_...) to allow Blender to use the extension.
  ******************************************************************************/
 static void LinkExtensions()
 {
-       static bool doDebugMessages = true;
+       static bool doDebugMessages = m_debug;
        extensions = STR_String((const char *) glGetString(GL_EXTENSIONS)).Explode(' ');
 
        doDebugMessages = false;
index c249a48..50a67ee 100644 (file)
@@ -48,6 +48,7 @@ namespace bgl
         */
        typedef enum {
                /* ARB Extensions */
+               _GL_ARB_imaging,
                _GL_ARB_multitexture ,
                _GLX_ARB_get_proc_address ,
                _GL_ARB_transpose_matrix ,
index 24f257b..912b478 100644 (file)
@@ -362,8 +362,8 @@ Example code output:
                if (glUnlockArraysEXT && glLockArraysEXT)
                {
                        EnableExtension(_GL_EXT_compiled_vertex_array);
-                       if (m_debug && doDebugMessages)
-                               std::cout << "Enabled GL_EXT_compiled_vertex_array" << std::endl;
+                       if (doDebugMessages)
+                               std::cout << "Detected GL_EXT_compiled_vertex_array" << std::endl;
                } else {
                        std::cout << "ERROR: GL_EXT_compiled_vertex_array implementation is broken!" << std::endl;
                }
@@ -374,11 +374,13 @@ def writeext(ext, fnlist):
        if (find(blacklist, ext)):
                return
        if (len(fnlist) == 0):
+               # This extension has no functions to detect - don't need to wrap in
+               # #ifdef GL_extension names
                print "\tif (QueryExtension(\"" + ext + "\"))"
                print "\t{"
                print "\t\tEnableExtension(_" + ext + ");"
-               print "\t\tif (m_debug && doDebugMessages)"
-               print "\t\t\tstd::cout << \"Enabled " + ext + "\" << std::endl;"
+               print "\t\tif (doDebugMessages)"
+               print "\t\t\tstd::cout << \"Detected " + ext + "\" << std::endl;"
                print "\t}"
                print
                return
@@ -395,7 +397,7 @@ def writeext(ext, fnlist):
                        errcheck = errcheck + " && " + fn[0]
        print "\t\tif (" + errcheck + ") {"
        print "\t\t\tEnableExtension(_" + ext + ");"
-       print "\t\t\tif (m_debug && doDebugMessages)"
+       print "\t\t\tif (doDebugMessages)"
        print "\t\t\t\tstd::cout << \"Enabled " + ext + "\" << std::endl;"
        print "\t\t} else {"
        print "\t\t\tstd::cout << \"ERROR: " + ext + " implementation is broken!\" << std::endl;"
index 918b4ea..86dbc7c 100644 (file)
@@ -1,4 +1,5 @@
 /**
+ * @file SG_Controller.cpp
  * $Id$
  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
  *
index 3fd4a7f..b5bb694 100644 (file)
@@ -37,6 +37,9 @@
 
 #include "SG_IObject.h"
 
+/**
+ * A scenegraph controller
+ */
 class SG_Controller 
 {
 public:
index e37fd08..77e805c 100644 (file)
@@ -48,13 +48,13 @@ SG_Spatial(
 
        SG_IObject(clientobj,clientinfo,callbacks),
        m_localPosition(MT_Point3(0,0,0)),
-       m_localScaling(MT_Vector3(1.f,1.f,1.f)),
        m_localRotation(1,0,0,0,1,0,0,0,1),
+       m_localScaling(MT_Vector3(1.f,1.f,1.f)),
        m_parent_relation (NULL),
 
        m_worldPosition(MT_Point3(0,0,0)),
-       m_worldScaling(MT_Vector3(1.f,1.f,1.f)),
-       m_worldRotation(0,0,0,0,0,0,0,0,0)
+       m_worldRotation(0,0,0,0,0,0,0,0,0),
+       m_worldScaling(MT_Vector3(1.f,1.f,1.f))
 
 {
 }
@@ -65,12 +65,12 @@ SG_Spatial(
 ) : 
        SG_IObject(other),
        m_localPosition(other.m_localPosition),
-       m_localScaling(other.m_localScaling),
        m_localRotation(other.m_localRotation),
+       m_localScaling(other.m_localScaling),
        m_parent_relation(NULL),
        m_worldPosition(other.m_worldPosition),
-       m_worldScaling(other.m_worldScaling),
-       m_worldRotation(other.m_worldRotation)
+       m_worldRotation(other.m_worldRotation),
+       m_worldScaling(other.m_worldScaling)
 {
        // duplicate the parent relation for this object
        m_parent_relation = other.m_parent_relation->NewCopy();