contribution from RCRuiz:
authorErwin Coumans <blender@erwincoumans.com>
Sat, 16 Dec 2006 05:50:38 +0000 (05:50 +0000)
committerErwin Coumans <blender@erwincoumans.com>
Sat, 16 Dec 2006 05:50:38 +0000 (05:50 +0000)
drawing of rigidbody constraint pivots, and allow passing of full constraint frame.

18 files changed:
source/blender/blenkernel/bad_level_call_stubs/stubs.c
source/blender/makesdna/DNA_constraint_types.h
source/blender/src/buttons_object.c
source/blender/src/drawobject.c
source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
source/gameengine/Converter/BL_BlenderDataConversion.cpp
source/gameengine/Converter/KX_BlenderSceneConverter.cpp
source/gameengine/Converter/KX_BlenderSceneConverter.h
source/gameengine/Ketsji/KX_BulletPhysicsController.cpp
source/gameengine/Ketsji/KX_ISceneConverter.h
source/gameengine/Ketsji/KX_KetsjiEngine.cpp
source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h
source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.cpp
source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h
source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.cpp
source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.h
source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h

index d112b60ad273b19aa10ebd961e66831ef3f828ed..cf9fc19efbf713b57fa0af6f0322c7118aa1127b 100644 (file)
@@ -296,3 +296,7 @@ void antialias_tagbuf(int xsize, int ysize, char *rectmove) {}
 
 /* imagetexture.c stub */
 void ibuf_sample(struct ImBuf *ibuf, float fx, float fy, float dx, float dy, float *result) {}
