synched with trunk at revision 36569
[blender.git] / source / gameengine / Converter / BL_BlenderDataConversion.cpp
index 969d8f8..1591e3b 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * $Id$
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
  * Convert blender data to ketsji
  */
 
+/** \file gameengine/Converter/BL_BlenderDataConversion.cpp
+ *  \ingroup bgeconv
+ */
+
+
 #if defined(WIN32) && !defined(FREE_WINDOWS)
 #pragma warning (disable : 4786)
 #endif
@@ -151,7 +156,7 @@ extern "C" {
 #include "KX_ScalarInterpolator.h"
 
 #include "KX_IpoConvert.h"
-#include "SYS_System.h"
+#include "BL_System.h"
 
 #include "SG_Node.h"
 #include "SG_BBox.h"
@@ -733,13 +738,13 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, KX_Scene* scene,
        MFace *mface = dm->getFaceArray(dm);
        MTFace *tface = static_cast<MTFace*>(dm->getFaceDataArray(dm, CD_MTFACE));
        MCol *mcol = static_cast<MCol*>(dm->getFaceDataArray(dm, CD_MCOL));
-       float (*tangent)[3] = NULL;
+       float (*tangent)[4] = NULL;
        int totface = dm->getNumFaces(dm);
        const char *tfaceName = "";
 
        if(tface) {
                DM_add_tangent_layer(dm);
-               tangent = (float(*)[3])dm->getFaceDataArray(dm, CD_TANGENT);
+               tangent = (float(*)[4])dm->getFaceDataArray(dm, CD_TANGENT);
        }
 
        meshobj = new RAS_MeshObject(mesh);
@@ -962,7 +967,7 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, KX_Scene* scene,
        
                                if (ma) {
                                        polymat->m_specular = MT_Vector3(ma->specr, ma->specg, ma->specb)*ma->spec;
-                                       polymat->m_shininess = (float)ma->har/4.0; // 0 < ma->har <= 512
+                                       polymat->m_shininess = (float)ma->har/4.0f; // 0 < ma->har <= 512
                                        polymat->m_diffuse = MT_Vector3(ma->r, ma->g, ma->b)*(ma->emit + ma->ref);
                                }
                                else {
@@ -1133,7 +1138,7 @@ static float my_boundbox_mesh(Mesh *me, float *loc, float *size)
 {
        MVert *mvert;
        BoundBox *bb;
-       MT_Point3 min, max;
+       float min[3], max[3];
        float mloc[3], msize[3];
        float radius=0.0f, vert_radius, *co;
        int a;
@@ -1160,17 +1165,17 @@ static float my_boundbox_mesh(Mesh *me, float *loc, float *size)
        }
                
        if(me->totvert) {
-               loc[0]= (min[0]+max[0])/2.0;
-               loc[1]= (min[1]+max[1])/2.0;
-               loc[2]= (min[2]+max[2])/2.0;
+               loc[0]= (min[0]+max[0])/2.0f;
+               loc[1]= (min[1]+max[1])/2.0f;
+               loc[2]= (min[2]+max[2])/2.0f;
                
-               size[0]= (max[0]-min[0])/2.0;
-               size[1]= (max[1]-min[1])/2.0;
-               size[2]= (max[2]-min[2])/2.0;
+               size[0]= (max[0]-min[0])/2.0f;
+               size[1]= (max[1]-min[1])/2.0f;
+               size[2]= (max[2]-min[2])/2.0f;
        }
        else {
-               loc[0]= loc[1]= loc[2]= 0.0;
-               size[0]= size[1]= size[2]= 0.0;
+               loc[0]= loc[1]= loc[2]= 0.0f;
+               size[0]= size[1]= size[2]= 0.0f;
        }
                
        bb->vec[0][0]=bb->vec[1][0]=bb->vec[2][0]=bb->vec[3][0]= loc[0]-size[0];
@@ -1208,8 +1213,8 @@ static void my_tex_space_mesh(Mesh *me)
                                        DO_MINMAX(fp, min, max);
                                }
                                if(kb->totelem) {
-                                       loc[0]= (min[0]+max[0])/2.0; loc[1]= (min[1]+max[1])/2.0; loc[2]= (min[2]+max[2])/2.0;
-                                       size[0]= (max[0]-min[0])/2.0; size[1]= (max[1]-min[1])/2.0; size[2]= (max[2]-min[2])/2.0;
+                                       loc[0]= (min[0]+max[0])/2.0f; loc[1]= (min[1]+max[1])/2.0f; loc[2]= (min[2]+max[2])/2.0f;
+                                       size[0]= (max[0]-min[0])/2.0f; size[1]= (max[1]-min[1])/2.0f; size[2]= (max[2]-min[2])/2.0f;
        } 
        else {
                                        loc[0]= loc[1]= loc[2]= 0.0;
@@ -1221,19 +1226,19 @@ static void my_tex_space_mesh(Mesh *me)
        
                VECCOPY(me->loc, loc);
                VECCOPY(me->size, size);
-               me->rot[0]= me->rot[1]= me->rot[2]= 0.0;
+               me->rot[0]= me->rot[1]= me->rot[2]= 0.0f;
        
-               if(me->size[0]==0.0) me->size[0]= 1.0;
-               else if(me->size[0]>0.0 && me->size[0]<0.00001) me->size[0]= 0.00001;
-               else if(me->size[0]<0.0 && me->size[0]> -0.00001) me->size[0]= -0.00001;
+               if(me->size[0]==0.0) me->size[0]= 1.0f;
+               else if(me->size[0]>0.0 && me->size[0]< 0.00001f) me->size[0]= 0.00001f;
+               else if(me->size[0]<0.0 && me->size[0]> -0.00001f) me->size[0]= -0.00001f;
        
-               if(me->size[1]==0.0) me->size[1]= 1.0;
-               else if(me->size[1]>0.0 && me->size[1]<0.00001) me->size[1]= 0.00001;
-               else if(me->size[1]<0.0 && me->size[1]> -0.00001) me->size[1]= -0.00001;
+               if(me->size[1]==0.0) me->size[1]= 1.0f;
+               else if(me->size[1]>0.0 && me->size[1]< 0.00001f) me->size[1]= 0.00001f;
+               else if(me->size[1]<0.0 && me->size[1]> -0.00001f) me->size[1]= -0.00001f;
                                                
-               if(me->size[2]==0.0) me->size[2]= 1.0;
-               else if(me->size[2]>0.0 && me->size[2]<0.00001) me->size[2]= 0.00001;
-               else if(me->size[2]<0.0 && me->size[2]> -0.00001) me->size[2]= -0.00001;
+               if(me->size[2]==0.0) me->size[2]= 1.0f;
+               else if(me->size[2]>0.0 && me->size[2]< 0.00001f) me->size[2]= 0.00001f;
+               else if(me->size[2]<0.0 && me->size[2]> -0.00001f) me->size[2]= -0.00001f;
        }
        
 }