+
+void update_for_newframe()
+{
+}
index 3570a0f7375c42bc945bd58be647e0f840d32612..2eb1139dd07d0dbb4c17b61a828ab5d8d5a01eb9 100644 (file)
@@ -324,6 +324,8 @@ typedef struct bRigidBodyJointConstraint{
 
 #define LIMIT_NOPARENT 0x01
 
+#define CONSTRAINT_DRAW_PIVOT 0x40
+
 /* important: these defines need to match up with PHY_DynamicTypes headerfile */
 #define CONSTRAINT_RB_BALL             1
 #define CONSTRAINT_RB_HINGE            2
index 44ae6421a707c677713c13c02b08557123d9f956..a5eb7f02793b790d81dcbd6e717405b66af08745 100644 (file)
@@ -1159,14 +1159,16 @@ static void draw_constraint (uiBlock *block, ListBase *list, bConstraint *con, s
                                {
                                    //uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, "");
                     uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "toObject:", *xco, *yco-50, 130, 18, &data->tar, "Child Object");
+                    uiDefButBitS(block, TOG, CONSTRAINT_DRAW_PIVOT, B_CONSTRAINT_TEST, "ShowPivot", *xco+135, *yco-50, 130, 18, &data->flag, 0, 24, 0, 0, "Show pivot position and rotation");                                 
                     //if (data->tar)
                     //    uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "Child:", *xco+135, *yco-50, 130, 18, &data->child, "Child2 Object (if this exist then this object will be the pivot Only)");
-                    uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Pivot X:", *xco, *yco-75, 130, 18, &data->pivX, -10000, 10000, 100.0, 0.0, "Offset Joint");
-                    uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Pivot Y:", *xco, *yco-100, 130, 18, &data->pivY, -10000, 10000, 100.0, 0.0, "Offset Joint");
-                    uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Pivot Z:", *xco, *yco-125, 130, 18, &data->pivZ, -10000, 10000, 100.0, 0.0, "Offset Joint");
-                    uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Ax X:", *xco+135, *yco-75, 130, 18, &data->axX, -10000, 10000, 100.0, 0.0, "Offset Joint");
-                    uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Ax Y:", *xco+135, *yco-100, 130, 18, &data->axY, -10000, 10000, 100.0, 0.0, "Offset Joint");
-                    uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Ax Z:", *xco+135, *yco-125, 130, 18, &data->axZ, -10000, 10000, 100.0, 0.0, "Offset Joint");
+                    uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Pivot X:", *xco, *yco-75, 130, 18, &data->pivX, -1000, 1000, 0.1, 0.0, "Offset pivot on X");
+                    uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Pivot Y:", *xco, *yco-100, 130, 18, &data->pivY, -1000, 1000, 0.1, 0.0, "Offset pivot on Y");
+                    uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Pivot Z:", *xco, *yco-125, 130, 18, &data->pivZ, -1000, 1000, 0.1, 0.0, "Offset pivot on z");
+                                       
+                    uiDefButF(block, NUM, B_CONSTRAINT_TEST, "AxEX:", *xco+135, *yco-75, 130, 18, &data->axX, -3.141592, 3.141592, 0.1, 0.0, "Rotate pivot on X Axis");
+                    uiDefButF(block, NUM, B_CONSTRAINT_TEST, "AxEY:", *xco+135, *yco-100, 130, 18, &data->axY, -3.141592, 3.141592, 0.1, 0.0, "Rotate pivot on Y Axis");
+                    uiDefButF(block, NUM, B_CONSTRAINT_TEST, "AxEZ:", *xco+135, *yco-125, 130, 18, &data->axZ, -3.141592, 3.141592, 0.1, 0.0, "Rotate pivot on Z Axis");
                                        
                                        if (data->type==CONSTRAINT_RB_GENERIC6DOF){
                                                /* Draw Pairs of LimitToggle+LimitValue */
index ec9962ce69760364fff9bd7ac82f90a83bb1e4b3..5b7a1b7134e2e685bef37c0f73e663ae870527cf 100644 (file)
@@ -3636,6 +3636,51 @@ static void draw_hooks(Object *ob)
        }
 }
 
+//<rcruiz>
+void drawRBpivot(bRigidBodyJointConstraint *data){
+       float size=1.0f;
+       int axis;
+       float v1[3]= {data->pivX, data->pivY, data->pivZ};
+       float eu[3]= {data->axX, data->axY, data->axZ};
+       float mat[4][4];
+       EulToMat4(eu,mat);
+       glLineWidth (4.0f);
+       setlinestyle(2);
+       for (axis=0; axis<3; axis++) {
+                       float dir[3] = {0,0,0};
+                       float v[3]= {data->pivX, data->pivY, data->pivZ};
+                       int arrow_axis= (axis==0)?1:0;
+                       dir[axis] = 1.f;
+                       glBegin(GL_LINES);
+                       Mat4MulVecfl(mat,dir);
+                       v[0] += dir[0];
+                       v[1] += dir[1];
+                       v[2] += dir[2];
+                       glVertex3fv(v1);
+                       glVertex3fv(v);                 
+/*                     v1[axis]= size*0.8;
+                       v1[arrow_axis]= -size*0.125;
+                       glVertex3fv(v1);
+                       glVertex3fv(v2);
+                               
+                       v1[arrow_axis]= size*0.125;
+                       glVertex3fv(v1);
+                       glVertex3fv(v2);
+*/
+                       glEnd();
+                       glRasterPos3fv(v);
+                       if (axis==0)
+                               BMF_DrawString(G.font, "px");
+                       else if (axis==1)
+                               BMF_DrawString(G.font, "py");
+                       else
+                               BMF_DrawString(G.font, "pz");                   
+                                       
+       }
+       glLineWidth (1.0f);
+       setlinestyle(0);
+}
+
 /* flag can be DRAW_PICKING    and/or DRAW_CONSTCOLOR */
 void draw_object(Base *base, int flag)
 {
@@ -4001,6 +4046,18 @@ void draw_object(Base *base, int flag)
        }
        if(ob->pd && ob->pd->forcefield) draw_forcefield(ob);
 
+       {
+               bConstraint *con;
+               for(con=ob->constraints.first; con; con= con->next) 
+               {
+                       if(con->type==CONSTRAINT_TYPE_RIGIDBODYJOINT) 
+                       {
+                               bRigidBodyJointConstraint *data = (bRigidBodyJointConstraint*)con->data;
+                               if(data->flag&CONSTRAINT_DRAW_PIVOT)
+                                       drawRBpivot(data);
+                       }
+               }
+       }
 
        /* draw extra: after normal draw because of makeDispList */
        if(dtx) {
index f37928fe2d51ea8ef428eb256d147e32deafac00..91394c8c21255db9e8e45acecc34f3193c493c0c 100644 (file)
 #include "DNA_scene_types.h"
        /***/
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+#include "BSE_headerbuttons.h"
+void update_for_newframe();
+#ifdef __cplusplus
+}
+#endif
+
 static BlendFileData *load_game_data(char *filename) {
        BlendReadError error;
        //this doesn't work anymore for relative paths, so use BLO_read_from_memory instead
@@ -310,7 +319,7 @@ extern "C" void StartKetsjiShell(struct ScrArea *area,
                        // create a scene converter, create and convert the startingscene
                        KX_ISceneConverter* sceneconverter = new KX_BlenderSceneConverter(blenderdata,sipo, ketsjiengine);
                        ketsjiengine->SetSceneConverter(sceneconverter);
-                       
+                       sceneconverter->addInitFromFrame=false;
                        if (always_use_expand_framing)
                                sceneconverter->SetAlwaysUseExpandFraming(true);
                        
@@ -452,14 +461,6 @@ extern "C" void StartKetsjiShell(struct ScrArea *area,
 
        if (bfd) BLO_blendfiledata_free(bfd);
 }
-#ifdef __cplusplus
-extern "C" {
-#endif
-#include "BSE_headerbuttons.h"
-void update_for_newframe();
-#ifdef __cplusplus
-}
-#endif
 
 extern "C" void StartKetsjiShellSimulation(struct ScrArea *area,
                                                                 char* scenename,
@@ -481,7 +482,6 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area,
 
        do
        {
-//             View3D *v3d= (View3D*) area->spacedata.first;
 
                // get some preferences
                SYS_SystemHandle syshandle = SYS_GetSystem();
@@ -493,19 +493,6 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area,
                bool displaylists = (SYS_GetCommandLineInt(syshandle, "displaylists", 0) != 0);
                bool usemat = false;
 
-/*             #ifdef GL_ARB_multitexture
-               if(bgl::RAS_EXT_support._ARB_multitexture && bgl::QueryVersion(1, 1)) {
-                       usemat = (SYS_GetCommandLineInt(syshandle, "blender_material", 0) != 0);
-                       int unitmax=0;
-                       glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, (GLint*)&unitmax);
-                       bgl::max_texture_units = MAXTEX>unitmax?unitmax:MAXTEX;
-                       //std::cout << "using(" << bgl::max_texture_units << ") of(" << unitmax << ") texture units." << std::endl;
-               } else {
-                       bgl::max_texture_units = 0;
-               }
-               #endif
-
-*/
                // create the canvas, rasterizer and rendertools
                RAS_ICanvas* canvas = new KX_BlenderCanvas(area);
                //canvas->SetMouseState(RAS_ICanvas::MOUSE_INVISIBLE);
@@ -544,83 +531,8 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area,
                // create the ketsjiengine
                KX_KetsjiEngine* ketsjiengine = new KX_KetsjiEngine(kxsystem);
 
-/*             // set the devices
-               ketsjiengine->SetKeyboardDevice(keyboarddevice);
-               ketsjiengine->SetMouseDevice(mousedevice);
-               ketsjiengine->SetNetworkDevice(networkdevice);
-               ketsjiengine->SetCanvas(canvas);
-               ketsjiengine->SetRenderTools(rendertools);
-               ketsjiengine->SetRasterizer(rasterizer);
-               ketsjiengine->SetNetworkDevice(networkdevice);
-               ketsjiengine->SetAudioDevice(audiodevice);
-               ketsjiengine->SetUseFixedTime(usefixed);
-               ketsjiengine->SetTimingDisplay(frameRate, profile, properties);
-
-*/
-
-               // some blender stuff
-               MT_CmMatrix4x4 projmat;
-               MT_CmMatrix4x4 viewmat;
                int i;
 
-/*             for (i = 0; i < 16; i++)
-               {
-                       float *viewmat_linear= (float*) v3d->viewmat;
-                       viewmat.setElem(i, viewmat_linear[i]);
-               }
-               for (i = 0; i < 16; i++)
-               {
-                       float *projmat_linear = (float*) area->winmat;
-                       projmat.setElem(i, projmat_linear[i]);
-               }
-*/
-/*             float camzoom = (1.41421 + (v3d->camzoom / 50.0));
-               camzoom *= camzoom;
-               camzoom = 4.0 / camzoom;
-*/
-//             ketsjiengine->SetDrawType(v3d->drawtype);
-//             ketsjiengine->SetCameraZoom(camzoom);
-/*
-               // if we got an exitcode 3 (KX_EXIT_REQUEST_START_OTHER_GAME) load a different file
-               if (exitrequested == KX_EXIT_REQUEST_START_OTHER_GAME || exitrequested == KX_EXIT_REQUEST_RESTART_GAME)
-               {
-                       exitrequested = KX_EXIT_REQUEST_NO_REQUEST;
-                       if (bfd) BLO_blendfiledata_free(bfd);
-
-                       char basedpath[160];
-                       // base the actuator filename with respect
-                       // to the original file working directory
-                       if (exitstring != "")
-                               strcpy(basedpath, exitstring.Ptr());
-
-                       BLI_convertstringcode(basedpath, pathname, 0);
-                       bfd = load_game_data(basedpath);
-
-                       // if it wasn't loaded, try it forced relative
-                       if (!bfd)
-                       {
-                               // just add "//" in front of it
-                               char temppath[162];
-                               strcpy(temppath, "//");
-                               strcat(temppath, basedpath);
-
-                               BLI_convertstringcode(temppath, pathname, 0);
-                               bfd = load_game_data(temppath);
-                       }
-
-                       // if we got a loaded blendfile, proceed
-                       if (bfd)
-                       {
-                               blenderdata = bfd->main;
-                               startscenename = bfd->curscene->id.name + 2;
-                       }
-                       // else forget it, we can't find it
-                       else
-                       {
-                               exitrequested = KX_EXIT_REQUEST_QUIT_GAME;
-                       }
-               }
-*/
                Scene *blscene = NULL;
                if (!bfd)
                {
@@ -652,18 +564,11 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area,
 
                if (exitrequested != KX_EXIT_REQUEST_QUIT_GAME)
                {
-                       /*if (v3d->persp != 2)
-                       {
-                               ketsjiengine->EnableCameraOverride(startscenename);
-                               ketsjiengine->SetCameraOverrideUseOrtho((v3d->persp == 0));
-                               ketsjiengine->SetCameraOverrideProjectionMatrix(projmat);
-                               ketsjiengine->SetCameraOverrideViewMatrix(viewmat);
-                       }*/
-
                        // create a scene converter, create and convert the startingscene
                        KX_ISceneConverter* sceneconverter = new KX_BlenderSceneConverter(maggie,sipo, ketsjiengine);
                        ketsjiengine->SetSceneConverter(sceneconverter);
-
+                       sceneconverter->addInitFromFrame=true;
+                       
                        if (always_use_expand_framing)
                                sceneconverter->SetAlwaysUseExpandFraming(true);
 
@@ -675,7 +580,6 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area,
                                networkdevice,
                                audiodevice,
                                startscenename);
-
                        // some python things
                        PyObject* dictionaryobject = initGamePythonScripting("Ketsji", psl_Lowest);
                        ketsjiengine->SetPythonDictionary(dictionaryobject);
@@ -696,9 +600,6 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area,
                                        canvas);
                                ketsjiengine->AddScene(startscene);
 
-                               // init the rasterizer
-                               //rasterizer->Init();
-
                                // start the engine
                                ketsjiengine->StartEngine(false);
 
@@ -708,38 +609,22 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area,
                     printf("frame %i\n",blscene->r.cfra);
                     // first check if we want to exit
                                        exitrequested = ketsjiengine->GetExitCode();
-
+                                       /*for (int ix=0;i<geobjs->GetCount();ix++){
+                                               KX_GameObject* gameobj = (KX_GameObject*) geobjs->GetValue(ix);
+                                               if (!gameobj->IsDynamic()){
+                                                       //gameobj->UpdateNonDynas();//UpdateIPO((float)blscene->r.cfra,true, true, true);
+                                                       struct Object* blenderobject = sceneconverter->FindBlenderObject(gameobj);
+                                               }
+                                       }*/
+       
+       
                                        // kick the engine
                                        ketsjiengine->NextFrame();
                                    blscene->r.cfra=blscene->r.cfra+1;
                                    update_for_newframe();
-                                       // render the frame
-                                       //ketsjiengine->Render();
-
-                                       // test for the ESC key
-                                       /*while (qtest())
-                                       {
-                                               short val;
-                                               unsigned short event = extern_qread(&val);
-
-                                               if (keyboarddevice->ConvertBlenderEvent(event,val))
-                                                       exitrequested = KX_EXIT_REQUEST_BLENDER_ESC;
-
-                                               if (event==MOUSEX) {
-                                                       val = val - scrarea_get_win_x(area);
-                                               } else if (event==MOUSEY) {
-                                                       val = scrarea_get_win_height(area) - (val - scrarea_get_win_y(area)) - 1;
-                                               }
-
-                                               mousedevice->ConvertBlenderEvent(event,val);
-                                       }*/
+                                       
                                }
                                exitstring = ketsjiengine->GetExitString();
-                               // when exiting the mainloop
-                               //dictionaryClearByHand(gameLogic);
-                               //ketsjiengine->StopEngine();
-                               //exitGamePythonScripting();
-                               //networkdevice->Disconnect();
                        }
                        if (sceneconverter)
                        {
@@ -778,21 +663,6 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area,
                        delete mousedevice;
                        mousedevice = NULL;
                }
-               /*if (rasterizer)
-               {
-                       delete rasterizer;
-                       rasterizer = NULL;
-               }
-               if (rendertools)
-               {
-                       delete rendertools;
-                       rendertools = NULL;
-               }
-               if (canvas)
-               {
-                       delete canvas;
-                       canvas = NULL;
-               }*/
                SND_DeviceManager::Unsubscribe();
 
        } while (exitrequested == KX_EXIT_REQUEST_RESTART_GAME || exitrequested == KX_EXIT_REQUEST_START_OTHER_GAME);
index a496c60639f7965709da86ec1c4e1fe7ed035d4d..8f4f692eab4f3cf39fc16f54822bb8e68b50d82b 100644 (file)
 #include "BL_ArmatureObject.h"
 #include "BL_DeformableGameObject.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+#include "BSE_headerbuttons.h"
+void update_for_newframe();
+//void scene_update_for_newframe(struct Scene *sce, unsigned int lay);
+//#include "BKE_ipo.h"
+//void do_all_data_ipos(void);
+#ifdef __cplusplus
+}
+#endif
+
 static int default_face_mode = TF_DYNAMIC;
 
 static unsigned int KX_rgbaint2uint_new(unsigned int icol)
@@ -1618,7 +1630,7 @@ KX_GameObject* getGameOb(STR_String busc,CListValue* sumolist){
        return 0;
 
 }
-
+#include "BLI_arithb.h"
 // convert blender objects into ketsji gameobjects
 void BL_ConvertBlenderObjects(struct Main* maggie,
                                                          const STR_String& scenename,
@@ -1642,6 +1654,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
        RAS_FrameSettings::RAS_FrameType frame_type;
        int aspect_width;
        int aspect_height;
+       vector<MT_Vector3> inivel,iniang;
        
        if (alwaysUseExpandFraming) {
                frame_type = RAS_FrameSettings::e_frame_extend;
@@ -1720,6 +1733,10 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
                                                                                        
                if (gameobj)
                {
+                       MT_Point3 posPrev;                      
+                       MT_Matrix3x3 angor;                     
+                       if (converter->addInitFromFrame) blenderscene->r.cfra=blenderscene->r.sfra;
+                       
                        MT_Point3 pos = MT_Point3(
                                blenderobject->loc[0]+blenderobject->dloc[0],
                                blenderobject->loc[1]+blenderobject->dloc[1],
@@ -1735,7 +1752,26 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
                                blenderobject->size[1],
                                blenderobject->size[2]
                        );
-                       
+                       if (converter->addInitFromFrame){//rcruiz
+                               float eulxyzPrev[3];
+                               blenderscene->r.cfra=blenderscene->r.sfra-1;
+                               update_for_newframe();
+                               MT_Vector3 tmp=pos-MT_Point3(blenderobject->loc[0]+blenderobject->dloc[0],
+                                                                                       blenderobject->loc[1]+blenderobject->dloc[1],
+                                                                                       blenderobject->loc[2]+blenderobject->dloc[2]
+                                                                       );
+                               eulxyzPrev[0]=blenderobject->rot[0];
+                               eulxyzPrev[1]=blenderobject->rot[1];
+                               eulxyzPrev[2]=blenderobject->rot[2];
+                               tmp.scale((float)blenderscene->r.frs_sec,(float)blenderscene->r.frs_sec,(float)blenderscene->r.frs_sec);
+                               inivel.push_back(tmp);
+                               tmp=eulxyz-eulxyzPrev;
+                               tmp.scale((float)blenderscene->r.frs_sec,(float)blenderscene->r.frs_sec,(float)blenderscene->r.frs_sec);
+                               iniang.push_back(tmp);
+                               blenderscene->r.cfra=blenderscene->r.sfra;
+                               update_for_newframe();
+                       }               
+                                               
                        gameobj->NodeSetLocalPosition(pos);
                        gameobj->NodeSetLocalOrientation(MT_Matrix3x3(eulxyz));
                        gameobj->NodeSetLocalScale(scale);
@@ -1759,7 +1795,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
                        templist->Add(gameobj->AddRef());
                        
                        // update children/parent hierarchy
-                       if (blenderobject->parent != 0)
+                       if ((blenderobject->parent != 0)&&(!converter->addInitFromFrame))
                        {
                                // blender has an additional 'parentinverse' offset in each object
                                SG_Node* parentinversenode = new SG_Node(NULL,NULL,SG_Callbacks());
@@ -1790,12 +1826,15 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
                                logicmgr->RegisterGameMeshName(gameobj->GetMesh(i)->GetName(), blenderobject);
        
                        converter->RegisterGameObject(gameobj, blenderobject);  
-                       
                        // this was put in rapidly, needs to be looked at more closely
                        // only draw/use objects in active 'blender' layers
        
                        logicbrick_conversionlist->Add(gameobj->AddRef());
                        
+                       if (converter->addInitFromFrame){
+                               posPrev=gameobj->NodeGetWorldPosition();
+                               angor=gameobj->NodeGetWorldOrientation();
+                       }
                        if (isInActiveLayer)
                        {
                                objectlist->Add(gameobj->AddRef());
@@ -1805,7 +1844,11 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
                                gameobj->Bucketize();
                                
                        }
-                       
+                       if (converter->addInitFromFrame){
+                               gameobj->NodeSetLocalPosition(posPrev);
+                               gameobj->NodeSetLocalOrientation(angor);
+                       }
+                                               
                }
                        
                base = base->next;
@@ -1928,6 +1971,20 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
                }
                BL_CreatePhysicsObjectNew(gameobj,blenderobject,meshobj,kxscene,activeLayerBitInfo,physics_engine,converter,processCompoundChildren);
        }
+       
+       
+       //set ini linearVel and int angularVel //rcruiz
+       if (converter->addInitFromFrame)
+               for (i=0;i<sumolist->GetCount();i++)
+               {
+                       KX_GameObject* gameobj = (KX_GameObject*) sumolist->GetValue(i);
+                       if (gameobj->IsDynamic()){
+                               gameobj->setLinearVelocity(inivel[i],false);
+                               gameobj->setAngularVelocity(iniang[i],false);
+                       }
+               
+               
+               }       
 
                // create physics joints
        for (i=0;i<sumolist->GetCount();i++)
@@ -1956,8 +2013,19 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
                                                        if (gameobj->GetPhysicsController())
                                                        {
                                                                PHY_IPhysicsController* physctrl = (PHY_IPhysicsController*) gameobj->GetPhysicsController()->GetUserData();
+                                                               //we need to pass a full constraint frame, not just axis
                                    
-                                                               int constraintId = kxscene->GetPhysicsEnvironment()->createConstraint(physctrl,physctr2,(PHY_ConstraintType)dat->type,(float)dat->pivX,(float)dat->pivY,(float)dat->pivZ,(float)dat->axX,(float)dat->axY,(float)dat->axZ);
+                                                               //localConstraintFrameBasis
+                                                               MT_Matrix3x3 localCFrame(MT_Vector3(dat->axX,dat->axY,dat->axZ));
+                                                               MT_Vector3 axis0 = localCFrame.getColumn(0);
+                                                               MT_Vector3 axis1 = localCFrame.getColumn(1);
+                                                               MT_Vector3 axis2 = localCFrame.getColumn(2);
+                                                               
+                                                               int constraintId = kxscene->GetPhysicsEnvironment()->createConstraint(physctrl,physctr2,(PHY_ConstraintType)dat->type,(float)dat->pivX,(float)dat->pivY,(float)dat->pivZ,
+                                                               (float)axis0.x(),(float)axis0.y(),(float)axis0.z(),
+                                                               (float)axis1.x(),(float)axis1.y(),(float)axis1.z(),
+                                                               (float)axis2.x(),(float)axis2.y(),(float)axis2.z()
+                                                                                       );
                                                                //if it is a generic 6DOF constraint, set all the limits accordingly
                                                                if (dat->type == PHY_GENERIC_6DOF_CONSTRAINT)
                                                                {
@@ -1984,40 +2052,9 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
 
        }
 
-    //Intento de actualizar posicion
-       /*for (i=0;i<sumolist->GetCount();i++)
-       {
-               KX_GameObject* gameobj = (KX_GameObject*) sumolist->GetValue(i);
-               struct Object* blenderobject = converter->FindBlenderObject(gameobj);
-
-               MT_Point3 pos = MT_Point3(
-                               blenderobject->loc[0]+blenderobject->dloc[0],
-                               blenderobject->loc[1]+blenderobject->dloc[1],
-                               blenderobject->loc[2]+blenderobject->dloc[2]
-                       );
-               MT_Vector3 eulxyz = MT_Vector3(
-                               blenderobject->rot[0],
-                               blenderobject->rot[1],
-                               blenderobject->rot[2]
-                       );
-               MT_Vector3 scale = MT_Vector3(
-                               blenderobject->size[0],
-                               blenderobject->size[1],
-                               blenderobject->size[2]
-                       );
-
-               gameobj->NodeSetLocalPosition(pos);
-               gameobj->NodeSetLocalOrientation(MT_Matrix3x3(eulxyz));
-               gameobj->NodeSetLocalScale(scale);
-               gameobj->NodeUpdateGS(0,true);
-       }*/
-    //rcruiz>
-
-       
        templist->Release();
        sumolist->Release();    
 
-
        int executePriority=0; /* incremented by converter routines */
        
        // convert global sound stuff
index 10f3ea3961665e09e830e8190c3275cad69cb95b..75c0e54eb68c8ca9cf9cc5b3222b689e46536bb2 100644 (file)
@@ -77,6 +77,8 @@
 #include "DNA_world_types.h"
 #include "BKE_main.h"
 
+#include "BLI_arithb.h"
+
 extern "C"
 {
 #include "DNA_object_types.h"
@@ -560,7 +562,8 @@ IpoCurve* findIpoCurve(IpoCurve* first,char* searchName)
        return 0;
 }
 
-Ipo* KX_BlenderSceneConverter::findIpoForName(char* objName)
+// this is not longer necesary //rcruiz
+/*Ipo* KX_BlenderSceneConverter::findIpoForName(char* objName)
 {
        Ipo* ipo_iter = (Ipo*)m_maggie->ipo.first;
 
@@ -574,7 +577,7 @@ Ipo* KX_BlenderSceneConverter::findIpoForName(char* objName)
        }
        return 0;
 }
-
+*/
 
 void   KX_BlenderSceneConverter::ResetPhysicsObjectsAnimationIpo(bool clearIpo)
 {
@@ -600,29 +603,35 @@ void      KX_BlenderSceneConverter::ResetPhysicsObjectsAnimationIpo(bool clearIpo)
                                if (blenderObject)
                                {
                                        //erase existing ipo's
-                                       Ipo* ipo = findIpoForName(blenderObject->id.name+2);
+                                       Ipo* ipo = blenderObject->ipo;//findIpoForName(blenderObject->id.name+2);
                                        if (ipo)
-                                       {
-                                               //clear the curve data
-                                               if (clearIpo){
-                                               IpoCurve *icu1;
-                                               int numCurves = 0;
-                                               for( icu1 = (IpoCurve*)ipo->curve.first; icu1;  ) {
+                                       {       //clear the curve data
+                                               if (clearIpo){//rcruiz
+                                                       IpoCurve *icu1;
+                                                                                                               
+                                                       int numCurves = 0;
+                                                       for( icu1 = (IpoCurve*)ipo->curve.first; icu1;  ) {
                                                        
-                                                       IpoCurve* tmpicu = icu1;
-                                                       icu1 = icu1->next;
-                                                       numCurves++;
+                                                               IpoCurve* tmpicu = icu1;
+                                                               
+                                                               /*int i;
+                                                               BezTriple *bezt;
+                                                               for( bezt = tmpicu->bezt, i = 0;        i < tmpicu->totvert; i++, bezt++){
+                                                                       printf("(%f,%f,%f),(%f,%f,%f),(%f,%f,%f)\n",bezt->vec[0][0],bezt->vec[0][1],bezt->vec[0][2],bezt->vec[1][0],bezt->vec[1][1],bezt->vec[1][2],bezt->vec[2][0],bezt->vec[2][1],bezt->vec[2][2]);
+                                                               }*/
+                                                               
+                                                               icu1 = icu1->next;
+                                                               numCurves++;
                        
-                                                       BLI_remlink( &( blenderObject->ipo->curve ), tmpicu );
-                                                       if( tmpicu->bezt )
-                                                               MEM_freeN( tmpicu->bezt );
-                                                       MEM_freeN( tmpicu );
-                                                       localDel_ipoCurve( tmpicu ,m_sipo);
-                                               }
-                                         }
+                                                               BLI_remlink( &( blenderObject->ipo->curve ), tmpicu );
+                                                               if( tmpicu->bezt )
+                                                                       MEM_freeN( tmpicu->bezt );
+                                                               MEM_freeN( tmpicu );
+                                                               localDel_ipoCurve( tmpicu ,m_sipo);
+                                                       }
+                                               }
                                        } else
-                                       {
-                                               ipo = add_ipo(blenderObject->id.name+2, ID_OB);
+                                       {       ipo = add_ipo(blenderObject->id.name+2, ID_OB);
                                                blenderObject->ipo = ipo;
 
                                        }
@@ -643,6 +652,48 @@ void       KX_BlenderSceneConverter::ResetPhysicsObjectsAnimationIpo(bool clearIpo)
 
 }
 
+void   KX_BlenderSceneConverter::resetNoneDynamicObjectToIpo(){
+       
+       if (addInitFromFrame){          
+               KX_SceneList* scenes = m_ketsjiEngine->CurrentScenes();
+               int numScenes = scenes->size();
+               if (numScenes>=0){
+                       KX_Scene* scene = scenes->at(0);
+                       CListValue* parentList = scene->GetRootParentList();
+                       for (int ix=0;ix<parentList->GetCount();ix++){
+                               KX_GameObject* gameobj = (KX_GameObject*)parentList->GetValue(ix);
+                               if (!gameobj->IsDynamic()){
+                                       Object* blenderobject = FindBlenderObject(gameobj);
+                                       if (!blenderobject)
+                                               continue;
+                                       if (blenderobject->type==OB_ARMATURE)
+                                               continue;
+                                       float eu[3];
+                                       Mat4ToEul(blenderobject->obmat,eu);                                     
+                                       MT_Point3 pos = MT_Point3(
+                                               blenderobject->obmat[3][0],
+                                               blenderobject->obmat[3][1],
+                                               blenderobject->obmat[3][2]
+                                       );
+                                       MT_Vector3 eulxyz = MT_Vector3(
+                                               eu[0],
+                                               eu[1],
+                                               eu[2]
+                                       );
+                                       MT_Vector3 scale = MT_Vector3(
+                                               blenderobject->size[0],
+                                               blenderobject->size[1],
+                                               blenderobject->size[2]
+                                       );
+                                       gameobj->NodeSetLocalPosition(pos);
+                                       gameobj->NodeSetLocalOrientation(MT_Matrix3x3(eulxyz));
+                                       gameobj->NodeSetLocalScale(scale);
+                                       gameobj->NodeUpdateGS(0,true);
+                               }
+                       }
+               }
+       }
+}
 
 #define TEST_HANDLES_GAME2IPO 0
 
@@ -797,9 +848,8 @@ void        KX_BlenderSceneConverter::WritePhysicsObjectToAnimationIpo(int frameNumber)
                }
                
        
-       }
-
-
+       }       
+       
 
 }
 
index c4447c539307fd5a7a68363e8367b2e45a79bd97..a897922d51b7898c7f2f59c0a9f002fe59986fba 100644 (file)
@@ -76,7 +76,7 @@ class KX_BlenderSceneConverter : public KX_ISceneConverter
        bool                                    m_usemat;
 
        void localDel_ipoCurve ( IpoCurve * icu ,struct SpaceIpo*       sipo);
-       struct Ipo* findIpoForName(char* objName);
+//     struct Ipo* findIpoForName(char* objName);
 
 public:
        KX_BlenderSceneConverter(
@@ -132,6 +132,9 @@ public:
 
        virtual void    ResetPhysicsObjectsAnimationIpo(bool clearIpo);
 
+       ///this is for reseting the position,rotation and scale of the gameobjet that is not dynamic
+       virtual void    resetNoneDynamicObjectToIpo();
+       
        ///this generates ipo curves for position, rotation, allowing to use game physics in animation
        virtual void    WritePhysicsObjectToAnimationIpo(int frameNumber);
        virtual void    TestHandlesPhysicsObjectToAnimationIpo();
index 6785cb957bc9f8762dbb459a25eb0269acaf9800..aa5d1f1cec1492c9b47238333d59c32bd4fce32a 100644 (file)
@@ -86,7 +86,8 @@ void  KX_BulletPhysicsController::ApplyForce(const MT_Vector3& force,bool local)
 MT_Vector3 KX_BulletPhysicsController::GetLinearVelocity()
 {
        float angVel[3];
-       CcdPhysicsController::GetAngularVelocity(angVel[0],angVel[1],angVel[2]);
+       //CcdPhysicsController::GetAngularVelocity(angVel[0],angVel[1],angVel[2]);
+       CcdPhysicsController::GetLinearVelocity(angVel[0],angVel[1],angVel[2]);//rcruiz
        return MT_Vector3(angVel[0],angVel[1],angVel[2]);
 }
 MT_Vector3 KX_BulletPhysicsController::GetVelocity(const MT_Point3& pos)
index 8693eb34d6bf94278e79412a4e77090896760fa4..2727ce7746e9f089780fe8410b9b64eef8910a32 100644 (file)
@@ -59,14 +59,18 @@ public:
 
        virtual void    SetNewFileName(const STR_String& filename) = 0;
        virtual bool    TryAndLoadNewFile() = 0;
-
+       bool    addInitFromFrame;//rcruiz
 
        virtual void    ResetPhysicsObjectsAnimationIpo(bool clearIpo) = 0;
 
+       
        ///this generates ipo curves for position, rotation, allowing to use game physics in animation
        virtual void    WritePhysicsObjectToAnimationIpo(int frameNumber) = 0;
        virtual void    TestHandlesPhysicsObjectToAnimationIpo() = 0;
 
+       ///this is for reseting the position,rotation and scale of the gameobjet that is not dynamic
+       virtual void    resetNoneDynamicObjectToIpo()=0;
+
        // use blender materials
        virtual void SetMaterials(bool val) =0;
        virtual bool GetMaterials()=0;
index 2e0c5d713dc40665b5539c56925d6e2601917c57..e76e28bcb7b98baf342cfaefc389374231c9f483 100644 (file)
@@ -394,6 +394,9 @@ else
                        * the settings for that preceed the logic and physics
                        * update. */
                        m_logger->StartLog(tc_logic, m_kxsystem->GetTimeInSeconds(), true);
+
+                       m_sceneconverter->resetNoneDynamicObjectToIpo();//this is for none dynamic objects with ipo
+
                        scene->UpdateObjectActivity();
        
                        if (!scene->IsSuspended())
@@ -456,7 +459,7 @@ else
                        
                        
                                if (m_game2ipo)
-                               {
+                               {                                       
                                        m_sceneconverter->WritePhysicsObjectToAnimationIpo(++m_currentFrame);
                                }
 
index edd4c2e2bb4a5912e482cc4a4f4ee7b4461ad985..57fe533825e369b9a273e826497f649bc86d6ce9 100644 (file)
@@ -1002,7 +1002,10 @@ PHY_IPhysicsController*  CcdPhysicsEnvironment::CreateSphereController(float radi
 
 int                    CcdPhysicsEnvironment::createConstraint(class PHY_IPhysicsController* ctrl0,class PHY_IPhysicsController* ctrl1,PHY_ConstraintType type,
                                                                                                        float pivotX,float pivotY,float pivotZ,
-                                                                                                       float axisX,float axisY,float axisZ)
+                                                                                                       float axisX,float axisY,float axisZ,
+                                                                                                       float axis1X,float axis1Y,float axis1Z,
+                                                                                                       float axis2X,float axis2Y,float axis2Z
+                                                                                                       )
 {
 
 
@@ -1066,9 +1069,12 @@ int                      CcdPhysicsEnvironment::createConstraint(class PHY_IPhysicsController* ctrl
                                btTransform frameInA;
                                btTransform frameInB;
                                
-                               btVector3 axis1, axis2;
-                               btPlaneSpace1( axisInA, axis1, axis2 );
-
+                               btVector3 axis1(axis1X,axis1Y,axis1Z), axis2(axis2X,axis2Y,axis2Z);
+                               if (axis1.length() == 0.0)
+                               {
+                                       btPlaneSpace1( axisInA, axis1, axis2 );
+                               }
+                               
                                frameInA.getBasis().setValue( axisInA.x(), axis1.x(), axis2.x(),
                                                                  axisInA.y(), axis1.y(), axis2.y(),
                                                                                          axisInA.z(), axis1.z(), axis2.z() );
index 9a8fc3f435d7d5536f01f86bb61f3b63e41f61c8..66a6ed59c17cb436274c736befd6e8db64e7c8ae 100644 (file)
@@ -117,7 +117,10 @@ protected:
 
                virtual int                     createConstraint(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsController* ctrl2,PHY_ConstraintType type,
                        float pivotX,float pivotY,float pivotZ,
-                       float axisX,float axisY,float axisZ);
+                       float axisX,float axisY,float axisZ,
+                       float axis1X=0,float axis1Y=0,float axis1Z=0,
+                       float axis2X=0,float axis2Y=0,float axis2Z=0
+                       );
 
 
                //Following the COLLADA physics specification for constraints
index 0532a9a8cf75251ccf36cef0863d6fdf22c1b79b..b40d1b430bb859194ee21515ffc2f32726d7c647 100644 (file)
@@ -93,7 +93,11 @@ void DummyPhysicsEnvironment::setGravity(float x,float y,float z)
 
 
 int                    DummyPhysicsEnvironment::createConstraint(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsController* ctrl2,PHY_ConstraintType type,
-               float pivotX,float pivotY,float pivotZ,float axisX,float axisY,float axisZ)
+               float pivotX,float pivotY,float pivotZ,float axisX,float axisY,float axisZ,
+                       float axis1X,float axis1Y,float axis1Z,
+                       float axis2X,float axis2Y,float axis2Z
+
+               )
 {
        
        int constraintid = 0;
index bd4e00e9fa5630acc8790cc0be0fb9b996e81f6c..4fc970da69967e90a154ff43c251a518a5fe31f0 100644 (file)
@@ -59,7 +59,10 @@ public:
 
        virtual int                     createConstraint(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsController* ctrl2,PHY_ConstraintType type,
                        float pivotX,float pivotY,float pivotZ,
-                       float axisX,float axisY,float axisZ);
+                       float axisX,float axisY,float axisZ,
+                       float axis1X=0,float axis1Y=0,float axis1Z=0,
+                       float axis2X=0,float axis2Y=0,float axis2Z=0
+                       );
 
        virtual void            removeConstraint(int    constraintid);
 
index ead6dcc010671b190d7310bb5803d766b318533d..6cdf1d41dc1acffd8031b0e2f72b8e60d13e1df6 100644 (file)
@@ -111,7 +111,11 @@ int SumoPhysicsEnvironment::createConstraint(
        class PHY_IPhysicsController* ctrl2,
        PHY_ConstraintType type,
        float pivotX,float pivotY,float pivotZ,
-       float axisX,float axisY,float axisZ)
+       float axisX,float axisY,float axisZ,
+       float axis1X,float axis1Y,float axis1Z,
+       float axis2X,float axis2Y,float axis2Z
+
+       )
 {
        int constraintid = 0;
        return constraintid;
index 1afb94335008a74c0d5defe9e34c9986c565fe6c..4d17d0c21fd9f5a2a34809f9b499b2182a2409a4 100644 (file)
@@ -64,7 +64,11 @@ public:
        virtual void            setGravity(float x,float y,float z);
        virtual int             createConstraint(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsController* ctrl2,PHY_ConstraintType type,
                        float pivotX,float pivotY,float pivotZ,
-                       float axisX,float axisY,float axisZ);
+                       float axisX,float axisY,float axisZ,
+                       float axis1X=0,float axis1Y=0,float axis1Z=0,
+                       float axis2X=0,float axis2Y=0,float axis2Z=0
+
+                       );
 
        virtual void            removeConstraint(int    constraintid);
 
index 2716baa0d6ded5b42fa9a73b14fee0d15885960f..5e4fd681914a908c027ea997b0dadeda6cd72ceb 100644 (file)
@@ -86,7 +86,10 @@ class PHY_IPhysicsEnvironment
 
                virtual int                     createConstraint(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsController* ctrl2,PHY_ConstraintType type,
                        float pivotX,float pivotY,float pivotZ,
-                       float axisX,float axisY,float axisZ)=0;
+                       float axis0X,float axis0Y,float axis0Z,
+                       float axis1X=0,float axis1Y=0,float axis1Z=0,
+                       float axis2X=0,float axis2Y=0,float axis2Z=0
+               )=0;
                virtual void            removeConstraint(int    constraintid)=0;
                virtual float           getAppliedImpulse(int   constraintid){ return 0.f;}