@@ -1250,13 +1255,13 @@ static void my_get_local_bounds(Object *ob, DerivedMesh *dm, float *center, floa
                                float min_r[3], max_r[3];
                                INIT_MINMAX(min_r, max_r);
                                dm->getMinMax(dm, min_r, max_r);
-                               size[0]= 0.5*fabs(max_r[0] - min_r[0]);
-                               size[1]= 0.5*fabs(max_r[1] - min_r[1]);
-                               size[2]= 0.5*fabs(max_r[2] - min_r[2]);
+                               size[0]= 0.5f*fabsf(max_r[0] - min_r[0]);
+                               size[1]= 0.5f*fabsf(max_r[1] - min_r[1]);
+                               size[2]= 0.5f*fabsf(max_r[2] - min_r[2]);
                                        
-                               center[0]= 0.5*(max_r[0] + min_r[0]);
-                               center[1]= 0.5*(max_r[1] + min_r[1]);
-                               center[2]= 0.5*(max_r[2] + min_r[2]);
+                               center[0]= 0.5f*(max_r[0] + min_r[0]);
+                               center[1]= 0.5f*(max_r[1] + min_r[1]);
+                               center[2]= 0.5f*(max_r[2] + min_r[2]);
                                return;
                        } else
                        {
@@ -1289,13 +1294,13 @@ static void my_get_local_bounds(Object *ob, DerivedMesh *dm, float *center, floa
        }
        else 
        {
-               size[0]= 0.5*fabs(bb->vec[0][0] - bb->vec[4][0]);
-               size[1]= 0.5*fabs(bb->vec[0][1] - bb->vec[2][1]);
-               size[2]= 0.5*fabs(bb->vec[0][2] - bb->vec[1][2]);
+               size[0]= 0.5f*fabs(bb->vec[0][0] - bb->vec[4][0]);
+               size[1]= 0.5f*fabs(bb->vec[0][1] - bb->vec[2][1]);
+               size[2]= 0.5f*fabs(bb->vec[0][2] - bb->vec[1][2]);
                                        
-               center[0]= 0.5*(bb->vec[0][0] + bb->vec[4][0]);
-               center[1]= 0.5*(bb->vec[0][1] + bb->vec[2][1]);
-               center[2]= 0.5*(bb->vec[0][2] + bb->vec[1][2]);
+               center[0]= 0.5f*(bb->vec[0][0] + bb->vec[4][0]);
+               center[1]= 0.5f*(bb->vec[0][1] + bb->vec[2][1]);
+               center[2]= 0.5f*(bb->vec[0][2] + bb->vec[1][2]);
        }
 }
        
@@ -1636,7 +1641,7 @@ static KX_LightObject *gamelight_from_blamp(Object *ob, Lamp *la, unsigned int l
        KX_LightObject *gamelight;
        
        lightobj.m_att1 = la->att1;
-       lightobj.m_att2 = (la->mode & LA_QUAD)?la->att2:0.0;
+       lightobj.m_att2 = (la->mode & LA_QUAD) ? la->att2 : 0.0f;
        lightobj.m_red = la->r;
        lightobj.m_green = la->g;
        lightobj.m_blue = la->b;
@@ -1836,6 +1841,7 @@ static KX_GameObject *gameobject_from_blenderobject(
        {
                gameobj->SetLayer(ob->lay);
                gameobj->SetBlenderObject(ob);
+               gameobj->SetObjectColor(ob->col);
                /* set the visibility state based on the objects render option in the outliner */
                if(ob->restrictflag & OB_RESTRICT_RENDER) gameobj->SetVisible(0, 0);
        }
@@ -2656,6 +2662,40 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
                                                                                dofbit<<=1;
                                                                        }
                                                                }
+                                                               else if(dat->type == PHY_CONE_TWIST_CONSTRAINT)
+                                                               {
+                                                                       int dof;
+                                                                       int dofbit = 1<<3; // bitflag use_angular_limit_x
+                                                                       
+                                                                       for (dof=3;dof<6;dof++)
+                                                                       {
+                                                                               if(dat->flag & dofbit)
+                                                                               {
+                                                                                       kxscene->GetPhysicsEnvironment()->setConstraintParam(constraintId,dof,dat->minLimit[dof],dat->maxLimit[dof]);
+                                                                               }
+                                                                               else
+                                                                               {
+                                                                                       //maxLimit < 0 means free(disabled limit) for this degree of freedom
+                                                                                       kxscene->GetPhysicsEnvironment()->setConstraintParam(constraintId,dof,1,-1);
+                                                                               }
+                                                                               dofbit<<=1;
+                                                                       }                                                               
+                                                               }
+                                                               else if (dat->type == PHY_LINEHINGE_CONSTRAINT)
+                                                               {
+                                                                       int dof = 3; // dof for angular x
+                                                                       int dofbit = 1<<3; // bitflag use_angular_limit_x
+                                                                       
+                                                                       if (dat->flag & dofbit)
+                                                                       {
+                                                                               kxscene->GetPhysicsEnvironment()->setConstraintParam(constraintId,dof,
+                                                                                               dat->minLimit[dof],dat->maxLimit[dof]);
+                                                                       } else
+                                                                       {
+                                                                               //minLimit > maxLimit means free(disabled limit) for this degree of freedom
+                                                                               kxscene->GetPhysicsEnvironment()->setConstraintParam(constraintId,dof,1,-1);
+                                                                       }
+                                                               }
                                                        }
                                                }
                                        }