svn merge ^/trunk/blender -r42742:42757
authorCampbell Barton <ideasman42@gmail.com>
Tue, 20 Dec 2011 08:09:46 +0000 (08:09 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 20 Dec 2011 08:09:46 +0000 (08:09 +0000)
38 files changed:
release/scripts/startup/bl_operators/wm.py
release/scripts/startup/bl_ui/properties_game.py
release/scripts/startup/bl_ui/properties_particle.py
release/scripts/startup/bl_ui/properties_render.py
release/scripts/startup/bl_ui/properties_scene.py
release/scripts/startup/bl_ui/space_logic.py
source/blender/blenkernel/intern/DerivedMesh.c
source/blender/blenlib/BLI_dynstr.h
source/blender/blenlib/intern/BLI_dynstr.c
source/blender/blenloader/intern/readfile.c
source/blender/editors/screen/screen_ops.c
source/blender/editors/sculpt_paint/paint_ops.c
source/blender/makesdna/DNA_scene_types.h
source/blender/makesrna/intern/rna_scene.c
source/blender/python/intern/bpy_rna.c
source/blender/python/mathutils/mathutils.c
source/blender/python/mathutils/mathutils.h
source/blender/python/mathutils/mathutils_Color.c
source/blender/python/mathutils/mathutils_Euler.c
source/blender/python/mathutils/mathutils_Matrix.c
source/blender/python/mathutils/mathutils_Matrix.h
source/blender/python/mathutils/mathutils_Quaternion.c
source/blender/python/mathutils/mathutils_Vector.c
source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
source/gameengine/BlenderRoutines/KX_BlenderInputDevice.h
source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.cpp
source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.h
source/gameengine/Converter/BL_BlenderDataConversion.cpp
source/gameengine/Converter/BL_BlenderDataConversion.h
source/gameengine/Converter/KX_ConvertSensors.cpp
source/gameengine/GamePlayer/common/GPC_KeyboardDevice.h
source/gameengine/GamePlayer/ghost/GPG_Application.cpp
source/gameengine/GamePlayer/ghost/GPG_Application.h
source/gameengine/Ketsji/KX_KetsjiEngine.cpp
source/gameengine/Ketsji/KX_KetsjiEngine.h
source/gameengine/Ketsji/KX_PythonInit.cpp
source/tests/CMakeLists.txt
source/tests/bl_pyapi_mathutils.py [new file with mode: 0644]

index 1da5e2ca381867435b91d427475d8ba66e620040..58941e00914177fca85aa8b2cd7988e98191b594 100644 (file)
@@ -29,6 +29,8 @@ from bpy.props import (StringProperty,
 
 from rna_prop_ui import rna_idprop_ui_prop_get, rna_idprop_ui_prop_clear
 
+import subprocess
+import os
 
 class MESH_OT_delete_edgeloop(Operator):
     '''Delete an edge loop by merging the faces on each side to a single face loop'''
@@ -1175,6 +1177,26 @@ class WM_OT_copy_prev_settings(Operator):
 
         return {'CANCELLED'}
 
+class WM_OT_blenderplayer_start(bpy.types.Operator):
+    '''Launches the Blenderplayer with the current blendfile'''
+    bl_idname = "wm.blenderplayer_start"
+    bl_label = "Start"
+    
+    blender_bin_path = bpy.app.binary_path
+    blender_bin_dir = os.path.dirname(blender_bin_path)
+    ext = os.path.splitext(blender_bin_path)[-1]
+    player_path = os.path.join(blender_bin_dir, 'blenderplayer' + ext)
+    
+    def execute(self, context):
+        import sys
+
+        if sys.platform == 'darwin':
+            self.player_path = os.path.join(self.blender_bin_dir, '../../../blenderplayer.app/Contents/MacOS/blenderplayer')
+       
+        filepath = bpy.app.tempdir + "game.blend"
+        bpy.ops.wm.save_as_mainfile(filepath=filepath, check_existing=False, copy=True)
+        subprocess.call([self.player_path, filepath])
+        return {'FINISHED'}
 
 class WM_OT_keyconfig_test(Operator):
     "Test keyconfig for conflicts"
index db65b0ff669cb800dced57aeddae3e386a0ac81a..66b8cca786671484255e306a24a3acaa94083ea9 100644 (file)
@@ -244,16 +244,22 @@ class RenderButtonsPanel():
         return (rd.engine in cls.COMPAT_ENGINES)
 
 
-class RENDER_PT_game(RenderButtonsPanel, Panel):
-    bl_label = "Game"
+class RENDER_PT_embedded(RenderButtonsPanel, bpy.types.Panel):
+    bl_label = "Embedded Player"
     COMPAT_ENGINES = {'BLENDER_GAME'}
-
     def draw(self, context):
         layout = self.layout
 
+        rd = context.scene.render
+
         row = layout.row()
         row.operator("view3d.game_start", text="Start")
         row.label()
+        row = layout.row()
+        row.label(text="Resolution:")
+        row = layout.row(align=True)
+        row.prop(rd, "resolution_x", slider=False, text="X")
+        row.prop(rd, "resolution_y", slider=False, text="Y")
 
 
 class RENDER_PT_game_player(RenderButtonsPanel, Panel):
@@ -264,29 +270,23 @@ class RENDER_PT_game_player(RenderButtonsPanel, Panel):
         layout = self.layout
 
         gs = context.scene.game_settings
-
-        layout.prop(gs, "show_fullscreen")
-
-        split = layout.split()
-
-        col = split.column()
-        col.label(text="Resolution:")
-        sub = col.column(align=True)
-        sub.prop(gs, "resolution_x", slider=False, text="X")
-        sub.prop(gs, "resolution_y", slider=False, text="Y")
-
-        col = split.column()
+        
+        row = layout.row()
+        row.operator("wm.blenderplayer_start", text="Start")
+        row.prop(gs, "show_fullscreen")
+        
+        row = layout.row()
+        row.label(text="Resolution:")
+        row = layout.row(align=True)
+        row.prop(gs, "resolution_x", slider=False, text="X")
+        row.prop(gs, "resolution_y", slider=False, text="Y")
+        
+        col = layout.column()
         col.label(text="Quality:")
-        sub = col.column(align=True)
-        sub.prop(gs, "depth", text="Bit Depth", slider=False)
-        sub.prop(gs, "frequency", text="FPS", slider=False)
+        col = layout.column(align=True)
+        col.prop(gs, "depth", text="Bit Depth", slider=False)
+        col.prop(gs, "frequency", text="Refresh Rate", slider=False)
 
-        # framing:
-        col = layout.column()
-        col.label(text="Framing:")
-        col.row().prop(gs, "frame_type", expand=True)
-        if gs.frame_type == 'LETTERBOX':
-            col.prop(gs, "frame_color", text="")
 
 
 class RENDER_PT_game_stereo(RenderButtonsPanel, Panel):
@@ -368,20 +368,24 @@ class RENDER_PT_game_shading(RenderButtonsPanel, Panel):
             col.prop(gs, "use_glsl_extra_textures", text="Extra Textures")
 
 
-class RENDER_PT_game_performance(RenderButtonsPanel, Panel):
-    bl_label = "Performance"
+class RENDER_PT_game_system(RenderButtonsPanel, Panel):
+    bl_label = "System"
     COMPAT_ENGINES = {'BLENDER_GAME'}
 
     def draw(self, context):
         layout = self.layout
 
         gs = context.scene.game_settings
-        col = layout.column()
-        row = col.row()
+        row = layout.row()
         row.prop(gs, "use_frame_rate")
+        row.prop(gs, "restrict_animation_updates")
+
+        row = layout.row()
         row.prop(gs, "use_display_lists")
 
-        col.prop(gs, "restrict_animation_updates")
+        row = layout.row()
+        row.label("Exit Key")
+        row.prop(gs, "exit_key", text="", event=True)
 
 
 class RENDER_PT_game_display(RenderButtonsPanel, Panel):
@@ -391,6 +395,9 @@ class RENDER_PT_game_display(RenderButtonsPanel, Panel):
     def draw(self, context):
         layout = self.layout
 
+        row = layout.row()
+        row.prop(context.scene.render, "fps", text="Animation Frame Rate", slider=False)
+
         gs = context.scene.game_settings
         flow = layout.column_flow()
         flow.prop(gs, "show_debug_properties", text="Debug Properties")
@@ -399,6 +406,12 @@ class RENDER_PT_game_display(RenderButtonsPanel, Panel):
         flow.prop(gs, "use_deprecation_warnings")
         flow.prop(gs, "show_mouse", text="Mouse Cursor")
 
+        col = layout.column()
+        col.label(text="Framing:")
+        col.row().prop(gs, "frame_type", expand=True)
+        if gs.frame_type == 'LETTERBOX':
+            col.prop(gs, "frame_color", text="")
+
 
 class SceneButtonsPanel():
     bl_space_type = 'PROPERTIES'
@@ -463,6 +476,20 @@ class SCENE_PT_game_navmesh(SceneButtonsPanel, Panel):
         row.prop(rd, "sample_dist")
         row.prop(rd, "sample_max_error")
 
+class RENDER_PT_game_sound(RenderButtonsPanel, Panel):
+    bl_label = "Sound"
+    COMPAT_ENGINES = {'BLENDER_GAME'}
+
+    def draw(self, context):
+        layout = self.layout
+
+        scene = context.scene
+
+        layout.prop(scene, "audio_distance_model")
+
+        col = layout.column(align=True)
+        col.prop(scene, "audio_doppler_speed", text="Speed")
+        col.prop(scene, "audio_doppler_factor")
 
 class WorldButtonsPanel():
     bl_space_type = 'PROPERTIES'
index f7f67527b639f5030bd7c52a1d03233c0c93b38d..b19cf0032afdd8d8d66ff9098fbefb3a937233d3 100644 (file)
@@ -76,7 +76,7 @@ class ParticleButtonsPanel():
 class PARTICLE_PT_context_particles(ParticleButtonsPanel, Panel):
     bl_label = ""
     bl_options = {'HIDE_HEADER'}
-    COMPAT_ENGINES = {'BLENDER_RENDER'}
+    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
 
     @classmethod
     def poll(cls, context):
@@ -85,6 +85,10 @@ class PARTICLE_PT_context_particles(ParticleButtonsPanel, Panel):
 
     def draw(self, context):
         layout = self.layout
+        
+        if context.scene.render.engine == "BLENDER_GAME":
+            layout.label("Not available in the Game Engine")
+            return
 
         ob = context.object
         psys = context.particle_system
index 4b4c2d2b214cde5d2bd48678b5d7e03c9e7f392f..6a8439ffaaada054f4ef2bee6743f361b97240d5 100644 (file)
@@ -51,7 +51,7 @@ class RenderButtonsPanel():
     @classmethod
     def poll(cls, context):
         rd = context.scene.render
-        return (context.scene and rd.use_game_engine is False) and (rd.engine in cls.COMPAT_ENGINES)
+        return context.scene and (rd.engine in cls.COMPAT_ENGINES)
 
 
 class RENDER_PT_render(RenderButtonsPanel, Panel):
@@ -553,7 +553,7 @@ class RENDER_PT_encoding(RenderButtonsPanel, Panel):
 class RENDER_PT_bake(RenderButtonsPanel, Panel):
     bl_label = "Bake"
     bl_options = {'DEFAULT_CLOSED'}
-    COMPAT_ENGINES = {'BLENDER_RENDER'}
+    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
 
     def draw(self, context):
         layout = self.layout
index 05f4887a5424403a45fde839c0b9acce401b5d47..b7218e4ba47ccde8cf6af7461b12a9ec840c47c6 100644 (file)
@@ -29,12 +29,13 @@ class SceneButtonsPanel():
 
     @classmethod
     def poll(cls, context):
-        return context.scene
+        rd = context.scene.render
+        return context.scene and (rd.engine in cls.COMPAT_ENGINES)
 
 
 class SCENE_PT_scene(SceneButtonsPanel, Panel):
     bl_label = "Scene"
-    COMPAT_ENGINES = {'BLENDER_RENDER'}
+    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
 
     def draw(self, context):
         layout = self.layout
@@ -75,7 +76,7 @@ class SCENE_PT_audio(SceneButtonsPanel, Panel):
 
 class SCENE_PT_unit(SceneButtonsPanel, Panel):
     bl_label = "Units"
-    COMPAT_ENGINES = {'BLENDER_RENDER'}
+    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
 
     def draw(self, context):
         layout = self.layout
@@ -93,6 +94,7 @@ class SCENE_PT_unit(SceneButtonsPanel, Panel):
 
 class SCENE_PT_keying_sets(SceneButtonsPanel, Panel):
     bl_label = "Keying Sets"
+    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
 
     def draw(self, context):
         layout = self.layout
@@ -125,6 +127,7 @@ class SCENE_PT_keying_sets(SceneButtonsPanel, Panel):
 
 class SCENE_PT_keying_set_paths(SceneButtonsPanel, Panel):
     bl_label = "Active Keying Set"
+    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
 
     @classmethod
     def poll(cls, context):
index 1ae8095fab3475e49978c4cde32a7e382a748610..1fc58475ace5773f42e2738c0333abcd94a7acc0 100644 (file)
@@ -70,7 +70,9 @@ class LOGIC_HT_header(Header):
         layout.template_header()
 
         if context.area.show_menus:
-            layout.menu("LOGIC_MT_view")
+            row = layout.row(align=True)
+            row.menu("LOGIC_MT_view")
+            row.menu("LOGIC_MT_logicbricks_add")
 
 
 class LOGIC_MT_view(Menu):
index e47c197cfa0d9d452c63c2fd35b2a080dfd3f311..20688151c1174223ab22e744b77219690bba5f3e 100644 (file)
@@ -958,11 +958,15 @@ void vDM_ColorBand_store(ColorBand *coba)
        stored_cb= coba;
 }
 
-/* return an array of vertex weight colors */
+/* return an array of vertex weight colors, caller must free.
+ *
+ * note that we could save some memory and allocate RGB only but then we'd need to
+ * re-arrange the colors when copying to the face since MCol has odd ordering,
+ * so leave this as is - campbell */
 static unsigned char *calc_weightpaint_vert_array(Object *ob, int const draw_flag, ColorBand *coba)
 {
        Mesh *me = ob->data;
-       unsigned char *wtcol_v = MEM_callocN (sizeof(unsigned char) * me->totvert * 4, "weightmap_v");
+       unsigned char *wtcol_v = MEM_mallocN (sizeof(unsigned char) * me->totvert * 4, "weightmap_v");
 
        if (me->dvert) {
                unsigned char *wc = wtcol_v;
@@ -1011,8 +1015,8 @@ static void add_weight_mcol_dm(Object *ob, DerivedMesh *dm, int const draw_flag)
                /*origindex being NULL means we're operating on original mesh data*/
                unsigned int fidx= mf->v4 ? 3:2;
                do {
-               copy_v4_v4_char((char *)&wtcol_f[(4 * i + fidx) * 4],
-                                               (char *)&wtcol_v[4 * (*(&mf->v1 + fidx))]);
+                       copy_v4_v4_char((char *)&wtcol_f[(4 * i + fidx) * 4],
+                                       (char *)&wtcol_v[4 * (*(&mf->v1 + fidx))]);
                } while (fidx--);
        }
 
index e27a315a023173bdfb99dbf988608881a4a0efca..861da665a305506418802745911e59b4a5bea70f 100644 (file)
@@ -100,6 +100,17 @@ int                BLI_dynstr_get_len                              (DynStr *ds);
         */
 char*  BLI_dynstr_get_cstring                  (DynStr *ds);
 
+/**
+ * Get a DynStr's contents as a c-string.
+ * <i> The str argument must be allocated to be at
+ * least the size of BLI_dynstr_get_len(ds). </i>
+ *
+ * @param ds The DynStr of interest.
+ * @param str The string to fill.
+ * @return The contents of @a ds as a c-string.
+ */
+void   BLI_dynstr_get_cstring_ex               (DynStr *ds, char *str);
+
        /**
         * Free the DynStr
         * 
index 349bc3492e78df611f8657b2792207c245693d70..ad52de180aa08c6091dcbacf618382c20dda91c0 100644 (file)
@@ -226,11 +226,11 @@ int BLI_dynstr_get_len(DynStr *ds)
        return ds->curlen;
 }
 
-char *BLI_dynstr_get_cstring(DynStr *ds)
+void BLI_dynstr_get_cstring_ex(DynStr *ds, char *rets)
 {
-       char *s, *rets= MEM_mallocN(ds->curlen+1, "dynstr_cstring");
+       char *s;
        DynStrElem *dse;
-       
+
        for (s= rets, dse= ds->elems; dse; dse= dse->next) {
                int slen= strlen(dse->str);
 
@@ -239,7 +239,12 @@ char *BLI_dynstr_get_cstring(DynStr *ds)
                s+= slen;
        }
        rets[ds->curlen]= '\0';
-       
+}
+
+char *BLI_dynstr_get_cstring(DynStr *ds)
+{
+       char *rets= MEM_mallocN(ds->curlen+1, "dynstr_cstring");
+       BLI_dynstr_get_cstring_ex(ds, rets);
        return rets;
 }
 
index 99c3ec0c134e132903bdbaa0348e871a81dd77ab..1c554cdcf9ab054a2dce326ea838bd40959a1041 100644 (file)
@@ -12805,6 +12805,14 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                        for (ntree=main->nodetree.first; ntree; ntree=ntree->id.next)
                                do_versions_nodetree_socket_use_flags_2_62(ntree);
                }
+               {
+                       /* Initialize BGE exit key to esc key */
+                       Scene *scene;
+                       for(scene= main->scene.first; scene; scene= scene->id.next) {
+                               if (!scene->gm.exitkey)
+                                       scene->gm.exitkey = 218; // Blender key code for ESC
+                       }
+               }
        }
 
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
index b15278bd5838bd8aaa10e49775765c88a35c5488..2f80c58a836d2ebea2347f10755d57e1348dd0ab 100644 (file)
@@ -1291,6 +1291,7 @@ static void area_split_exit(bContext *C, wmOperator *op)
                op->customdata = NULL;
        }
        
+       WM_cursor_restore(CTX_wm_window(C));
        WM_event_add_notifier(C, NC_SCREEN|NA_EDITED, NULL);
        
        /* this makes sure aligned edges will result in aligned grabbing */
@@ -1489,6 +1490,37 @@ static int area_split_modal(bContext *C, wmOperator *op, wmEvent *event)
                                }
                        }
                        break;
+                       
+               case MIDDLEMOUSE:
+               case TABKEY:
+                       if (sd->previewmode==0){
+                       }
+                       else{
+                               dir = RNA_enum_get(op->ptr, "direction");
+                               
+                               if(event->val==KM_PRESS){
+                                       if (sd->sarea){
+                                               sd->sarea->flag &= ~(AREA_FLAG_DRAWSPLIT_H|AREA_FLAG_DRAWSPLIT_V);
+                                               ED_area_tag_redraw(sd->sarea);
+                                               
+                                               if (dir=='v'){
+                                                       RNA_enum_set(op->ptr, "direction", 'h');
+                                                       sd->sarea->flag |= AREA_FLAG_DRAWSPLIT_H;
+                                                       
+                                                       WM_cursor_set(CTX_wm_window(C),CURSOR_X_MOVE);
+                                               }
+                                               else{
+                                                       RNA_enum_set(op->ptr, "direction", 'v');
+                                                       sd->sarea->flag |= AREA_FLAG_DRAWSPLIT_V;
+                                                       
+                                                       WM_cursor_set(CTX_wm_window(C),CURSOR_Y_MOVE);
+                                               }
+                                       }
+                               }
+                       }
+                       
+                       break;
+                       
                case RIGHTMOUSE: /* cancel operation */
                case ESCKEY:
                        return area_split_cancel(C, op);
index 2d0ad349be80a4de534520c224259171f19c8d5d..eb20465a2ab4baecea979a2da4ce36f3c1cabbf7 100644 (file)
@@ -605,9 +605,13 @@ void ED_keymap_paint(wmKeyConfig *keyconf)
        ed_keymap_paint_brush_size(keymap, "tool_settings.weight_paint.brush.size");
        ed_keymap_paint_brush_radial_control(keymap, "weight_paint", 0);
 
-       kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", MKEY, KM_PRESS, 0, 0); /* mask toggle */
+       kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", MKEY, KM_PRESS, 0, 0); /* face mask toggle */
        RNA_string_set(kmi->ptr, "data_path", "weight_paint_object.data.use_paint_mask");
 
+       /* note, conflicts with vertex paint, but this is more useful */
+       kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", VKEY, KM_PRESS, 0, 0); /* vert mask toggle */
+       RNA_string_set(kmi->ptr, "data_path", "weight_paint_object.data.use_paint_mask_vertex");
+
        WM_keymap_verify_item(keymap, "PAINT_OT_weight_from_bones", WKEY, KM_PRESS, 0, 0);
 
        
index 1b849754db84c3599d93c130ebc69fc2d46653ac..345e78d70c9c531e7a5efef7e304a1b7372bc8c3 100644 (file)
@@ -576,7 +576,7 @@ typedef struct GameData {
        short mode, matmode;
        short occlusionRes;             /* resolution of occlusion Z buffer in pixel */
        short physicsEngine;
-       short pad[2];
+       short exitkey, pad;
        short ticrate, maxlogicstep, physubstep, maxphystep;
        short obstacleSimulation, pad1;
        float levelHeight;
index eef7cddf0883ca17ceee07e5d96ad24df823384c..a193f5d0f33ea779d816d85e308b331e892c5377 100644 (file)
@@ -1215,6 +1215,13 @@ static void rna_GameSettings_auto_start_set(PointerRNA *UNUSED(ptr), int value)
                G.fileflags &= ~G_FILE_AUTOPLAY;
 }
 
+static void rna_GameSettings_exit_key_set(PointerRNA *ptr, int value)
+{
+       GameData *gm = (GameData*)ptr->data;
+
+       if(ISKEYBOARD(value))
+               gm->exitkey=value;
+}
 
 static TimeMarker *rna_TimeLine_add(Scene *scene, const char name[])
 {
@@ -2105,6 +2112,13 @@ static void rna_def_scene_game_data(BlenderRNA *brna)
        RNA_def_property_range(prop, 8, 32);
        RNA_def_property_ui_text(prop, "Bits", "Display bit depth of full screen display");
        RNA_def_property_update(prop, NC_SCENE, NULL);
+
+       prop= RNA_def_property(srna, "exit_key", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_sdna(prop, NULL, "exitkey");
+       RNA_def_property_enum_items(prop, event_type_items);
+       RNA_def_property_enum_funcs(prop, NULL, "rna_GameSettings_exit_key_set", NULL);
+       RNA_def_property_ui_text(prop, "Exit Key",  "Sets the key that exits the Game Engine");
+       RNA_def_property_update(prop, NC_SCENE, NULL);
        
        // Do we need it here ? (since we already have it in World
        prop= RNA_def_property(srna, "frequency", PROP_INT, PROP_NONE);
index 69a5fb39b673f5783d968bfe6e6b204861714cb2..ded0f2f768c2cf836965d86d73287f84ccfe143c 100644 (file)
@@ -642,7 +642,7 @@ PyObject *pyrna_math_object_from_array(PointerRNA *ptr, PropertyRNA *prop)
                        if (len==16) {
                                if (is_thick) {
                                        ret= Matrix_CreatePyObject(NULL, 4, 4, Py_NEW, NULL);
-                                       RNA_property_float_get_array(ptr, prop, ((MatrixObject *)ret)->contigPtr);
+                                       RNA_property_float_get_array(ptr, prop, ((MatrixObject *)ret)->matrix);
                                }
                                else {
                                        PyObject *mat_cb= Matrix_CreatePyObject_cb(ret, 4,4, mathutils_rna_matrix_cb_index, FALSE);
@@ -653,7 +653,7 @@ PyObject *pyrna_math_object_from_array(PointerRNA *ptr, PropertyRNA *prop)
                        else if (len==9) {
                                if (is_thick) {
                                        ret= Matrix_CreatePyObject(NULL, 3, 3, Py_NEW, NULL);
-                                       RNA_property_float_get_array(ptr, prop, ((MatrixObject *)ret)->contigPtr);
+                                       RNA_property_float_get_array(ptr, prop, ((MatrixObject *)ret)->matrix);
                                }
                                else {
                                        PyObject *mat_cb= Matrix_CreatePyObject_cb(ret, 3,3, mathutils_rna_matrix_cb_index, FALSE);
index 5587028d81291d3bd66785c26eecbd86467b2a2e..1dfd7c574dd1a8460cdc537830e02fb15696cef0 100644 (file)
@@ -35,6 +35,7 @@
 
 #include "BLI_math.h"
 #include "BLI_utildefines.h"
+#include "BLI_dynstr.h"
 
 PyDoc_STRVAR(M_Mathutils_doc,
 "This module provides access to matrices, eulers, quaternions and vectors."
@@ -211,7 +212,7 @@ int mathutils_any_to_rotmat(float rmat[3][3], PyObject *value, const char *error
                if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) {
                        return -1;
                }
-               else if (((MatrixObject *)value)->col_size < 3 || ((MatrixObject *)value)->row_size < 3) {
+               else if (((MatrixObject *)value)->num_row < 3 || ((MatrixObject *)value)->num_col < 3) {
                        PyErr_Format(PyExc_ValueError,
                                     "%.200s: matrix must have minimum 3x3 dimensions",
                                     error_prefix);
@@ -267,6 +268,18 @@ int EXPP_VectorsAreEqual(float *vecA, float *vecB, int size, int floatSteps)
        return 1;
 }
 
+/* dynstr as python string utility funcions, frees 'ds'! */
+PyObject *mathutils_dynstr_to_py(struct DynStr *ds)
+{
+       const int ds_len = BLI_dynstr_get_len(ds); /* space for \0 */
+       char *ds_buf     = PyMem_Malloc(ds_len + 1);
+       PyObject *ret;
+       BLI_dynstr_get_cstring_ex(ds, ds_buf);
+       BLI_dynstr_free(ds);
+       ret = PyUnicode_FromStringAndSize(ds_buf, ds_len);
+       PyMem_Free(ds_buf);
+       return ret;
+}
 
 /* Mathutils Callbacks */
 
index cd3548b9b825218757e32a4a985c1309047c9b34..2454e953949c25bcf4287bf2615202f011556d8c 100644 (file)
@@ -37,6 +37,8 @@
 
 /* Can cast different mathutils types to this, use for generic funcs */
 
+struct DynStr;
+
 extern char BaseMathObject_Wrapped_doc[];
 extern char BaseMathObject_Owner_doc[];
 
@@ -120,4 +122,7 @@ int mathutils_any_to_rotmat(float rmat[3][3], PyObject *value, const char *error
 
 int column_vector_multiplication(float rvec[4], VectorObject *vec, MatrixObject *mat);
 
+/* dynstr as python string utility funcions */
+PyObject *mathutils_dynstr_to_py(struct DynStr *ds);
+
 #endif /* MATHUTILS_H */
index e46dda7560f55a7d3bc3e11a7ab07714d526cda0..e0a0deb9a0e7945355b89b05e8dddb07a86e5df8 100644 (file)
@@ -32,6 +32,7 @@
 
 #include "BLI_math.h"
 #include "BLI_utildefines.h"
+#include "BLI_dynstr.h"
 
 #define COLOR_SIZE 3
 
@@ -125,6 +126,21 @@ static PyObject *Color_repr(ColorObject * self)
        return ret;
 }
 
+static PyObject *Color_str(ColorObject * self)
+{
+       DynStr *ds;
+
+       if (BaseMath_ReadCallback(self) == -1)
+               return NULL;
+
+       ds= BLI_dynstr_new();
+
+       BLI_dynstr_appendf(ds, "<Color (r=%.4f, g=%.4f, b=%.4f)>",
+                          self->col[0], self->col[1], self->col[2]);
+
+       return mathutils_dynstr_to_py(ds); /* frees ds */
+}
+
 //------------------------tp_richcmpr
 //returns -1 execption, 0 false, 1 true
 static PyObject* Color_richcmpr(PyObject *a, PyObject *b, int op)
@@ -789,7 +805,7 @@ PyTypeObject color_Type = {
        &Color_AsMapping,                               //tp_as_mapping
        NULL,                                                   //tp_hash
        NULL,                                                   //tp_call
-       NULL,                                                   //tp_str
+       (reprfunc) Color_str,                   //tp_str
        NULL,                                                   //tp_getattro
        NULL,                                                   //tp_setattro
        NULL,                                                   //tp_as_buffer
index f44c0b82a2d4e05e054a4fe5691a93d0a63f7fac..443e77c37989f276c87de488db107fcc1e845e92 100644 (file)
@@ -36,6 +36,7 @@
 
 #include "BLI_math.h"
 #include "BLI_utildefines.h"
+#include "BLI_dynstr.h"
 
 #define EULER_SIZE 3
 
@@ -317,6 +318,21 @@ static PyObject *Euler_repr(EulerObject * self)
        return ret;
 }
 
+static PyObject *Euler_str(EulerObject * self)
+{
+       DynStr *ds;
+
+       if (BaseMath_ReadCallback(self) == -1)
+               return NULL;
+
+       ds= BLI_dynstr_new();
+
+       BLI_dynstr_appendf(ds, "<Euler (x=%.4f, y=%.4f, z=%.4f), order='%s'>",
+                          self->eul[0], self->eul[1], self->eul[2], euler_order_str(self));
+
+       return mathutils_dynstr_to_py(ds); /* frees ds */
+}
+
 static PyObject* Euler_richcmpr(PyObject *a, PyObject *b, int op)
 {
        PyObject *res;
@@ -635,7 +651,7 @@ PyTypeObject euler_Type = {
        &Euler_AsMapping,                               //tp_as_mapping
        NULL,                                                   //tp_hash
        NULL,                                                   //tp_call
-       NULL,                                                   //tp_str
+       (reprfunc) Euler_str,                   //tp_str
        NULL,                                                   //tp_getattro
        NULL,                                                   //tp_setattro
        NULL,                                                   //tp_as_buffer
index 44799bb7943a1077f064a414e5f0726bae9d2a4b..59aad37f7465e5efc26827922a55c2cdc6567bd8 100644 (file)
@@ -35,6 +35,8 @@
 
 #include "BLI_math.h"
 #include "BLI_utildefines.h"
+#include "BLI_string.h"
+#include "BLI_dynstr.h"
 
 static PyObject *Matrix_copy(MatrixObject *self);
 static int Matrix_ass_slice(MatrixObject *self, int begin, int end, PyObject *value);
@@ -49,56 +51,56 @@ static int mathutils_matrix_vector_check(BaseMathObject *bmo)
        return BaseMath_ReadCallback(self);
 }
 
-static int mathutils_matrix_vector_get(BaseMathObject *bmo, int subtype)
+static int mathutils_matrix_vector_get(BaseMathObject *bmo, int col)
 {
        MatrixObject *self= (MatrixObject *)bmo->cb_user;
-       int index;
+       int row;
 
        if (BaseMath_ReadCallback(self) == -1)
                return -1;
 
-       for (index=0; index < self->col_size; index++) {
-               bmo->data[index] = MATRIX_ITEM(self, subtype, index);
+       for (row=0; row < self->num_row; row++) {
+               bmo->data[row] = MATRIX_ITEM(self, row, col);
        }
 
        return 0;
 }
 
-static int mathutils_matrix_vector_set(BaseMathObject *bmo, int subtype)
+static int mathutils_matrix_vector_set(BaseMathObject *bmo, int col)
 {
        MatrixObject *self= (MatrixObject *)bmo->cb_user;
-       int index;
+       int row;
 
        if (BaseMath_ReadCallback(self) == -1)
                return -1;
 
-       for (index=0; index < self->col_size; index++) {
-               MATRIX_ITEM(self, subtype, index) = bmo->data[index];
+       for (row=0; row < self->num_row; row++) {
+               MATRIX_ITEM(self, row, col) = bmo->data[row];
        }
 
        (void)BaseMath_WriteCallback(self);
        return 0;
 }
 
-static int mathutils_matrix_vector_get_index(BaseMathObject *bmo, int subtype, int index)
+static int mathutils_matrix_vector_get_index(BaseMathObject *bmo, int col, int row)
 {
        MatrixObject *self= (MatrixObject *)bmo->cb_user;
 
        if (BaseMath_ReadCallback(self) == -1)
                return -1;
 
-       bmo->data[index]= MATRIX_ITEM(self, subtype, index);
+       bmo->data[row]= MATRIX_ITEM(self, row, col);
        return 0;
 }
 
-static int mathutils_matrix_vector_set_index(BaseMathObject *bmo, int subtype, int index)
+static int mathutils_matrix_vector_set_index(BaseMathObject *bmo, int col, int row)
 {
        MatrixObject *self= (MatrixObject *)bmo->cb_user;
 
        if (BaseMath_ReadCallback(self) == -1)
                return -1;
 
-       MATRIX_ITEM(self, subtype, index) = bmo->data[index];
+       MATRIX_ITEM(self, row, col) = bmo->data[row];
 
        (void)BaseMath_WriteCallback(self);
        return 0;
@@ -133,16 +135,16 @@ static PyObject *Matrix_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
                        PyObject *arg= PyTuple_GET_ITEM(args, 0);
 
                        /* -1 is an error, size checks will accunt for this */
-                       const unsigned short row_size= PySequence_Size(arg);
+                       const unsigned short num_col= PySequence_Size(arg);
 
-                       if (row_size >= 2 && row_size <= 4) {
+                       if (num_col >= 2 && num_col <= 4) {
                                PyObject *item= PySequence_GetItem(arg, 0);
-                               const unsigned short col_size= PySequence_Size(item);
+                               const unsigned short num_row= PySequence_Size(item);
                                Py_XDECREF(item);
 
-                               if (col_size >= 2 && col_size <= 4) {
+                               if (num_row >= 2 && num_row <= 4) {
                                        /* sane row & col size, new matrix and assign as slice  */
-                                       PyObject *matrix= Matrix_CreatePyObject(NULL, row_size, col_size, Py_NEW, type);
+                                       PyObject *matrix= Matrix_CreatePyObject(NULL, num_col, num_row, Py_NEW, type);
                                        if (Matrix_ass_slice((MatrixObject *)matrix, 0, INT_MAX, arg) == 0) {
                                                return matrix;
                                        }
@@ -622,25 +624,25 @@ static PyObject *C_Matrix_Shear(PyObject *cls, PyObject *args)
 
 void matrix_as_3x3(float mat[3][3], MatrixObject *self)
 {
-       copy_v3_v3(mat[0], MATRIX_ROW_PTR(self, 0));
-       copy_v3_v3(mat[1], MATRIX_ROW_PTR(self, 1));
-       copy_v3_v3(mat[2], MATRIX_ROW_PTR(self, 2));
+       copy_v3_v3(mat[0], MATRIX_COL_PTR(self, 0));
+       copy_v3_v3(mat[1], MATRIX_COL_PTR(self, 1));
+       copy_v3_v3(mat[2], MATRIX_COL_PTR(self, 2));
 }
 
 /* assumes rowsize == colsize is checked and the read callback has run */
 static float matrix_determinant_internal(MatrixObject *self)
 {
-       if (self->row_size == 2) {
+       if (self->num_col == 2) {
                return determinant_m2(MATRIX_ITEM(self, 0, 0), MATRIX_ITEM(self, 0, 1),
                                      MATRIX_ITEM(self, 1, 0), MATRIX_ITEM(self, 1, 1));
        }
-       else if (self->row_size == 3) {
+       else if (self->num_col == 3) {
                return determinant_m3(MATRIX_ITEM(self, 0, 0), MATRIX_ITEM(self, 0, 1), MATRIX_ITEM(self, 0, 2),
                                      MATRIX_ITEM(self, 1, 0), MATRIX_ITEM(self, 1, 1), MATRIX_ITEM(self, 1, 2),
                                      MATRIX_ITEM(self, 2, 0), MATRIX_ITEM(self, 2, 1), MATRIX_ITEM(self, 2, 2));
        }
        else {
-               return determinant_m4((float (*)[4])self->contigPtr);
+               return determinant_m4((float (*)[4])self->matrix);
        }
 }
 
@@ -662,17 +664,17 @@ static PyObject *Matrix_to_quaternion(MatrixObject *self)
                return NULL;
 
        /*must be 3-4 cols, 3-4 rows, square matrix*/
-       if ((self->col_size < 3) || (self->row_size < 3) || (self->col_size != self->row_size)) {
+       if ((self->num_row < 3) || (self->num_col < 3) || (self->num_row != self->num_col)) {
                PyErr_SetString(PyExc_ValueError,
                                "Matrix.to_quat(): "
                                "inappropriate matrix size - expects 3x3 or 4x4 matrix");
                return NULL;
        }
-       if (self->col_size == 3) {
-               mat3_to_quat(quat, (float (*)[3])self->contigPtr);
+       if (self->num_row == 3) {
+               mat3_to_quat(quat, (float (*)[3])self->matrix);
        }
        else {
-               mat4_to_quat(quat, (float (*)[4])self->contigPtr);
+               mat4_to_quat(quat, (float (*)[4])self->matrix);
        }
 
        return Quaternion_CreatePyObject(quat, Py_NEW, NULL);
@@ -719,11 +721,11 @@ static PyObject *Matrix_to_euler(MatrixObject *self, PyObject *args)
        }
 
        /*must be 3-4 cols, 3-4 rows, square matrix*/
-       if (self->col_size ==3 && self->row_size ==3) {
-               mat= (float (*)[3])self->contigPtr;
+       if (self->num_row ==3 && self->num_col ==3) {
+               mat= (float (*)[3])self->matrix;
        }
-       else if (self->col_size ==4 && self->row_size ==4) {
-               copy_m3_m4(tmat, (float (*)[4])self->contigPtr);
+       else if (self->num_row ==4 && self->num_col ==4) {
+               copy_m3_m4(tmat, (float (*)[4])self->matrix);
                mat= tmat;
        }
        else {
@@ -774,8 +776,8 @@ static PyObject *Matrix_resize_4x4(MatrixObject *self)
                return NULL;
        }
 
-       self->contigPtr = PyMem_Realloc(self->contigPtr, (sizeof(float) * 16));
-       if (self->contigPtr == NULL) {
+       self->matrix = PyMem_Realloc(self->matrix, (sizeof(float) * 16));
+       if (self->matrix == NULL) {
                PyErr_SetString(PyExc_MemoryError,
                                "Matrix.resize_4x4(): "
                                "problem allocating pointer space");
@@ -783,31 +785,31 @@ static PyObject *Matrix_resize_4x4(MatrixObject *self)
        }
 
        /*move data to new spot in array + clean*/
-       for (blank_rows = (4 - self->row_size); blank_rows > 0; blank_rows--) {
+       for (blank_rows = (4 - self->num_col); blank_rows > 0; blank_rows--) {
                for (x = 0; x < 4; x++) {
-                       index = (4 * (self->row_size + (blank_rows - 1))) + x;
+                       index = (4 * (self->num_col + (blank_rows - 1))) + x;
                        if (index == 10 || index == 15) {
-                               self->contigPtr[index] = 1.0f;
+                               self->matrix[index] = 1.0f;
                        }
                        else {
-                               self->contigPtr[index] = 0.0f;
+                               self->matrix[index] = 0.0f;
                        }
                }
        }
-       for (x = 1; x <= self->row_size; x++) {
-               first_row_elem = (self->col_size * (self->row_size - x));
-               curr_pos = (first_row_elem + (self->col_size -1));
-               new_pos = (4 * (self->row_size - x)) + (curr_pos - first_row_elem);
-               for (blank_columns = (4 - self->col_size); blank_columns > 0; blank_columns--) {
-                       self->contigPtr[new_pos + blank_columns] = 0.0f;
+       for (x = 1; x <= self->num_col; x++) {
+               first_row_elem = (self->num_row * (self->num_col - x));
+               curr_pos = (first_row_elem + (self->num_row -1));
+               new_pos = (4 * (self->num_col - x)) + (curr_pos - first_row_elem);
+               for (blank_columns = (4 - self->num_row); blank_columns > 0; blank_columns--) {
+                       self->matrix[new_pos + blank_columns] = 0.0f;
                }
                for ( ; curr_pos >= first_row_elem; curr_pos--) {
-                       self->contigPtr[new_pos] = self->contigPtr[curr_pos];
+                       self->matrix[new_pos] = self->matrix[curr_pos];
                        new_pos--;
                }
        }
-       self->row_size = 4;
-       self->col_size = 4;
+       self->num_col = 4;
+       self->num_row = 4;
 
        Py_RETURN_NONE;
 }
@@ -825,12 +827,12 @@ static PyObject *Matrix_to_4x4(MatrixObject *self)
        if (BaseMath_ReadCallback(self) == -1)
                return NULL;
 
-       if (self->col_size==4 && self->row_size==4) {
-               return Matrix_CreatePyObject(self->contigPtr, 4, 4, Py_NEW, Py_TYPE(self));
+       if (self->num_row==4 && self->num_col==4) {
+               return Matrix_CreatePyObject(self->matrix, 4, 4, Py_NEW, Py_TYPE(self));
        }
-       else if (self->col_size==3 && self->row_size==3) {
+       else if (self->num_row==3 && self->num_col==3) {
                float mat[4][4];
-               copy_m4_m3(mat, (float (*)[3])self->contigPtr);
+               copy_m4_m3(mat, (float (*)[3])self->matrix);
                return Matrix_CreatePyObject((float *)mat, 4, 4, Py_NEW, Py_TYPE(self));
        }
        /* TODO, 2x2 matrix */
@@ -856,7 +858,7 @@ static PyObject *Matrix_to_3x3(MatrixObject *self)
        if (BaseMath_ReadCallback(self) == -1)
                return NULL;
 
-       if ((self->col_size < 3) || (self->row_size < 3)) {
+       if ((self->num_row < 3) || (self->num_col < 3)) {
                PyErr_SetString(PyExc_TypeError,
                                "Matrix.to_3x3(): inappropriate matrix size");
                return NULL;
@@ -880,14 +882,14 @@ static PyObject *Matrix_to_translation(MatrixObject *self)
        if (BaseMath_ReadCallback(self) == -1)
                return NULL;
 
-       if ((self->col_size < 3) || self->row_size < 4) {
+       if ((self->num_row < 3) || self->num_col < 4) {
                PyErr_SetString(PyExc_TypeError,
                                "Matrix.to_translation(): "
                                "inappropriate matrix size");
                return NULL;
        }
 
-       return Vector_CreatePyObject(MATRIX_ROW_PTR(self, 3), 3, Py_NEW, NULL);
+       return Vector_CreatePyObject(MATRIX_COL_PTR(self, 3), 3, Py_NEW, NULL);
 }
 
 PyDoc_STRVAR(Matrix_to_scale_doc,
@@ -910,7 +912,7 @@ static PyObject *Matrix_to_scale(MatrixObject *self)
                return NULL;
 
        /*must be 3-4 cols, 3-4 rows, square matrix*/
-       if ((self->col_size < 3) || (self->row_size < 3)) {
+       if ((self->num_row < 3) || (self->num_col < 3)) {
                PyErr_SetString(PyExc_TypeError,
                                "Matrix.to_scale(): "
                                "inappropriate matrix size, 3x3 minimum size");
@@ -948,7 +950,7 @@ static PyObject *Matrix_invert(MatrixObject *self)
        if (BaseMath_ReadCallback(self) == -1)
                return NULL;
 
-       if (self->row_size != self->col_size) {
+       if (self->num_col != self->num_row) {
                PyErr_SetString(PyExc_TypeError,
                                "Matrix.invert(ed): "
                                "only square matrices are supported");
@@ -960,26 +962,26 @@ static PyObject *Matrix_invert(MatrixObject *self)
 
        if (det != 0) {
                /*calculate the classical adjoint*/
-               if (self->row_size == 2) {
+               if (self->num_col == 2) {
                        mat[0] =  MATRIX_ITEM(self, 1, 1);
                        mat[1] = -MATRIX_ITEM(self, 0, 1);
                        mat[2] = -MATRIX_ITEM(self, 1, 0);
                        mat[3] =  MATRIX_ITEM(self, 0, 0);
                }
-               else if (self->row_size == 3) {
-                       adjoint_m3_m3((float (*)[3]) mat,(float (*)[3])self->contigPtr);
+               else if (self->num_col == 3) {
+                       adjoint_m3_m3((float (*)[3]) mat,(float (*)[3])self->matrix);
                }
-               else if (self->row_size == 4) {
-                       adjoint_m4_m4((float (*)[4]) mat, (float (*)[4])self->contigPtr);
+               else if (self->num_col == 4) {
+                       adjoint_m4_m4((float (*)[4]) mat, (float (*)[4])self->matrix);
                }
                /*divide by determinate*/
-               for (x = 0; x < (self->row_size * self->col_size); x++) {
+               for (x = 0; x < (self->num_col * self->num_row); x++) {
                        mat[x] /= det;
                }
                /*set values*/
-               for (x = 0; x < self->row_size; x++) {
-                       for (y = 0; y < self->col_size; y++) {
-                               MATRIX_ITEM(self, x, y) = mat[z];
+               for (x = 0; x < self->num_col; x++) {
+                       for (y = 0; y < self->num_row; y++) {
+                               MATRIX_ITEM(self, y, x) = mat[z];
                                z++;
                        }
                }
@@ -1032,7 +1034,7 @@ static PyObject *Matrix_rotate(MatrixObject *self, PyObject *value)
        if (mathutils_any_to_rotmat(other_rmat, value, "matrix.rotate(value)") == -1)
                return NULL;
 
-       if (self->col_size != 3 || self->row_size != 3) {
+       if (self->num_row != 3 || self->num_col != 3) {
                PyErr_SetString(PyExc_TypeError,
                                "Matrix.rotate(): "
                                "must have 3x3 dimensions");
@@ -1042,7 +1044,7 @@ static PyObject *Matrix_rotate(MatrixObject *self, PyObject *value)
        matrix_as_3x3(self_rmat, self);
        mul_m3_m3m3(rmat, other_rmat, self_rmat);
 
-       copy_m3_m3((float (*)[3])(self->contigPtr), rmat);
+       copy_m3_m3((float (*)[3])(self->matrix), rmat);
 
        (void)BaseMath_WriteCallback(self);
        Py_RETURN_NONE;
@@ -1065,7 +1067,7 @@ static PyObject *Matrix_decompose(MatrixObject *self)
        float quat[4];
        float size[3];
 
-       if (self->col_size != 4 || self->row_size != 4) {
+       if (self->num_row != 4 || self->num_col != 4) {
                PyErr_SetString(PyExc_TypeError,
                                "Matrix.decompose(): "
                                "inappropriate matrix size - expects 4x4 matrix");
@@ -1075,7 +1077,7 @@ static PyObject *Matrix_decompose(MatrixObject *self)
        if (BaseMath_ReadCallback(self) == -1)
                return NULL;
 
-       mat4_to_loc_rot_size(loc, rot, size, (float (*)[4])self->contigPtr);
+       mat4_to_loc_rot_size(loc, rot, size, (float (*)[4])self->matrix);
        mat3_to_quat(quat, rot);
 
        ret= PyTuple_New(3);
@@ -1108,7 +1110,7 @@ static PyObject *Matrix_lerp(MatrixObject *self, PyObject *args)
        if (!PyArg_ParseTuple(args, "O!f:lerp", &matrix_Type, &mat2, &fac))
                return NULL;
 
-       if (self->row_size != mat2->row_size || self->col_size != mat2->col_size) {
+       if (self->num_col != mat2->num_col || self->num_row != mat2->num_row) {
                PyErr_SetString(PyExc_ValueError,
                                "Matrix.lerp(): "
                                "expects both matrix objects of the same dimensions");
@@ -1119,11 +1121,11 @@ static PyObject *Matrix_lerp(MatrixObject *self, PyObject *args)
                return NULL;
 
        /* TODO, different sized matrix */
-       if (self->row_size==4 && self->col_size==4) {
-               blend_m4_m4m4((float (*)[4])mat, (float (*)[4])self->contigPtr, (float (*)[4])mat2->contigPtr, fac);
+       if (self->num_col==4 && self->num_row==4) {
+               blend_m4_m4m4((float (*)[4])mat, (float (*)[4])self->matrix, (float (*)[4])mat2->matrix, fac);
        }
-       else if (self->row_size==3 && self->col_size==3) {
-               blend_m3_m3m3((float (*)[3])mat, (float (*)[3])self->contigPtr, (float (*)[3])mat2->contigPtr, fac);
+       else if (self->num_col==3 && self->num_row==3) {
+               blend_m3_m3m3((float (*)[3])mat, (float (*)[3])self->matrix, (float (*)[3])mat2->matrix, fac);
        }
        else {
                PyErr_SetString(PyExc_ValueError,
@@ -1132,7 +1134,7 @@ static PyObject *Matrix_lerp(MatrixObject *self, PyObject *args)
                return NULL;
        }
 
-       return Matrix_CreatePyObject(mat, self->row_size, self->col_size, Py_NEW, Py_TYPE(self));
+       return Matrix_CreatePyObject(mat, self->num_col, self->num_row, Py_NEW, Py_TYPE(self));
 }
 
 /*---------------------------matrix.determinant() ----------------*/
@@ -1151,7 +1153,7 @@ static PyObject *Matrix_determinant(MatrixObject *self)
        if (BaseMath_ReadCallback(self) == -1)
                return NULL;
 
-       if (self->row_size != self->col_size) {
+       if (self->num_col != self->num_row) {
                PyErr_SetString(PyExc_TypeError,
                                "Matrix.determinant(): "
                                "only square matrices are supported");
@@ -1173,23 +1175,23 @@ static PyObject *Matrix_transpose(MatrixObject *self)
        if (BaseMath_ReadCallback(self) == -1)
                return NULL;
 
-       if (self->row_size != self->col_size) {
+       if (self->num_col != self->num_row) {
                PyErr_SetString(PyExc_TypeError,
                                "Matrix.transpose(d): "
                                "only square matrices are supported");
                return NULL;
        }
 
-       if (self->row_size == 2) {
+       if (self->num_col == 2) {
                const float t = MATRIX_ITEM(self, 1, 0);
                MATRIX_ITEM(self, 1, 0) = MATRIX_ITEM(self, 0, 1);
                MATRIX_ITEM(self, 0, 1) = t;
        }
-       else if (self->row_size == 3) {
-               transpose_m3((float (*)[3])self->contigPtr);
+       else if (self->num_col == 3) {
+               transpose_m3((float (*)[3])self->matrix);
        }
        else {
-               transpose_m4((float (*)[4])self->contigPtr);
+               transpose_m4((float (*)[4])self->matrix);
        }
 
        (void)BaseMath_WriteCallback(self);
@@ -1220,7 +1222,7 @@ PyDoc_STRVAR(Matrix_zero_doc,
 );
 static PyObject *Matrix_zero(MatrixObject *self)
 {
-       fill_vn_fl(self->contigPtr, self->row_size * self->col_size, 0.0f);
+       fill_vn_fl(self->matrix, self->num_col * self->num_row, 0.0f);
 
        if (BaseMath_WriteCallback(self) == -1)
                return NULL;
@@ -1243,24 +1245,24 @@ static PyObject *Matrix_identity(MatrixObject *self)
        if (BaseMath_ReadCallback(self) == -1)
                return NULL;
 
-       if (self->row_size != self->col_size) {
+       if (self->num_col != self->num_row) {
                PyErr_SetString(PyExc_TypeError,
                                "Matrix.identity(): "
                                "only square matrices are supported");
                return NULL;
        }
 
-       if (self->row_size == 2) {
+       if (self->num_col == 2) {
                MATRIX_ITEM(self, 0, 0) = 1.0f;
                MATRIX_ITEM(self, 0, 1) = 0.0f;
                MATRIX_ITEM(self, 1, 0) = 0.0f;
                MATRIX_ITEM(self, 1, 1) = 1.0f;
        }
-       else if (self->row_size == 3) {
-               unit_m3((float (*)[3])self->contigPtr);
+       else if (self->num_col == 3) {
+               unit_m3((float (*)[3])self->matrix);
        }
        else {
-               unit_m4((float (*)[4])self->contigPtr);
+               unit_m4((float (*)[4])self->matrix);
        }
 
        if (BaseMath_WriteCallback(self) == -1)
@@ -1283,26 +1285,26 @@ static PyObject *Matrix_copy(MatrixObject *self)
        if (BaseMath_ReadCallback(self) == -1)
                return NULL;
 
-       return Matrix_CreatePyObject((float (*))self->contigPtr, self->row_size, self->col_size, Py_NEW, Py_TYPE(self));
+       return Matrix_CreatePyObject((float (*))self->matrix, self->num_col, self->num_row, Py_NEW, Py_TYPE(self));
 }
 
 /*----------------------------print object (internal)-------------*/
 /*print the object to screen*/
 static PyObject *Matrix_repr(MatrixObject *self)
 {
-       int x, y;
+       int col, row;
        PyObject *rows[MATRIX_MAX_DIM]= {NULL};
 
        if (BaseMath_ReadCallback(self) == -1)
                return NULL;
 
-       for (x = 0; x < self->row_size; x++) {
-               rows[x]= PyTuple_New(self->col_size);
-               for (y = 0; y < self->col_size; y++) {
-                       PyTuple_SET_ITEM(rows[x], y, PyFloat_FromDouble(MATRIX_ITEM(self, x, y)));
+       for (col = 0; col < self->num_col; col++) {
+               rows[col]= PyTuple_New(self->num_row);
+               for (row = 0; row < self->num_row; row++) {
+                       PyTuple_SET_ITEM(rows[col], row, PyFloat_FromDouble(MATRIX_ITEM(self, row, col)));
                }
        }
-       switch (self->row_size) {
+       switch (self->num_col) {
        case 2: return PyUnicode_FromFormat("Matrix((%R,\n"
                                                                                "        %R))", rows[0], rows[1]);
 
@@ -1320,6 +1322,42 @@ static PyObject *Matrix_repr(MatrixObject *self)
        return NULL;
 }
 
+static PyObject* Matrix_str(MatrixObject *self)
+{
+       DynStr *ds;
+
+       int maxsize[MATRIX_MAX_DIM];
+       int row, col;
+
+       char dummy_buf[1];
+
+       if (BaseMath_ReadCallback(self) == -1)
+               return NULL;
+
+       ds= BLI_dynstr_new();
+
+       /* First determine the maximum width for each column */
+       for (col = 0; col < self->num_col; col++) {
+               maxsize[col]= 0;
+               for (row = 0; row < self->num_row; row++) {
+                       int size= BLI_snprintf(dummy_buf, sizeof(dummy_buf), "%.4f", MATRIX_ITEM(self, row, col));
+                       maxsize[col]= MAX2(maxsize[col], size);
+               }
+       }
+
+       /* Now write the unicode string to be printed */
+       BLI_dynstr_appendf(ds, "<Matrix %dx%d (", self->num_row, self->num_col);
+       for (row = 0; row < self->num_row; row++) {
+               for (col = 0; col < self->num_col; col++) {
+                       BLI_dynstr_appendf(ds, col ? ", %*.4f" : "%*.4f", maxsize[col], MATRIX_ITEM(self, row, col));
+               }
+               BLI_dynstr_append(ds, row + 1 != self->num_row ? ")\n             " : ")");
+       }
+       BLI_dynstr_append(ds, ">");
+
+       return mathutils_dynstr_to_py(ds); /* frees ds */
+}
+
 static PyObject* Matrix_richcmpr(PyObject *a, PyObject *b, int op)
 {
        PyObject *res;
@@ -1332,9 +1370,9 @@ static PyObject* Matrix_richcmpr(PyObject *a, PyObject *b, int op)
                if (BaseMath_ReadCallback(matA) == -1 || BaseMath_ReadCallback(matB) == -1)
                        return NULL;
 
-               ok=     (       (matA->col_size == matB->col_size) &&
-                               (matA->row_size == matB->row_size) &&
-                               EXPP_VectorsAreEqual(matA->contigPtr, matB->contigPtr, (matA->row_size * matA->col_size), 1)
+               ok=     (       (matA->num_row == matB->num_row) &&
+                               (matA->num_col == matB->num_col) &&
+                               EXPP_VectorsAreEqual(matA->matrix, matB->matrix, (matA->num_col * matA->num_row), 1)
                        ) ? 0 : -1;
        }
 
@@ -1364,7 +1402,7 @@ static PyObject* Matrix_richcmpr(PyObject *a, PyObject *b, int op)
   sequence length*/
 static int Matrix_len(MatrixObject *self)
 {
-       return (self->row_size);
+       return (self->num_col);
 }
 /*----------------------------object[]---------------------------
   sequence accessor (get)
@@ -1374,13 +1412,13 @@ static PyObject *Matrix_item(MatrixObject *self, int i)
        if (BaseMath_ReadCallback(self) == -1)
                return NULL;
 
-       if (i < 0 || i >= self->row_size) {
+       if (i < 0 || i >= self->num_col) {
                PyErr_SetString(PyExc_IndexError,
                                "matrix[attribute]: "
                                "array index out of range");
                return NULL;
        }
-       return Vector_CreatePyObject_cb((PyObject *)self, self->col_size, mathutils_matrix_vector_cb_index, i);
+       return Vector_CreatePyObject_cb((PyObject *)self, self->num_row, mathutils_matrix_vector_cb_index, i);
 }
 /*----------------------------object[]-------------------------
   sequence accessor (set) */
@@ -1391,17 +1429,17 @@ static int Matrix_ass_item(MatrixObject *self, int i, PyObject *value)
        if (BaseMath_ReadCallback(self) == -1)
                return -1;
 
-       if (i >= self->row_size || i < 0) {
+       if (i >= self->num_col || i < 0) {
                PyErr_SetString(PyExc_IndexError,
                                "matrix[attribute] = x: bad column");
                return -1;
        }
 
-       if (mathutils_array_parse(vec, self->col_size, self->col_size, value, "matrix[i] = value assignment") < 0) {
+       if (mathutils_array_parse(vec, self->num_row, self->num_row, value, "matrix[i] = value assignment") < 0) {
                return -1;
        }
 
-       memcpy(MATRIX_ROW_PTR(self, i), vec, self->col_size * sizeof(float));
+       memcpy(MATRIX_COL_PTR(self, i), vec, self->num_row * sizeof(float));
 
        (void)BaseMath_WriteCallback(self);
        return 0;
@@ -1418,14 +1456,14 @@ static PyObject *Matrix_slice(MatrixObject *self, int begin, int end)
        if (BaseMath_ReadCallback(self) == -1)
                return NULL;
 
-       CLAMP(begin, 0, self->row_size);
-       CLAMP(end, 0, self->row_size);
+       CLAMP(begin, 0, self->num_col);
+       CLAMP(end, 0, self->num_col);
        begin= MIN2(begin, end);
 
        tuple= PyTuple_New(end - begin);
        for (count= begin; count < end; count++) {
                PyTuple_SET_ITEM(tuple, count - begin,
-                               Vector_CreatePyObject_cb((PyObject *)self, self->col_size, mathutils_matrix_vector_cb_index, count));
+                               Vector_CreatePyObject_cb((PyObject *)self, self->num_row, mathutils_matrix_vector_cb_index, count));
 
        }
 
@@ -1440,8 +1478,8 @@ static int Matrix_ass_slice(MatrixObject *self, int begin, int end, PyObject *va
        if (BaseMath_ReadCallback(self) == -1)
                return -1;
 
-       CLAMP(begin, 0, self->row_size);
-       CLAMP(end, 0, self->row_size);
+       CLAMP(begin, 0, self->num_col);
+       CLAMP(end, 0, self->num_col);
        begin = MIN2(begin, end);
 
        /* non list/tuple cases */
@@ -1467,7 +1505,7 @@ static int Matrix_ass_slice(MatrixObject *self, int begin, int end, PyObject *va
                        /*parse each sub sequence*/
                        PyObject *item= PySequence_Fast_GET_ITEM(value_fast, i);
 
-                       if (mathutils_array_parse(&mat[i * self->col_size], self->col_size, self->col_size, item,
+                       if (mathutils_array_parse(&mat[i * self->num_row], self->num_row, self->num_row, item,
                                                  "matrix[begin:end] = value assignment") < 0)
                        {
                                return -1;
@@ -1477,7 +1515,7 @@ static int Matrix_ass_slice(MatrixObject *self, int begin, int end, PyObject *va
                Py_DECREF(value_fast);
 
                /*parsed well - now set in matrix*/
-               memcpy(self->contigPtr + (begin * self->col_size), mat, sizeof(float) * (size * self->col_size));
+               memcpy(self->matrix + (begin * self->num_row), mat, sizeof(float) * (size * self->num_row));
 
                (void)BaseMath_WriteCallback(self);
                return 0;
@@ -1504,16 +1542,16 @@ static PyObject *Matrix_add(PyObject *m1, PyObject *m2)
        if (BaseMath_ReadCallback(mat1) == -1 || BaseMath_ReadCallback(mat2) == -1)
                return NULL;
 
-       if (mat1->row_size != mat2->row_size || mat1->col_size != mat2->col_size) {
+       if (mat1->num_col != mat2->num_col || mat1->num_row != mat2->num_row) {
                PyErr_SetString(PyExc_TypeError,
                                "Matrix addition: "
                                "matrices must have the same dimensions for this operation");
                return NULL;
        }
 
-       add_vn_vnvn(mat, mat1->contigPtr, mat2->contigPtr, mat1->row_size * mat1->col_size);
+       add_vn_vnvn(mat, mat1->matrix, mat2->matrix, mat1->num_col * mat1->num_row);
 
-       return Matrix_CreatePyObject(mat, mat1->row_size, mat1->col_size, Py_NEW, Py_TYPE(mat1));
+       return Matrix_CreatePyObject(mat, mat1->num_col, mat1->num_row, Py_NEW, Py_TYPE(mat1));
 }
 /*------------------------obj - obj------------------------------
   subtraction*/
@@ -1537,24 +1575,24 @@ static PyObject *Matrix_sub(PyObject *m1, PyObject *m2)
        if (BaseMath_ReadCallback(mat1) == -1 || BaseMath_ReadCallback(mat2) == -1)
                return NULL;
 
-       if (mat1->row_size != mat2->row_size || mat1->col_size != mat2->col_size) {
+       if (mat1->num_col != mat2->num_col || mat1->num_row != mat2->num_row) {
                PyErr_SetString(PyExc_TypeError,
                                "Matrix addition: "
                                "matrices must have the same dimensions for this operation");
                return NULL;
        }
 
-       sub_vn_vnvn(mat, mat1->contigPtr, mat2->contigPtr, mat1->row_size * mat1->col_size);
+       sub_vn_vnvn(mat, mat1->matrix, mat2->matrix, mat1->num_col * mat1->num_row);
 
-       return Matrix_CreatePyObject(mat, mat1->row_size, mat1->col_size, Py_NEW, Py_TYPE(mat1));
+       return Matrix_CreatePyObject(mat, mat1->num_col, mat1->num_row, Py_NEW, Py_TYPE(mat1));
 }
 /*------------------------obj * obj------------------------------
   mulplication*/
 static PyObject *matrix_mul_float(MatrixObject *mat, const float scalar)
 {
        float tmat[16];
-       mul_vn_vn_fl(tmat, mat->contigPtr, mat->row_size * mat->col_size, scalar);
-       return Matrix_CreatePyObject(tmat, mat->row_size, mat->col_size, Py_NEW, Py_TYPE(mat));
+       mul_vn_vn_fl(tmat, mat->matrix, mat->num_col * mat->num_row, scalar);
+       return Matrix_CreatePyObject(tmat, mat->num_col, mat->num_row, Py_NEW, Py_TYPE(mat));
 }
 
 static PyObject *Matrix_mul(PyObject *m1, PyObject *m2)
@@ -1581,19 +1619,19 @@ static PyObject *Matrix_mul(PyObject *m1, PyObject *m2)
                                                0.0f, 0.0f, 0.0f, 0.0f,
                                                0.0f, 0.0f, 0.0f, 1.0f};
                double dot = 0.0f;
-               int x, y, z;
+               int col, row, item;
 
-               for (x = 0; x < mat2->row_size; x++) {
-                       for (y = 0; y < mat1->col_size; y++) {
-                               for (z = 0; z < mat1->row_size; z++) {
-                                       dot += MATRIX_ITEM(mat1, z, y) * MATRIX_ITEM(mat2, x, z);
+               for (col = 0; col < mat2->num_col; col++) {
+                       for (row = 0; row < mat1->num_row; row++) {
+                               for (item = 0; item < mat1->num_col; item++) {
+                                       dot += MATRIX_ITEM(mat1, row, item) * MATRIX_ITEM(mat2, item, col);
                                }
-                               mat[((x * mat1->col_size) + y)] = (float)dot;
+                               mat[((col * mat1->num_row) + row)] = (float)dot;
                                dot = 0.0f;
                        }
                }
 
-               return Matrix_CreatePyObject(mat, mat2->row_size, mat1->col_size, Py_NEW, Py_TYPE(mat1));
+               return Matrix_CreatePyObject(mat, mat2->num_col, mat1->num_row, Py_NEW, Py_TYPE(mat1));
        }
        else if (mat2) {
                /*FLOAT/INT * MATRIX */
@@ -1660,13 +1698,13 @@ static PyObject *Matrix_subscript(MatrixObject* self, PyObject* item)
                if (i == -1 && PyErr_Occurred())
                        return NULL;
                if (i < 0)
-                       i += self->row_size;
+                       i += self->num_col;
                return Matrix_item(self, i);
        }
        else if (PySlice_Check(item)) {
                Py_ssize_t start, stop, step, slicelength;
 
-               if (PySlice_GetIndicesEx((void *)item, self->row_size, &start, &stop, &step, &slicelength) < 0)
+               if (PySlice_GetIndicesEx((void *)item, self->num_col, &start, &stop, &step, &slicelength) < 0)
                        return NULL;
 
                if (slicelength <= 0) {
@@ -1696,13 +1734,13 @@ static int Matrix_ass_subscript(MatrixObject* self, PyObject* item, PyObject* va
                if (i == -1 && PyErr_Occurred())
                        return -1;
                if (i < 0)
-                       i += self->row_size;
+                       i += self->num_col;
                return Matrix_ass_item(self, i, value);
        }
        else if (PySlice_Check(item)) {
                Py_ssize_t start, stop, step, slicelength;
 
-               if (PySlice_GetIndicesEx((void *)item, self->row_size, &start, &stop, &step, &slicelength) < 0)
+               if (PySlice_GetIndicesEx((void *)item, self->num_col, &start, &stop, &step, &slicelength) < 0)
                        return -1;
 
                if (step == 1)
@@ -1767,12 +1805,12 @@ static PyNumberMethods Matrix_NumMethods = {
 
 static PyObject *Matrix_getRowSize(MatrixObject *self, void *UNUSED(closure))
 {
-       return PyLong_FromLong((long) self->row_size);
+       return PyLong_FromLong((long) self->num_col);
 }
 
 static PyObject *Matrix_getColSize(MatrixObject *self, void *UNUSED(closure))
 {
-       return PyLong_FromLong((long) self->col_size);
+       return PyLong_FromLong((long) self->num_row);
 }
 
 static PyObject *Matrix_median_scale_get(MatrixObject *self, void *UNUSED(closure))
@@ -1783,7 +1821,7 @@ static PyObject *Matrix_median_scale_get(MatrixObject *self, void *UNUSED(closur
                return NULL;
 
        /*must be 3-4 cols, 3-4 rows, square matrix*/
-       if ((self->col_size < 3) || (self->row_size < 3)) {
+       if ((self->num_row < 3) || (self->num_col < 3)) {
                PyErr_SetString(PyExc_AttributeError,
                                "Matrix.median_scale: "
                                "inappropriate matrix size, 3x3 minimum");
@@ -1801,10 +1839,10 @@ static PyObject *Matrix_is_negative_get(MatrixObject *self, void *UNUSED(closure
                return NULL;
 
        /*must be 3-4 cols, 3-4 rows, square matrix*/
-       if (self->col_size == 4 && self->row_size == 4)
-               return PyBool_FromLong(is_negative_m4((float (*)[4])self->contigPtr));
-       else if (self->col_size == 3 && self->row_size == 3)
-               return PyBool_FromLong(is_negative_m3((float (*)[3])self->contigPtr));
+       if (self->num_row == 4 && self->num_col == 4)
+               return PyBool_FromLong(is_negative_m4((float (*)[4])self->matrix));
+       else if (self->num_row == 3 && self->num_col == 3)
+               return PyBool_FromLong(is_negative_m3((float (*)[3])self->matrix));
        else {
                PyErr_SetString(PyExc_AttributeError,
                                "Matrix.is_negative: "
@@ -1819,10 +1857,10 @@ static PyObject *Matrix_is_orthogonal_get(MatrixObject *self, void *UNUSED(closu
                return NULL;
 
        /*must be 3-4 cols, 3-4 rows, square matrix*/
-       if (self->col_size == 4 && self->row_size == 4)
-               return PyBool_FromLong(is_orthogonal_m4((float (*)[4])self->contigPtr));
-       else if (self->col_size == 3 && self->row_size == 3)
-               return PyBool_FromLong(is_orthogonal_m3((float (*)[3])self->contigPtr));
+       if (self->num_row == 4 && self->num_col == 4)
+               return PyBool_FromLong(is_orthogonal_m4((float (*)[4])self->matrix));
+       else if (self->num_row == 3 && self->num_col == 3)
+               return PyBool_FromLong(is_orthogonal_m3((float (*)[3])self->matrix));
        else {
                PyErr_SetString(PyExc_AttributeError,
                                "Matrix.is_orthogonal: "
@@ -1906,7 +1944,7 @@ PyTypeObject matrix_Type = {
        &Matrix_AsMapping,                                      /*tp_as_mapping*/
        NULL,                                                           /*tp_hash*/
        NULL,                                                           /*tp_call*/
-       NULL,                                                           /*tp_str*/
+       (reprfunc) Matrix_str,                          /*tp_str*/
        NULL,                                                           /*tp_getattro*/
        NULL,                                                           /*tp_setattro*/
        NULL,                                                           /*tp_as_buffer*/
@@ -1944,37 +1982,37 @@ PyTypeObject matrix_Type = {
  * pass Py_NEW - if vector is not a WRAPPER and managed by PYTHON
  * (i.e. it must be created here with PyMEM_malloc()) */
 PyObject *Matrix_CreatePyObject(float *mat,
-                                const unsigned short row_size, const unsigned short col_size,
+                                const unsigned short num_col, const unsigned short num_row,
                                 int type, PyTypeObject *base_type)
 {
        MatrixObject *self;
 
        /* matrix objects can be any 2-4row x 2-4col matrix */
-       if (row_size < 2 || row_size > 4 || col_size < 2 || col_size > 4) {
+       if (num_col < 2 || num_col > 4 || num_row < 2 || num_row > 4) {
                PyErr_SetString(PyExc_RuntimeError,
                                "Matrix(): "
                                "row and column sizes must be between 2 and 4");
                return NULL;
        }
 
-       self= base_type ?       (MatrixObject *)base_type->tp_alloc(base_type, 0) :
-                                               (MatrixObject *)PyObject_GC_New(MatrixObject, &matrix_Type);
+       self= base_type ? (MatrixObject *)base_type->tp_alloc(base_type, 0) :
+                         (MatrixObject *)PyObject_GC_New(MatrixObject, &matrix_Type);
 
        if (self) {
-               self->row_size = row_size;
-               self->col_size = col_size;
+               self->num_col = num_col;
+               self->num_row = num_row;
 
                /* init callbacks as NULL */
                self->cb_user= NULL;
                self->cb_type= self->cb_subtype= 0;
 
                if (type == Py_WRAP) {
-                       self->contigPtr = mat;
+                       self->matrix = mat;
                        self->wrapped = Py_WRAP;
                }
                else if (type == Py_NEW) {
-                       self->contigPtr = PyMem_Malloc(row_size * col_size * sizeof(float));
-                       if (self->contigPtr == NULL) { /*allocation failure*/
+                       self->matrix = PyMem_Malloc(num_col * num_row * sizeof(float));
+                       if (self->matrix == NULL) { /*allocation failure*/
                                PyErr_SetString(PyExc_MemoryError,
                                                "Matrix(): "
                                                "problem allocating pointer space");
@@ -1982,16 +2020,16 @@ PyObject *Matrix_CreatePyObject(float *mat,
                        }
 
                        if (mat) {      /*if a float array passed*/
-                               memcpy(self->contigPtr, mat, row_size * col_size * sizeof(float));
+                               memcpy(self->matrix, mat, num_col * num_row * sizeof(float));
                        }
-                       else if (row_size == col_size) {
+                       else if (num_col == num_row) {
                                /* or if no arguments are passed return identity matrix for square matrices */
                                PyObject *ret_dummy= Matrix_identity(self);
                                Py_DECREF(ret_dummy);
                        }
                        else {
                                /* otherwise zero everything */
-                               memset(self->contigPtr, 0, row_size * col_size * sizeof(float));
+                               memset(self->matrix, 0, num_col * num_row * sizeof(float));
                        }
                        self->wrapped = Py_NEW;
                }
index 95768febca0c3d1c803f03ce5b6544d9554b90ca..91a276b648e84b85f58952e58f836a003e114984 100644 (file)
@@ -41,22 +41,22 @@ extern PyTypeObject matrix_Type;
 /* matrix[row][col] == MATRIX_ITEM_INDEX(matrix, row, col) */
 
 #ifdef DEBUG
-#  define MATRIX_ITEM_ASSERT(_mat, _row, _col) (BLI_assert(_row < (_mat)->row_size && _col < (_mat)->col_size))
+#  define MATRIX_ITEM_ASSERT(_mat, _row, _col) (BLI_assert(_row < (_mat)->num_row && _col < (_mat)->num_col))
 #else
 #  define MATRIX_ITEM_ASSERT(_mat, _row, _col) (void)0
 #endif
 
-#define MATRIX_ITEM_INDEX(_mat, _row, _col) (MATRIX_ITEM_ASSERT(_mat, _row, _col),(((_mat)->col_size * (_row)) + (_col)))
-#define MATRIX_ITEM_PTR(  _mat, _row, _col) ((_mat)->contigPtr + MATRIX_ITEM_INDEX(_mat, _row, _col))
-#define MATRIX_ITEM(      _mat, _row, _col) ((_mat)->contigPtr  [MATRIX_ITEM_INDEX(_mat, _row, _col)])
+#define MATRIX_ITEM_INDEX(_mat, _row, _col) (MATRIX_ITEM_ASSERT(_mat, _row, _col),(((_mat)->num_row * (_col)) + (_row)))
+#define MATRIX_ITEM_PTR(  _mat, _row, _col) ((_mat)->matrix + MATRIX_ITEM_INDEX(_mat, _row, _col))
+#define MATRIX_ITEM(      _mat, _row, _col) ((_mat)->matrix  [MATRIX_ITEM_INDEX(_mat, _row, _col)])
 
-#define MATRIX_ROW_INDEX(_mat, _row) (MATRIX_ITEM_INDEX(_mat, _row, 0))
-#define MATRIX_ROW_PTR(  _mat, _row) ((_mat)->contigPtr + MATRIX_ROW_INDEX(_mat, _row))
+#define MATRIX_COL_INDEX(_mat, _col) (MATRIX_ITEM_INDEX(_mat, 0, _col))
+#define MATRIX_COL_PTR(  _mat, _col) ((_mat)->matrix + MATRIX_COL_INDEX(_mat, _col))
 
 typedef struct {
-       BASE_MATH_MEMBERS(contigPtr);
-       unsigned short row_size;
-       unsigned short col_size;
+       BASE_MATH_MEMBERS(matrix);
+       unsigned short num_col;
+       unsigned short num_row;
 } MatrixObject;
 
 /* struct data contains a pointer to the actual data that the
@@ -66,9 +66,9 @@ typedef struct {
 
 /* prototypes */
 PyObject *Matrix_CreatePyObject(float *mat,
-                                const unsigned short row_size, const unsigned short col_size,
+                                const unsigned short num_col, const unsigned short num_row,
                                 int type, PyTypeObject *base_type);
-PyObject *Matrix_CreatePyObject_cb(PyObject *user, int row_size, int col_size, int cb_type, int cb_subtype);
+PyObject *Matrix_CreatePyObject_cb(PyObject *user, int num_col, int num_row, int cb_type, int cb_subtype);
 
 extern int mathutils_matrix_vector_cb_index;
 extern struct Mathutils_Callback mathutils_matrix_vector_cb;
index 7ab9b7b07138094a4042f6aa520fc1a04cc779f0..7c339807ee9d57e55ef21471282a1a9e0750ae96 100644 (file)
@@ -35,6 +35,7 @@
 
 #include "BLI_math.h"
 #include "BLI_utildefines.h"
+#include "BLI_dynstr.h"
 
 #define QUAT_SIZE 4
 
@@ -493,6 +494,21 @@ static PyObject *Quaternion_repr(QuaternionObject *self)
        return ret;
 }
 
+static PyObject *Quaternion_str(QuaternionObject *self)
+{
+       DynStr *ds;
+
+       if (BaseMath_ReadCallback(self) == -1)
+               return NULL;
+
+       ds= BLI_dynstr_new();
+
+       BLI_dynstr_appendf(ds, "<Quaternion (w=%.4f, x=%.4f, y=%.4f, z=%.4f)>",
+                          self->quat[0], self->quat[1], self->quat[2], self->quat[3]);
+
+       return mathutils_dynstr_to_py(ds); /* frees ds */
+}
+
 static PyObject* Quaternion_richcmpr(PyObject *a, PyObject *b, int op)
 {
        PyObject *res;
@@ -1167,7 +1183,7 @@ PyTypeObject quaternion_Type = {
        &Quaternion_AsMapping,                  //tp_as_mapping
        NULL,                                                           //tp_hash
        NULL,                                                           //tp_call
-       NULL,                                                           //tp_str
+       (reprfunc) Quaternion_str,                      //tp_str
        NULL,                                                           //tp_getattro
        NULL,                                                           //tp_setattro
        NULL,                                                           //tp_as_buffer
index aedf60e71918f11ab3ba1266a0855df1c5172a26..25760910c4ee0d59f5724f7b958b338ff999f1e9 100644 (file)
@@ -35,6 +35,7 @@
 
 #include "BLI_math.h"
 #include "BLI_utildefines.h"
+#include "BLI_dynstr.h"
 
 #define MAX_DIMENSIONS 4
 
@@ -1171,6 +1172,29 @@ static PyObject *Vector_repr(VectorObject *self)
        return ret;
 }
 
+static PyObject *Vector_str(VectorObject *self)
+{
+       int i;
+
+       DynStr *ds;
+
+       if (BaseMath_ReadCallback(self) == -1)
+               return NULL;
+
+       ds= BLI_dynstr_new();
+
+       BLI_dynstr_append(ds, "<Vector (");
+
+       for (i = 0; i < self->size; i++) {
+               BLI_dynstr_appendf(ds, i ? ", %.4f" : "%.4f", self->vec[i]);
+       }
+
+       BLI_dynstr_append(ds, ")>");
+
+       return mathutils_dynstr_to_py(ds); /* frees ds */
+}
+
+
 /* Sequence Protocol */
 /* sequence length len(vector) */
 static int Vector_len(VectorObject *self)
@@ -1468,8 +1492,8 @@ int column_vector_multiplication(float rvec[MAX_DIMENSIONS], VectorObject* vec,
        double dot = 0.0f;
        int x, y, z = 0;
 
-       if (mat->row_size != vec->size) {
-               if (mat->row_size == 4 && vec->size == 3) {
+       if (mat->num_col != vec->size) {
+               if (mat->num_col == 4 && vec->size == 3) {
                        vec_cpy[3] = 1.0f;
                }
                else {
@@ -1485,8 +1509,8 @@ int column_vector_multiplication(float rvec[MAX_DIMENSIONS], VectorObject* vec,
 
        rvec[3] = 1.0f;
 
-       for (x = 0; x < mat->col_size; x++) {
-               for (y = 0; y < mat->row_size; y++) {
+       for (x = 0; x < mat->num_row; x++) {
+               for (y = 0; y < mat->num_col; y++) {
                        dot += (double)(MATRIX_ITEM(mat, y, x) * vec_cpy[y]);
                }
                rvec[z++] = (float)dot;
@@ -2589,8 +2613,8 @@ static int row_vector_multiplication(float rvec[MAX_DIMENSIONS], VectorObject *v
        double dot = 0.0f;
        int x, y, z= 0, vec_size= vec->size;
 
-       if (mat->col_size != vec_size) {
-               if (mat->col_size == 4 && vec_size != 3) {
+       if (mat->num_row != vec_size) {
+               if (mat->num_row == 4 && vec_size != 3) {
                        PyErr_SetString(PyExc_ValueError,
                                        "vector * matrix: matrix column size "
                                        "and the vector size must be the same");
@@ -2608,8 +2632,8 @@ static int row_vector_multiplication(float rvec[MAX_DIMENSIONS], VectorObject *v
 
        rvec[3] = 1.0f;
        //muliplication
-       for (x = 0; x < mat->row_size; x++) {
-               for (y = 0; y < mat->col_size; y++) {
+       for (x = 0; x < mat->num_col; x++) {
+               for (y = 0; y < mat->num_row; y++) {
                        dot += MATRIX_ITEM(mat, x, y) * vec_cpy[y];
                }
                rvec[z++] = (float)dot;
@@ -2715,7 +2739,7 @@ PyTypeObject vector_Type = {
 
        NULL,                       /* hashfunc tp_hash; */
        NULL,                       /* ternaryfunc tp_call; */
-       NULL,                       /* reprfunc tp_str; */
+       (reprfunc)Vector_str,       /* reprfunc tp_str; */
        NULL,                       /* getattrofunc tp_getattro; */
        NULL,                       /* setattrofunc tp_setattro; */
 
index 360a082b03b302e470aaaa4f7b457634410477a4..445f2b8f0ba8f6ef1d9558fa8195fa42d7b18e20 100644 (file)
@@ -241,6 +241,7 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *c
                ketsjiengine->SetUseFixedTime(usefixed);
                ketsjiengine->SetTimingDisplay(frameRate, profile, properties);
                ketsjiengine->SetRestrictAnimationFPS(restrictAnimFPS);
+               KX_KetsjiEngine::SetExitKey(ConvertKeyCode(startscene->gm.exitkey));
 
                //set the global settings (carried over if restart/load new files)
                ketsjiengine->SetGlobalSettings(&gs);
index 1c91f498d32d390f65a31788f1e8c1115489ece6..93bf133635d26cd298fc7457f74603ee5b8dbc1b 100644 (file)
@@ -41,6 +41,7 @@
 #include "wm_event_types.h"
 #include "WM_types.h"
 #include "SCA_IInputDevice.h"
+#include "BL_BlenderDataConversion.h"
 
 #ifdef WITH_CXX_GUARDEDALLOC
 #include "MEM_guardedalloc.h"
 */
 class BL_BlenderInputDevice : public SCA_IInputDevice
 {
-       // this map is Blender specific: a conversion between blender and ketsji enums
-       std::map<int,KX_EnumInputs> m_reverseKeyTranslateTable;
 public:
        BL_BlenderInputDevice()
        {
-
-               /* The reverse table. In order to not confuse ourselves, we      */
-               /* immediately convert all events that come in to KX codes.      */
-               m_reverseKeyTranslateTable[LEFTMOUSE                    ] =     KX_LEFTMOUSE;
-               m_reverseKeyTranslateTable[MIDDLEMOUSE                  ] =     KX_MIDDLEMOUSE;
-               m_reverseKeyTranslateTable[RIGHTMOUSE                   ] =     KX_RIGHTMOUSE;
-               m_reverseKeyTranslateTable[WHEELUPMOUSE                 ] =     KX_WHEELUPMOUSE;
-               m_reverseKeyTranslateTable[WHEELDOWNMOUSE               ] =     KX_WHEELDOWNMOUSE;
-               m_reverseKeyTranslateTable[MOUSEX                       ] =     KX_MOUSEX;
-               m_reverseKeyTranslateTable[MOUSEY                       ] =     KX_MOUSEY;
-
-               // TIMERS
-
-               m_reverseKeyTranslateTable[TIMER0                           ] = KX_TIMER0;
-               m_reverseKeyTranslateTable[TIMER1                           ] = KX_TIMER1;
-               m_reverseKeyTranslateTable[TIMER2                           ] = KX_TIMER2;
-
-               // SYSTEM
-#if 0
-               /* **** XXX **** */
-               m_reverseKeyTranslateTable[KEYBD                            ] = KX_KEYBD;
-               m_reverseKeyTranslateTable[RAWKEYBD                         ] = KX_RAWKEYBD;
-               m_reverseKeyTranslateTable[REDRAW                           ] = KX_REDRAW;
-               m_reverseKeyTranslateTable[INPUTCHANGE                      ] = KX_INPUTCHANGE;
-               m_reverseKeyTranslateTable[QFULL                            ] = KX_QFULL;
-               m_reverseKeyTranslateTable[WINFREEZE                        ] = KX_WINFREEZE;
-               m_reverseKeyTranslateTable[WINTHAW                          ] = KX_WINTHAW;
-               m_reverseKeyTranslateTable[WINCLOSE                         ] = KX_WINCLOSE;
-               m_reverseKeyTranslateTable[WINQUIT                          ] = KX_WINQUIT;
-               m_reverseKeyTranslateTable[Q_FIRSTTIME                      ] = KX_Q_FIRSTTIME;
-               /* **** XXX **** */
-#endif
-               // standard keyboard
-
-               m_reverseKeyTranslateTable[AKEY                             ] = KX_AKEY;
-               m_reverseKeyTranslateTable[BKEY                             ] = KX_BKEY;
-               m_reverseKeyTranslateTable[CKEY                             ] = KX_CKEY;
-               m_reverseKeyTranslateTable[DKEY                             ] = KX_DKEY;
-               m_reverseKeyTranslateTable[EKEY                             ] = KX_EKEY;
-               m_reverseKeyTranslateTable[FKEY                             ] = KX_FKEY;
-               m_reverseKeyTranslateTable[GKEY                             ] = KX_GKEY;
-               //XXX clean up
-#ifdef WIN32
-#define HKEY   'h'
-#endif
-               m_reverseKeyTranslateTable[HKEY                             ] = KX_HKEY;
-               //XXX clean up
-#ifdef WIN32
-#undef HKEY
-#endif
-               m_reverseKeyTranslateTable[IKEY                             ] = KX_IKEY;
-               m_reverseKeyTranslateTable[JKEY                             ] = KX_JKEY;
-               m_reverseKeyTranslateTable[KKEY                             ] = KX_KKEY;
-               m_reverseKeyTranslateTable[LKEY                             ] = KX_LKEY;
-               m_reverseKeyTranslateTable[MKEY                             ] = KX_MKEY;
-               m_reverseKeyTranslateTable[NKEY                             ] = KX_NKEY;
-               m_reverseKeyTranslateTable[OKEY                             ] = KX_OKEY;
-               m_reverseKeyTranslateTable[PKEY                             ] = KX_PKEY;
-               m_reverseKeyTranslateTable[QKEY                             ] = KX_QKEY;
-               m_reverseKeyTranslateTable[RKEY                             ] = KX_RKEY;
-               m_reverseKeyTranslateTable[SKEY                             ] = KX_SKEY;
-               m_reverseKeyTranslateTable[TKEY                             ] = KX_TKEY;
-               m_reverseKeyTranslateTable[UKEY                             ] = KX_UKEY;
-               m_reverseKeyTranslateTable[VKEY                             ] = KX_VKEY;
-               m_reverseKeyTranslateTable[WKEY                             ] = KX_WKEY;
-               m_reverseKeyTranslateTable[XKEY                             ] = KX_XKEY;
-               m_reverseKeyTranslateTable[YKEY                             ] = KX_YKEY;
-               m_reverseKeyTranslateTable[ZKEY                             ] = KX_ZKEY;
-
-               m_reverseKeyTranslateTable[ZEROKEY                              ] = KX_ZEROKEY;
-               m_reverseKeyTranslateTable[ONEKEY                               ] = KX_ONEKEY;
-               m_reverseKeyTranslateTable[TWOKEY                               ] = KX_TWOKEY;
-               m_reverseKeyTranslateTable[THREEKEY                     ] = KX_THREEKEY;
-               m_reverseKeyTranslateTable[FOURKEY                              ] = KX_FOURKEY;
-               m_reverseKeyTranslateTable[FIVEKEY                              ] = KX_FIVEKEY;
-               m_reverseKeyTranslateTable[SIXKEY                               ] = KX_SIXKEY;
-               m_reverseKeyTranslateTable[SEVENKEY                         ] = KX_SEVENKEY;
-               m_reverseKeyTranslateTable[EIGHTKEY                         ] = KX_EIGHTKEY;
-               m_reverseKeyTranslateTable[NINEKEY                              ] = KX_NINEKEY;
-
-               m_reverseKeyTranslateTable[CAPSLOCKKEY                      ] = KX_CAPSLOCKKEY;
-
-               m_reverseKeyTranslateTable[LEFTCTRLKEY                  ] = KX_LEFTCTRLKEY;
-               m_reverseKeyTranslateTable[LEFTALTKEY                   ] = KX_LEFTALTKEY;
-               m_reverseKeyTranslateTable[RIGHTALTKEY                  ] = KX_RIGHTALTKEY;
-               m_reverseKeyTranslateTable[RIGHTCTRLKEY                         ] = KX_RIGHTCTRLKEY;
-               m_reverseKeyTranslateTable[RIGHTSHIFTKEY                        ] = KX_RIGHTSHIFTKEY;
-               m_reverseKeyTranslateTable[LEFTSHIFTKEY                     ] = KX_LEFTSHIFTKEY;
-
-               m_reverseKeyTranslateTable[ESCKEY                           ] = KX_ESCKEY;
-               m_reverseKeyTranslateTable[TABKEY                           ] = KX_TABKEY;
-               m_reverseKeyTranslateTable[RETKEY                           ] = KX_RETKEY;
-               m_reverseKeyTranslateTable[SPACEKEY                         ] = KX_SPACEKEY;
-               m_reverseKeyTranslateTable[LINEFEEDKEY                  ] = KX_LINEFEEDKEY;
-               m_reverseKeyTranslateTable[BACKSPACEKEY                     ] = KX_BACKSPACEKEY;
-               m_reverseKeyTranslateTable[DELKEY                           ] = KX_DELKEY;
-               m_reverseKeyTranslateTable[SEMICOLONKEY                     ] = KX_SEMICOLONKEY;
-               m_reverseKeyTranslateTable[PERIODKEY                    ] = KX_PERIODKEY;
-               m_reverseKeyTranslateTable[COMMAKEY                             ] = KX_COMMAKEY;
-               m_reverseKeyTranslateTable[QUOTEKEY                             ] = KX_QUOTEKEY;
-               m_reverseKeyTranslateTable[ACCENTGRAVEKEY                       ] = KX_ACCENTGRAVEKEY;
-               m_reverseKeyTranslateTable[MINUSKEY                             ] = KX_MINUSKEY;
-               m_reverseKeyTranslateTable[SLASHKEY                             ] = KX_SLASHKEY;
-               m_reverseKeyTranslateTable[BACKSLASHKEY                     ] = KX_BACKSLASHKEY;
-               m_reverseKeyTranslateTable[EQUALKEY                             ] = KX_EQUALKEY;
-               m_reverseKeyTranslateTable[LEFTBRACKETKEY                       ] = KX_LEFTBRACKETKEY;
-               m_reverseKeyTranslateTable[RIGHTBRACKETKEY                      ] = KX_RIGHTBRACKETKEY;
-
-               m_reverseKeyTranslateTable[LEFTARROWKEY                     ] = KX_LEFTARROWKEY;
-               m_reverseKeyTranslateTable[DOWNARROWKEY                     ] = KX_DOWNARROWKEY;
-               m_reverseKeyTranslateTable[RIGHTARROWKEY                        ] = KX_RIGHTARROWKEY;
-               m_reverseKeyTranslateTable[UPARROWKEY                   ] = KX_UPARROWKEY;
-
-               m_reverseKeyTranslateTable[PAD2                         ] = KX_PAD2;
-               m_reverseKeyTranslateTable[PAD4                         ] = KX_PAD4;
-               m_reverseKeyTranslateTable[PAD6                         ] = KX_PAD6;
-               m_reverseKeyTranslateTable[PAD8                         ] = KX_PAD8;
-
-               m_reverseKeyTranslateTable[PAD1                         ] = KX_PAD1;
-               m_reverseKeyTranslateTable[PAD3                         ] = KX_PAD3;
-               m_reverseKeyTranslateTable[PAD5                         ] = KX_PAD5;
-               m_reverseKeyTranslateTable[PAD7                         ] = KX_PAD7;
-               m_reverseKeyTranslateTable[PAD9                         ] = KX_PAD9;
-
-               m_reverseKeyTranslateTable[PADPERIOD                        ] = KX_PADPERIOD;
-               m_reverseKeyTranslateTable[PADSLASHKEY                    ] = KX_PADSLASHKEY;
-               m_reverseKeyTranslateTable[PADASTERKEY                      ] = KX_PADASTERKEY;
-
-
-               m_reverseKeyTranslateTable[PAD0                         ] = KX_PAD0;
-               m_reverseKeyTranslateTable[PADMINUS                         ] = KX_PADMINUS;
-               m_reverseKeyTranslateTable[PADENTER                         ] = KX_PADENTER;
-               m_reverseKeyTranslateTable[PADPLUSKEY                       ] = KX_PADPLUSKEY;
-
-
-               m_reverseKeyTranslateTable[F1KEY                            ] = KX_F1KEY;
-               m_reverseKeyTranslateTable[F2KEY                            ] = KX_F2KEY;
-               m_reverseKeyTranslateTable[F3KEY                            ] = KX_F3KEY;
-               m_reverseKeyTranslateTable[F4KEY                            ] = KX_F4KEY;
-               m_reverseKeyTranslateTable[F5KEY                            ] = KX_F5KEY;
-               m_reverseKeyTranslateTable[F6KEY                            ] = KX_F6KEY;
-               m_reverseKeyTranslateTable[F7KEY                            ] = KX_F7KEY;
-               m_reverseKeyTranslateTable[F8KEY                            ] = KX_F8KEY;
-               m_reverseKeyTranslateTable[F9KEY                            ] = KX_F9KEY;
-               m_reverseKeyTranslateTable[F10KEY                           ] = KX_F10KEY;
-               m_reverseKeyTranslateTable[F11KEY      ] = KX_F11KEY;
-               m_reverseKeyTranslateTable[F12KEY      ] = KX_F12KEY;
-               m_reverseKeyTranslateTable[F13KEY      ] = KX_F13KEY;
-               m_reverseKeyTranslateTable[F14KEY      ] = KX_F14KEY;
-               m_reverseKeyTranslateTable[F15KEY      ] = KX_F15KEY;
-               m_reverseKeyTranslateTable[F16KEY      ] = KX_F16KEY;
-               m_reverseKeyTranslateTable[F17KEY      ] = KX_F17KEY;
-               m_reverseKeyTranslateTable[F18KEY      ] = KX_F18KEY;
-               m_reverseKeyTranslateTable[F19KEY      ] = KX_F19KEY;
-
-               m_reverseKeyTranslateTable[PAUSEKEY    ] = KX_PAUSEKEY;
-               m_reverseKeyTranslateTable[INSERTKEY   ] = KX_INSERTKEY;
-               m_reverseKeyTranslateTable[HOMEKEY     ] = KX_HOMEKEY;
-               m_reverseKeyTranslateTable[PAGEUPKEY   ] = KX_PAGEUPKEY;
-               m_reverseKeyTranslateTable[PAGEDOWNKEY ] = KX_PAGEDOWNKEY;
-               m_reverseKeyTranslateTable[ENDKEY      ] = KX_ENDKEY;
        }
 
        virtual ~BL_BlenderInputDevice()
@@ -225,7 +63,7 @@ public:
        }
 
        KX_EnumInputs ToNative(unsigned short incode) {
-               return m_reverseKeyTranslateTable[incode];
+                return ConvertKeyCode(incode);
        }
 
        virtual bool    IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode)=0;
index a6712c531fb8e420c9b0471f7856e41859d06c26..54c60096812c33387051117ad1950ceb2e45b2d6 100644 (file)
@@ -36,6 +36,7 @@
 #endif 
 
 #include "KX_BlenderKeyboardDevice.h"
+#include "KX_KetsjiEngine.h"
 
 KX_BlenderKeyboardDevice::KX_BlenderKeyboardDevice()
        : m_hookesc(false)
@@ -106,7 +107,7 @@ bool        KX_BlenderKeyboardDevice::ConvertBlenderEvent(unsigned short incode,short v
 
                if (val == KM_PRESS)
                {
-                       if (kxevent == KX_ESCKEY && val != 0 && !m_hookesc)
+                       if (kxevent == KX_KetsjiEngine::GetExitKey() && val != 0 && !m_hookesc)
                                result = true;
                        if (kxevent == KX_PAUSEKEY && val && (IsPressed(KX_LEFTCTRLKEY) || IsPressed(KX_RIGHTCTRLKEY)))
                                result = true;
index 63a01db2fe0959b6d0024d5477f7f4691aeb165d..3039e69efcdd36894bf50e9173100e91155616c8 100644 (file)
@@ -50,6 +50,8 @@ public:
        virtual bool    ConvertBlenderEvent(unsigned short incode,short val);
        virtual void    NextFrame();
        virtual void    HookEscape();
+private:
+       short           m_exit_key;
 
 
 #ifdef WITH_CXX_GUARDEDALLOC
index 95ae75917763021ac256a8b2e1e329fa56a35bde..821cb746b65b74bda70c82170ceec6d937069611 100644 (file)
@@ -197,6 +197,180 @@ extern "C" {
 
 static bool default_light_mode = 0;
 
+static std::map<int, SCA_IInputDevice::KX_EnumInputs> create_translate_table()
+{
+       std::map<int, SCA_IInputDevice::KX_EnumInputs> m;
+               
+       /* The reverse table. In order to not confuse ourselves, we      */
+       /* immediately convert all events that come in to KX codes.      */
+       m[LEFTMOUSE                     ] =     SCA_IInputDevice::KX_LEFTMOUSE;
+       m[MIDDLEMOUSE           ] =     SCA_IInputDevice::KX_MIDDLEMOUSE;
+       m[RIGHTMOUSE            ] =     SCA_IInputDevice::KX_RIGHTMOUSE;
+       m[WHEELUPMOUSE          ] =     SCA_IInputDevice::KX_WHEELUPMOUSE;
+       m[WHEELDOWNMOUSE        ] =     SCA_IInputDevice::KX_WHEELDOWNMOUSE;
+       m[MOUSEX                        ] = SCA_IInputDevice::KX_MOUSEX;
+       m[MOUSEY                        ] =     SCA_IInputDevice::KX_MOUSEY;
+               
+       // TIMERS                                                                                                  
+               
+       m[TIMER0                        ] = SCA_IInputDevice::KX_TIMER0;                  
+       m[TIMER1                        ] = SCA_IInputDevice::KX_TIMER1;                  
+       m[TIMER2                        ] = SCA_IInputDevice::KX_TIMER2;                  
+               
+       // SYSTEM                                                                                                  
+               
+#if 0                  
+       /* **** XXX **** */
+       m[KEYBD                         ] = SCA_IInputDevice::KX_KEYBD;                  
+       m[RAWKEYBD                      ] = SCA_IInputDevice::KX_RAWKEYBD;                  
+       m[REDRAW                        ] = SCA_IInputDevice::KX_REDRAW;                  
+       m[INPUTCHANGE           ] = SCA_IInputDevice::KX_INPUTCHANGE;                  
+       m[QFULL                         ] = SCA_IInputDevice::KX_QFULL;                  
+       m[WINFREEZE                     ] = SCA_IInputDevice::KX_WINFREEZE;                  
+       m[WINTHAW                       ] = SCA_IInputDevice::KX_WINTHAW;                  
+       m[WINCLOSE                      ] = SCA_IInputDevice::KX_WINCLOSE;                  
+       m[WINQUIT                       ] = SCA_IInputDevice::KX_WINQUIT;                  
+       m[Q_FIRSTTIME           ] = SCA_IInputDevice::KX_Q_FIRSTTIME;                  
+       /* **** XXX **** */
+#endif 
+               
+       // standard keyboard                                                                                       
+               
+       m[AKEY                          ] = SCA_IInputDevice::KX_AKEY;                  
+       m[BKEY                          ] = SCA_IInputDevice::KX_BKEY;                  
+       m[CKEY                          ] = SCA_IInputDevice::KX_CKEY;                  
+       m[DKEY                          ] = SCA_IInputDevice::KX_DKEY;                  
+       m[EKEY                          ] = SCA_IInputDevice::KX_EKEY;                  
+       m[FKEY                          ] = SCA_IInputDevice::KX_FKEY;                  
+       m[GKEY                          ] = SCA_IInputDevice::KX_GKEY;                  
+
+//XXX clean up
+#ifdef WIN32
+#define HKEY   'h'
+#endif
+       m[HKEY                          ] = SCA_IInputDevice::KX_HKEY;                  
+//XXX clean up
+#ifdef WIN32
+#undef HKEY
+#endif
+
+       m[IKEY                          ] = SCA_IInputDevice::KX_IKEY;                  
+       m[JKEY                          ] = SCA_IInputDevice::KX_JKEY;                  
+       m[KKEY                          ] = SCA_IInputDevice::KX_KKEY;                  
+       m[LKEY                          ] = SCA_IInputDevice::KX_LKEY;                  
+       m[MKEY                          ] = SCA_IInputDevice::KX_MKEY;                  
+       m[NKEY                          ] = SCA_IInputDevice::KX_NKEY;                  
+       m[OKEY                          ] = SCA_IInputDevice::KX_OKEY;                  
+       m[PKEY                          ] = SCA_IInputDevice::KX_PKEY;                  
+       m[QKEY                          ] = SCA_IInputDevice::KX_QKEY;                  
+       m[RKEY                          ] = SCA_IInputDevice::KX_RKEY;                  
+       m[SKEY                          ] = SCA_IInputDevice::KX_SKEY;                  
+       m[TKEY                          ] = SCA_IInputDevice::KX_TKEY;                  
+       m[UKEY                          ] = SCA_IInputDevice::KX_UKEY;                  
+       m[VKEY                          ] = SCA_IInputDevice::KX_VKEY;                  
+       m[WKEY                          ] = SCA_IInputDevice::KX_WKEY;                  
+       m[XKEY                          ] = SCA_IInputDevice::KX_XKEY;                  
+       m[YKEY                          ] = SCA_IInputDevice::KX_YKEY;                  
+       m[ZKEY                          ] = SCA_IInputDevice::KX_ZKEY;                  
+               
+       m[ZEROKEY                       ] = SCA_IInputDevice::KX_ZEROKEY;                  
+       m[ONEKEY                        ] = SCA_IInputDevice::KX_ONEKEY;                  
+       m[TWOKEY                        ] = SCA_IInputDevice::KX_TWOKEY;                  
+       m[THREEKEY                      ] = SCA_IInputDevice::KX_THREEKEY;                  
+       m[FOURKEY                       ] = SCA_IInputDevice::KX_FOURKEY;                  
+       m[FIVEKEY                       ] = SCA_IInputDevice::KX_FIVEKEY;                  
+       m[SIXKEY                        ] = SCA_IInputDevice::KX_SIXKEY;                  
+       m[SEVENKEY                      ] = SCA_IInputDevice::KX_SEVENKEY;                  
+       m[EIGHTKEY                      ] = SCA_IInputDevice::KX_EIGHTKEY;                  
+       m[NINEKEY                       ] = SCA_IInputDevice::KX_NINEKEY;                  
+               
+       m[CAPSLOCKKEY           ] = SCA_IInputDevice::KX_CAPSLOCKKEY;                  
+               
+       m[LEFTCTRLKEY           ] = SCA_IInputDevice::KX_LEFTCTRLKEY;                  
+       m[LEFTALTKEY            ] = SCA_IInputDevice::KX_LEFTALTKEY;                  
+       m[RIGHTALTKEY           ] = SCA_IInputDevice::KX_RIGHTALTKEY;                  
+       m[RIGHTCTRLKEY          ] = SCA_IInputDevice::KX_RIGHTCTRLKEY;                  
+       m[RIGHTSHIFTKEY         ] = SCA_IInputDevice::KX_RIGHTSHIFTKEY;                  
+       m[LEFTSHIFTKEY          ] = SCA_IInputDevice::KX_LEFTSHIFTKEY;                  
+               
+       m[ESCKEY                        ] = SCA_IInputDevice::KX_ESCKEY;                  
+       m[TABKEY                        ] = SCA_IInputDevice::KX_TABKEY;                  
+       m[RETKEY                        ] = SCA_IInputDevice::KX_RETKEY;                  
+       m[SPACEKEY                      ] = SCA_IInputDevice::KX_SPACEKEY;                  
+       m[LINEFEEDKEY           ] = SCA_IInputDevice::KX_LINEFEEDKEY;                  
+       m[BACKSPACEKEY          ] = SCA_IInputDevice::KX_BACKSPACEKEY;                  
+       m[DELKEY                        ] = SCA_IInputDevice::KX_DELKEY;                  
+       m[SEMICOLONKEY          ] = SCA_IInputDevice::KX_SEMICOLONKEY;                  
+       m[PERIODKEY                     ] = SCA_IInputDevice::KX_PERIODKEY;                  
+       m[COMMAKEY                      ] = SCA_IInputDevice::KX_COMMAKEY;                  
+       m[QUOTEKEY                      ] = SCA_IInputDevice::KX_QUOTEKEY;                  
+       m[ACCENTGRAVEKEY        ] = SCA_IInputDevice::KX_ACCENTGRAVEKEY;                  
+       m[MINUSKEY                      ] = SCA_IInputDevice::KX_MINUSKEY;                  
+       m[SLASHKEY                      ] = SCA_IInputDevice::KX_SLASHKEY;                  
+       m[BACKSLASHKEY          ] = SCA_IInputDevice::KX_BACKSLASHKEY;                  
+       m[EQUALKEY                      ] = SCA_IInputDevice::KX_EQUALKEY;                  
+       m[LEFTBRACKETKEY        ] = SCA_IInputDevice::KX_LEFTBRACKETKEY;                  
+       m[RIGHTBRACKETKEY       ] = SCA_IInputDevice::KX_RIGHTBRACKETKEY;                  
+               
+       m[LEFTARROWKEY          ] = SCA_IInputDevice::KX_LEFTARROWKEY;                  
+       m[DOWNARROWKEY          ] = SCA_IInputDevice::KX_DOWNARROWKEY;                  
+       m[RIGHTARROWKEY         ] = SCA_IInputDevice::KX_RIGHTARROWKEY;                  
+       m[UPARROWKEY            ] = SCA_IInputDevice::KX_UPARROWKEY;                  
+               
+       m[PAD2                          ] = SCA_IInputDevice::KX_PAD2;                  
+       m[PAD4                          ] = SCA_IInputDevice::KX_PAD4;                  
+       m[PAD6                          ] = SCA_IInputDevice::KX_PAD6;                  
+       m[PAD8                          ] = SCA_IInputDevice::KX_PAD8;                  
+               
+       m[PAD1                          ] = SCA_IInputDevice::KX_PAD1;                  
+       m[PAD3                          ] = SCA_IInputDevice::KX_PAD3;                  
+       m[PAD5                          ] = SCA_IInputDevice::KX_PAD5;                  
+       m[PAD7                          ] = SCA_IInputDevice::KX_PAD7;                  
+       m[PAD9                          ] = SCA_IInputDevice::KX_PAD9;                  
+               
+       m[PADPERIOD                     ] = SCA_IInputDevice::KX_PADPERIOD;                  
+       m[PADSLASHKEY           ] = SCA_IInputDevice::KX_PADSLASHKEY;                  
+       m[PADASTERKEY           ] = SCA_IInputDevice::KX_PADASTERKEY;                  
+               
+       m[PAD0                          ] = SCA_IInputDevice::KX_PAD0;                  
+       m[PADMINUS                      ] = SCA_IInputDevice::KX_PADMINUS;                  
+       m[PADENTER                      ] = SCA_IInputDevice::KX_PADENTER;                  
+       m[PADPLUSKEY            ] = SCA_IInputDevice::KX_PADPLUSKEY;                  
+               
+               
+       m[F1KEY                         ] = SCA_IInputDevice::KX_F1KEY;                  
+       m[F2KEY                         ] = SCA_IInputDevice::KX_F2KEY;                  
+       m[F3KEY                         ] = SCA_IInputDevice::KX_F3KEY;                  
+       m[F4KEY                         ] = SCA_IInputDevice::KX_F4KEY;                  
+       m[F5KEY                         ] = SCA_IInputDevice::KX_F5KEY;                  
+       m[F6KEY                         ] = SCA_IInputDevice::KX_F6KEY;                  
+       m[F7KEY                         ] = SCA_IInputDevice::KX_F7KEY;                  
+       m[F8KEY                         ] = SCA_IInputDevice::KX_F8KEY;                  
+       m[F9KEY                         ] = SCA_IInputDevice::KX_F9KEY;                  
+       m[F10KEY                        ] = SCA_IInputDevice::KX_F10KEY;                  
+       m[F11KEY                        ] = SCA_IInputDevice::KX_F11KEY;                  
+       m[F12KEY                        ] = SCA_IInputDevice::KX_F12KEY;
+       m[F13KEY                        ] = SCA_IInputDevice::KX_F13KEY;
+       m[F14KEY                        ] = SCA_IInputDevice::KX_F14KEY;
+       m[F15KEY                        ] = SCA_IInputDevice::KX_F15KEY;
+       m[F16KEY                        ] = SCA_IInputDevice::KX_F16KEY;
+       m[F17KEY                        ] = SCA_IInputDevice::KX_F17KEY;
+       m[F18KEY                        ] = SCA_IInputDevice::KX_F18KEY;
+       m[F19KEY                        ] = SCA_IInputDevice::KX_F19KEY;
+               
+               
+       m[PAUSEKEY                      ] = SCA_IInputDevice::KX_PAUSEKEY;                  
+       m[INSERTKEY                     ] = SCA_IInputDevice::KX_INSERTKEY;                  
+       m[HOMEKEY                       ] = SCA_IInputDevice::KX_HOMEKEY;                  
+       m[PAGEUPKEY                     ] = SCA_IInputDevice::KX_PAGEUPKEY;                  
+       m[PAGEDOWNKEY           ] = SCA_IInputDevice::KX_PAGEDOWNKEY;                  
+       m[ENDKEY                        ] = SCA_IInputDevice::KX_ENDKEY;
+
+       return m;
+}
+
+static std::map<int, SCA_IInputDevice::KX_EnumInputs> gReverseKeyTranslateTable = create_translate_table();
+
 static unsigned int KX_rgbaint2uint_new(unsigned int icol)
 {
        union
@@ -2854,3 +3028,8 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
        RAS_BucketManager *bucketmanager = kxscene->GetBucketManager();
        bucketmanager->OptimizeBuckets(distance);
 }
+
+SCA_IInputDevice::KX_EnumInputs ConvertKeyCode(int key_code)
+{
+       return gReverseKeyTranslateTable[key_code];
+}
\ No newline at end of file
index 2ae7fee1798209bf73a2951dfedc2fbb8428a60a..6da3ac90aef5ff9312822af15ae298321362b5a8 100644 (file)
@@ -36,6 +36,7 @@
 #include "STR_String.h"
 #include "KX_Python.h"
 #include "KX_PhysicsEngineEnums.h"
+#include "SCA_IInputDevice.h"
 
 class RAS_MeshObject* BL_ConvertMesh(struct Mesh* mesh,struct Object* lightobj,class KX_Scene* scene, class KX_BlenderSceneConverter *converter);
 
@@ -49,5 +50,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
                                                          bool alwaysUseExpandFraming
                                                          );
 
+SCA_IInputDevice::KX_EnumInputs ConvertKeyCode(int key_code);
+
 #endif // __BLENDER_CONVERT
 
index b7aee8ec92404d3de288080e5db0c9690bd890b8..9391d12a3ce22c693f3276461aaab31ae6300200 100644 (file)
@@ -86,10 +86,7 @@ probably misplaced */
 
 #include "KX_KetsjiEngine.h"
 #include "KX_BlenderSceneConverter.h"
-
-// this map is Blender specific: a conversion between blender and ketsji enums
-std::map<int,SCA_IInputDevice::KX_EnumInputs> gReverseKeyTranslateTable;
-
+#include "BL_BlenderDataConversion.h"
 
 void BL_ConvertSensors(struct Object* blenderobject,
                                           class KX_GameObject* gameobj,
@@ -102,177 +99,6 @@ void BL_ConvertSensors(struct Object* blenderobject,
                                           KX_BlenderSceneConverter* converter
                                           )
 {
-       static bool reverseTableConverted = false;      
-       
-       if (!reverseTableConverted)
-       {
-               reverseTableConverted = true;
-               
-               /* The reverse table. In order to not confuse ourselves, we      */
-               /* immediately convert all events that come in to KX codes.      */
-               gReverseKeyTranslateTable[LEFTMOUSE                     ] =     SCA_IInputDevice::KX_LEFTMOUSE;
-               gReverseKeyTranslateTable[MIDDLEMOUSE           ] =     SCA_IInputDevice::KX_MIDDLEMOUSE;
-               gReverseKeyTranslateTable[RIGHTMOUSE            ] =     SCA_IInputDevice::KX_RIGHTMOUSE;
-               gReverseKeyTranslateTable[WHEELUPMOUSE          ] =     SCA_IInputDevice::KX_WHEELUPMOUSE;
-               gReverseKeyTranslateTable[WHEELDOWNMOUSE        ] =     SCA_IInputDevice::KX_WHEELDOWNMOUSE;
-               gReverseKeyTranslateTable[MOUSEX                        ] = SCA_IInputDevice::KX_MOUSEX;
-               gReverseKeyTranslateTable[MOUSEY                        ] =     SCA_IInputDevice::KX_MOUSEY;
-               
-               // TIMERS                                                                                                  
-               
-               gReverseKeyTranslateTable[TIMER0                        ] = SCA_IInputDevice::KX_TIMER0;                  
-               gReverseKeyTranslateTable[TIMER1                        ] = SCA_IInputDevice::KX_TIMER1;                  
-               gReverseKeyTranslateTable[TIMER2                        ] = SCA_IInputDevice::KX_TIMER2;                  
-               
-               // SYSTEM                                                                                                  
-               
-#if 0                  
-               /* **** XXX **** */
-               gReverseKeyTranslateTable[KEYBD                         ] = SCA_IInputDevice::KX_KEYBD;                  
-               gReverseKeyTranslateTable[RAWKEYBD                      ] = SCA_IInputDevice::KX_RAWKEYBD;                  
-               gReverseKeyTranslateTable[REDRAW                        ] = SCA_IInputDevice::KX_REDRAW;                  
-               gReverseKeyTranslateTable[INPUTCHANGE           ] = SCA_IInputDevice::KX_INPUTCHANGE;                  
-               gReverseKeyTranslateTable[QFULL                         ] = SCA_IInputDevice::KX_QFULL;                  
-               gReverseKeyTranslateTable[WINFREEZE                     ] = SCA_IInputDevice::KX_WINFREEZE;                  
-               gReverseKeyTranslateTable[WINTHAW                       ] = SCA_IInputDevice::KX_WINTHAW;                  
-               gReverseKeyTranslateTable[WINCLOSE                      ] = SCA_IInputDevice::KX_WINCLOSE;                  
-               gReverseKeyTranslateTable[WINQUIT                       ] = SCA_IInputDevice::KX_WINQUIT;                  
-               gReverseKeyTranslateTable[Q_FIRSTTIME           ] = SCA_IInputDevice::KX_Q_FIRSTTIME;                  
-               /* **** XXX **** */
-#endif 
-               
-               // standard keyboard                                                                                       
-               
-               gReverseKeyTranslateTable[AKEY                          ] = SCA_IInputDevice::KX_AKEY;                  
-               gReverseKeyTranslateTable[BKEY                          ] = SCA_IInputDevice::KX_BKEY;                  
-               gReverseKeyTranslateTable[CKEY                          ] = SCA_IInputDevice::KX_CKEY;                  
-               gReverseKeyTranslateTable[DKEY                          ] = SCA_IInputDevice::KX_DKEY;                  
-               gReverseKeyTranslateTable[EKEY                          ] = SCA_IInputDevice::KX_EKEY;                  
-               gReverseKeyTranslateTable[FKEY                          ] = SCA_IInputDevice::KX_FKEY;                  
-               gReverseKeyTranslateTable[GKEY                          ] = SCA_IInputDevice::KX_GKEY;                  
-
-//XXX clean up
-#ifdef WIN32
-#define HKEY   'h'
-#endif
-               gReverseKeyTranslateTable[HKEY                          ] = SCA_IInputDevice::KX_HKEY;                  
-//XXX clean up
-#ifdef WIN32
-#undef HKEY
-#endif
-
-               gReverseKeyTranslateTable[IKEY                          ] = SCA_IInputDevice::KX_IKEY;                  
-               gReverseKeyTranslateTable[JKEY                          ] = SCA_IInputDevice::KX_JKEY;                  
-               gReverseKeyTranslateTable[KKEY                          ] = SCA_IInputDevice::KX_KKEY;                  
-               gReverseKeyTranslateTable[LKEY                          ] = SCA_IInputDevice::KX_LKEY;                  
-               gReverseKeyTranslateTable[MKEY                          ] = SCA_IInputDevice::KX_MKEY;                  
-               gReverseKeyTranslateTable[NKEY                          ] = SCA_IInputDevice::KX_NKEY;                  
-               gReverseKeyTranslateTable[OKEY                          ] = SCA_IInputDevice::KX_OKEY;                  
-               gReverseKeyTranslateTable[PKEY                          ] = SCA_IInputDevice::KX_PKEY;                  
-               gReverseKeyTranslateTable[QKEY                          ] = SCA_IInputDevice::KX_QKEY;                  
-               gReverseKeyTranslateTable[RKEY                          ] = SCA_IInputDevice::KX_RKEY;                  
-               gReverseKeyTranslateTable[SKEY                          ] = SCA_IInputDevice::KX_SKEY;                  
-               gReverseKeyTranslateTable[TKEY                          ] = SCA_IInputDevice::KX_TKEY;                  
-               gReverseKeyTranslateTable[UKEY                          ] = SCA_IInputDevice::KX_UKEY;                  
-               gReverseKeyTranslateTable[VKEY                          ] = SCA_IInputDevice::KX_VKEY;                  
-               gReverseKeyTranslateTable[WKEY                          ] = SCA_IInputDevice::KX_WKEY;                  
-               gReverseKeyTranslateTable[XKEY                          ] = SCA_IInputDevice::KX_XKEY;                  
-               gReverseKeyTranslateTable[YKEY                          ] = SCA_IInputDevice::KX_YKEY;                  
-               gReverseKeyTranslateTable[ZKEY                          ] = SCA_IInputDevice::KX_ZKEY;                  
-               
-               gReverseKeyTranslateTable[ZEROKEY                       ] = SCA_IInputDevice::KX_ZEROKEY;                  
-               gReverseKeyTranslateTable[ONEKEY                        ] = SCA_IInputDevice::KX_ONEKEY;                  
-               gReverseKeyTranslateTable[TWOKEY                        ] = SCA_IInputDevice::KX_TWOKEY;                  
-               gReverseKeyTranslateTable[THREEKEY                      ] = SCA_IInputDevice::KX_THREEKEY;                  
-               gReverseKeyTranslateTable[FOURKEY                       ] = SCA_IInputDevice::KX_FOURKEY;                  
-               gReverseKeyTranslateTable[FIVEKEY                       ] = SCA_IInputDevice::KX_FIVEKEY;                  
-               gReverseKeyTranslateTable[SIXKEY                        ] = SCA_IInputDevice::KX_SIXKEY;                  
-               gReverseKeyTranslateTable[SEVENKEY                      ] = SCA_IInputDevice::KX_SEVENKEY;                  
-               gReverseKeyTranslateTable[EIGHTKEY                      ] = SCA_IInputDevice::KX_EIGHTKEY;                  
-               gReverseKeyTranslateTable[NINEKEY                       ] = SCA_IInputDevice::KX_NINEKEY;                  
-               
-               gReverseKeyTranslateTable[CAPSLOCKKEY           ] = SCA_IInputDevice::KX_CAPSLOCKKEY;                  
-               
-               gReverseKeyTranslateTable[LEFTCTRLKEY           ] = SCA_IInputDevice::KX_LEFTCTRLKEY;                  
-               gReverseKeyTranslateTable[LEFTALTKEY            ] = SCA_IInputDevice::KX_LEFTALTKEY;                  
-               gReverseKeyTranslateTable[RIGHTALTKEY           ] = SCA_IInputDevice::KX_RIGHTALTKEY;                  
-               gReverseKeyTranslateTable[RIGHTCTRLKEY          ] = SCA_IInputDevice::KX_RIGHTCTRLKEY;                  
-               gReverseKeyTranslateTable[RIGHTSHIFTKEY         ] = SCA_IInputDevice::KX_RIGHTSHIFTKEY;                  
-               gReverseKeyTranslateTable[LEFTSHIFTKEY          ] = SCA_IInputDevice::KX_LEFTSHIFTKEY;                  
-               
-               gReverseKeyTranslateTable[ESCKEY                        ] = SCA_IInputDevice::KX_ESCKEY;                  
-               gReverseKeyTranslateTable[TABKEY                        ] = SCA_IInputDevice::KX_TABKEY;                  
-               gReverseKeyTranslateTable[RETKEY                        ] = SCA_IInputDevice::KX_RETKEY;                  
-               gReverseKeyTranslateTable[SPACEKEY                      ] = SCA_IInputDevice::KX_SPACEKEY;                  
-               gReverseKeyTranslateTable[LINEFEEDKEY           ] = SCA_IInputDevice::KX_LINEFEEDKEY;                  
-               gReverseKeyTranslateTable[BACKSPACEKEY          ] = SCA_IInputDevice::KX_BACKSPACEKEY;                  
-               gReverseKeyTranslateTable[DELKEY                        ] = SCA_IInputDevice::KX_DELKEY;                  
-               gReverseKeyTranslateTable[SEMICOLONKEY          ] = SCA_IInputDevice::KX_SEMICOLONKEY;                  
-               gReverseKeyTranslateTable[PERIODKEY                     ] = SCA_IInputDevice::KX_PERIODKEY;                  
-               gReverseKeyTranslateTable[COMMAKEY                      ] = SCA_IInputDevice::KX_COMMAKEY;                  
-               gReverseKeyTranslateTable[QUOTEKEY                      ] = SCA_IInputDevice::KX_QUOTEKEY;                  
-               gReverseKeyTranslateTable[ACCENTGRAVEKEY        ] = SCA_IInputDevice::KX_ACCENTGRAVEKEY;                  
-               gReverseKeyTranslateTable[MINUSKEY                      ] = SCA_IInputDevice::KX_MINUSKEY;                  
-               gReverseKeyTranslateTable[SLASHKEY                      ] = SCA_IInputDevice::KX_SLASHKEY;                  
-               gReverseKeyTranslateTable[BACKSLASHKEY          ] = SCA_IInputDevice::KX_BACKSLASHKEY;                  
-               gReverseKeyTranslateTable[EQUALKEY                      ] = SCA_IInputDevice::KX_EQUALKEY;                  
-               gReverseKeyTranslateTable[LEFTBRACKETKEY        ] = SCA_IInputDevice::KX_LEFTBRACKETKEY;                  
-               gReverseKeyTranslateTable[RIGHTBRACKETKEY       ] = SCA_IInputDevice::KX_RIGHTBRACKETKEY;                  
-               
-               gReverseKeyTranslateTable[LEFTARROWKEY          ] = SCA_IInputDevice::KX_LEFTARROWKEY;                  
-               gReverseKeyTranslateTable[DOWNARROWKEY          ] = SCA_IInputDevice::KX_DOWNARROWKEY;                  
-               gReverseKeyTranslateTable[RIGHTARROWKEY         ] = SCA_IInputDevice::KX_RIGHTARROWKEY;                  
-               gReverseKeyTranslateTable[UPARROWKEY            ] = SCA_IInputDevice::KX_UPARROWKEY;                  
-               
-               gReverseKeyTranslateTable[PAD2                          ] = SCA_IInputDevice::KX_PAD2;                  
-               gReverseKeyTranslateTable[PAD4                          ] = SCA_IInputDevice::KX_PAD4;                  
-               gReverseKeyTranslateTable[PAD6                          ] = SCA_IInputDevice::KX_PAD6;                  
-               gReverseKeyTranslateTable[PAD8                          ] = SCA_IInputDevice::KX_PAD8;                  
-               
-               gReverseKeyTranslateTable[PAD1                          ] = SCA_IInputDevice::KX_PAD1;                  
-               gReverseKeyTranslateTable[PAD3                          ] = SCA_IInputDevice::KX_PAD3;                  
-               gReverseKeyTranslateTable[PAD5                          ] = SCA_IInputDevice::KX_PAD5;                  
-               gReverseKeyTranslateTable[PAD7                          ] = SCA_IInputDevice::KX_PAD7;                  
-               gReverseKeyTranslateTable[PAD9                          ] = SCA_IInputDevice::KX_PAD9;                  
-               
-               gReverseKeyTranslateTable[PADPERIOD                     ] = SCA_IInputDevice::KX_PADPERIOD;                  
-               gReverseKeyTranslateTable[PADSLASHKEY           ] = SCA_IInputDevice::KX_PADSLASHKEY;                  
-               gReverseKeyTranslateTable[PADASTERKEY           ] = SCA_IInputDevice::KX_PADASTERKEY;                  
-               
-               gReverseKeyTranslateTable[PAD0                          ] = SCA_IInputDevice::KX_PAD0;                  
-               gReverseKeyTranslateTable[PADMINUS                      ] = SCA_IInputDevice::KX_PADMINUS;                  
-               gReverseKeyTranslateTable[PADENTER                      ] = SCA_IInputDevice::KX_PADENTER;                  
-               gReverseKeyTranslateTable[PADPLUSKEY            ] = SCA_IInputDevice::KX_PADPLUSKEY;                  
-               
-               
-               gReverseKeyTranslateTable[F1KEY                         ] = SCA_IInputDevice::KX_F1KEY;                  
-               gReverseKeyTranslateTable[F2KEY                         ] = SCA_IInputDevice::KX_F2KEY;                  
-               gReverseKeyTranslateTable[F3KEY                         ] = SCA_IInputDevice::KX_F3KEY;                  
-               gReverseKeyTranslateTable[F4KEY                         ] = SCA_IInputDevice::KX_F4KEY;                  
-               gReverseKeyTranslateTable[F5KEY                         ] = SCA_IInputDevice::KX_F5KEY;                  
-               gReverseKeyTranslateTable[F6KEY                         ] = SCA_IInputDevice::KX_F6KEY;                  
-               gReverseKeyTranslateTable[F7KEY                         ] = SCA_IInputDevice::KX_F7KEY;                  
-               gReverseKeyTranslateTable[F8KEY                         ] = SCA_IInputDevice::KX_F8KEY;                  
-               gReverseKeyTranslateTable[F9KEY                         ] = SCA_IInputDevice::KX_F9KEY;                  
-               gReverseKeyTranslateTable[F10KEY                        ] = SCA_IInputDevice::KX_F10KEY;                  
-               gReverseKeyTranslateTable[F11KEY                        ] = SCA_IInputDevice::KX_F11KEY;                  
-               gReverseKeyTranslateTable[F12KEY                        ] = SCA_IInputDevice::KX_F12KEY;
-               gReverseKeyTranslateTable[F13KEY                        ] = SCA_IInputDevice::KX_F13KEY;
-               gReverseKeyTranslateTable[F14KEY                        ] = SCA_IInputDevice::KX_F14KEY;
-               gReverseKeyTranslateTable[F15KEY                        ] = SCA_IInputDevice::KX_F15KEY;
-               gReverseKeyTranslateTable[F16KEY                        ] = SCA_IInputDevice::KX_F16KEY;
-               gReverseKeyTranslateTable[F17KEY                        ] = SCA_IInputDevice::KX_F17KEY;
-               gReverseKeyTranslateTable[F18KEY                        ] = SCA_IInputDevice::KX_F18KEY;
-               gReverseKeyTranslateTable[F19KEY                        ] = SCA_IInputDevice::KX_F19KEY;
-               
-               
-               gReverseKeyTranslateTable[PAUSEKEY                      ] = SCA_IInputDevice::KX_PAUSEKEY;                  
-               gReverseKeyTranslateTable[INSERTKEY                     ] = SCA_IInputDevice::KX_INSERTKEY;                  
-               gReverseKeyTranslateTable[HOMEKEY                       ] = SCA_IInputDevice::KX_HOMEKEY;                  
-               gReverseKeyTranslateTable[PAGEUPKEY                     ] = SCA_IInputDevice::KX_PAGEUPKEY;                  
-               gReverseKeyTranslateTable[PAGEDOWNKEY           ] = SCA_IInputDevice::KX_PAGEDOWNKEY;                  
-               gReverseKeyTranslateTable[ENDKEY                        ] = SCA_IInputDevice::KX_ENDKEY;
-       }
 
        int executePriority = 0;
        int uniqueint = 0;
@@ -470,9 +296,9 @@ void BL_ConvertSensors(struct Object* blenderobject,
                                if (eventmgr)
                                {
                                        gamesensor = new SCA_KeyboardSensor(eventmgr,
-                                               gReverseKeyTranslateTable[blenderkeybdsensor->key],
-                                               gReverseKeyTranslateTable[blenderkeybdsensor->qual],
-                                               gReverseKeyTranslateTable[blenderkeybdsensor->qual2],
+                                               ConvertKeyCode(blenderkeybdsensor->key),
+                                               ConvertKeyCode(blenderkeybdsensor->qual),
+                                               ConvertKeyCode(blenderkeybdsensor->qual2),
                                                (blenderkeybdsensor->type == SENS_ALL_KEYS),
                                                blenderkeybdsensor->targetName,
                                                blenderkeybdsensor->toggleName,
index 5b267c92908780790d1e9e8dd8856e0fec20b108..3d88dc467b066791aa5d99b988b695ebd92276c1 100644 (file)
@@ -57,6 +57,7 @@ protected:
         * System dependent keyboard codes are stored as ints.
         */
        std::map<int, KX_EnumInputs> m_reverseKeyTranslateTable;
+       short   m_exitkey;
 
 public:
        bool m_hookesc;
index 7490e18782473b5b8bbad396d671d88828979cd3..f9403c9725a93697a4aa507007ea32b23342bc83 100644 (file)
@@ -40,6 +40,7 @@
 #include "GPU_extensions.h"
 
 #include "GPG_Application.h"
+#include "BL_BlenderDataConversion.h"
 
 #include <iostream>
 #include <MT_assert.h>
@@ -626,6 +627,8 @@ bool GPG_Application::initEngine(GHOST_IWindow* window, const int stereoMode)
                m_ketsjiengine->SetRasterizer(m_rasterizer);
 
                m_ketsjiengine->SetTimingDisplay(frameRate, false, false);
+
+               KX_KetsjiEngine::SetExitKey(ConvertKeyCode(gm->exitkey));
 #ifdef WITH_PYTHON
                CValue::SetDeprecationWarnings(nodepwarnings);
 #else
@@ -908,12 +911,10 @@ bool GPG_Application::handleKey(GHOST_IEvent* event, bool isDown)
        {
                GHOST_TEventDataPtr eventData = ((GHOST_IEvent*)event)->getData();
                GHOST_TEventKeyData* keyData = static_cast<GHOST_TEventKeyData*>(eventData);
-               //no need for this test
-               //if (fSystem->getFullScreen()) {
-                       if (keyData->key == GHOST_kKeyEsc && !m_keyboard->m_hookesc && !m_isEmbedded) {
-                               m_exitRequested = KX_EXIT_REQUEST_OUTSIDE;
-                       }
-               //}
+
+               if (m_keyboard->ToNative(keyData->key) == KX_KetsjiEngine::GetExitKey() && !m_keyboard->m_hookesc && !m_isEmbedded) {
+                       m_exitRequested = KX_EXIT_REQUEST_OUTSIDE;
+               }
                m_keyboard->ConvertEvent(keyData->key, isDown);
                handled = true;
        }
index a8a976f9dd2b1af906324c83da945e05cf7e1dd5..37625dc8998b99f7213bcc841c2bd3b988361057 100644 (file)
@@ -103,6 +103,7 @@ protected:
         * Shuts the game engine down.
         */
        void exitEngine(void);
+       short                                   m_exitkey;
 
        /* The game data */
        STR_String                              m_startSceneName;
index a9be588e6b2e0df9b96413391ab2857fd0fec240..29727dc04da8863d1447797d489f7d8f70002b21 100644 (file)
@@ -110,6 +110,7 @@ double KX_KetsjiEngine::m_suspendedtime = 0.0;
 double KX_KetsjiEngine::m_suspendeddelta = 0.0;
 double KX_KetsjiEngine::m_average_framerate = 0.0;
 bool   KX_KetsjiEngine::m_restrict_anim_fps = false;
+short  KX_KetsjiEngine::m_exitkey = 130; //ESC Key
 
 
 /**
@@ -1857,6 +1858,16 @@ double KX_KetsjiEngine::GetAverageFrameRate()
        return m_average_framerate;
 }
 
+void KX_KetsjiEngine::SetExitKey(short key)
+{
+       m_exitkey = key;
+}
+
+short KX_KetsjiEngine::GetExitKey()
+{
+       return m_exitkey;
+}
+
 void KX_KetsjiEngine::SetTimingDisplay(bool frameRate, bool profile, bool properties)
 {
        m_show_framerate = frameRate;
index 5a02da07e4324ffdccd9ba62b1601ec893f4d41f..96b737b686df4b34a18e0af142fd001204d925f6 100644 (file)
@@ -124,6 +124,8 @@ private:
        static double                   m_suspendedtime;
        static double                   m_suspendeddelta;
 
+       static short                    m_exitkey; /* Key used to exit the BGE */
+
        int                                     m_exitcode;
        STR_String                      m_exitstring;
                /**
@@ -352,6 +354,10 @@ public:
         */
        static double GetAverageFrameRate();
 
+       static void SetExitKey(short key);
+
+       static short GetExitKey();
+
        /**
         * Activates or deactivates timing information display.
         * @param frameRate             Display for frame rate on or off.
index 29871c2b3cd53378e6a020fc89deb4d969681fd3..9a2c0cb89b149655bcd83b487c9ae0d804163ca8 100644 (file)
@@ -419,6 +419,20 @@ static PyObject* gPyGetLogicTicRate(PyObject*)
        return PyFloat_FromDouble(KX_KetsjiEngine::GetTicRate());
 }
 
+static PyObject* gPySetExitKey(PyObject*, PyObject* args)
+{
+       short exitkey;
+       if (!PyArg_ParseTuple(args, "h:setExitKey", &exitkey))
+               return NULL;
+       KX_KetsjiEngine::SetExitKey(exitkey);
+       Py_RETURN_NONE;
+}
+
+static PyObject* gPyGetExitKey(PyObject*)
+{
+       return PyLong_FromSsize_t(KX_KetsjiEngine::GetExitKey());
+}
+
 static PyObject* gPySetMaxLogicFrame(PyObject*, PyObject* args)
 {
        int frame;
@@ -812,6 +826,8 @@ static struct PyMethodDef game_methods[] = {
        {"setLogicTicRate", (PyCFunction) gPySetLogicTicRate, METH_VARARGS, (const char *)"Sets the logic tic rate"},
        {"getPhysicsTicRate", (PyCFunction) gPyGetPhysicsTicRate, METH_NOARGS, (const char *)"Gets the physics tic rate"},
        {"setPhysicsTicRate", (PyCFunction) gPySetPhysicsTicRate, METH_VARARGS, (const char *)"Sets the physics tic rate"},
+       {"getExitKey", (PyCFunction) gPyGetExitKey, METH_NOARGS, (const char *)"Gets the key used to exit the game engine"},
+       {"setExitKey", (PyCFunction) gPySetExitKey, METH_VARARGS, (const char *)"Sets the key used to exit the game engine"},
        {"getAverageFrameRate", (PyCFunction) gPyGetAverageFrameRate, METH_NOARGS, (const char *)"Gets the estimated average frame rate"},
        {"getBlendFileList", (PyCFunction)gPyGetBlendFileList, METH_VARARGS, (const char *)"Gets a list of blend files in the same directory as the current blend file"},
        {"PrintGLInfo", (PyCFunction)pyPrintExt, METH_NOARGS, (const char *)"Prints GL Extension Info"},
index 40d304ef4b9e5bb3a9ef18055039419aa1906e93..74a0ad1c628253b58ce626ba379816128dddf0b6 100644 (file)
@@ -60,6 +60,11 @@ add_test(script_run_operators ${TEST_BLENDER_EXE}
        --python ${CMAKE_CURRENT_LIST_DIR}/bl_run_operators.py
 )
 
+# test running mathutils testing script
+add_test(script_pyapi_mathutils ${TEST_BLENDER_EXE}
+       --python ${CMAKE_CURRENT_LIST_DIR}/bl_pyapi_mathutils.py
+)
+
 # ------------------------------------------------------------------------------
 # IO TESTS
 
diff --git a/source/tests/bl_pyapi_mathutils.py b/source/tests/bl_pyapi_mathutils.py
new file mode 100644 (file)
index 0000000..f1d6d96
--- /dev/null
@@ -0,0 +1,109 @@
+import unittest
+from test import support
+from mathutils import Matrix, Vector
+
+
+class MatrixTesting(unittest.TestCase):
+    def test_matrix_column_access(self):
+        #mat =
+        #[ 1  2  3  4 ]
+        #[ 1  2  3  4 ]
+        #[ 1  2  3  4 ]
+        mat = Matrix(((1, 11, 111),
+                      (2, 22, 222),
+                      (3, 33, 333),
+                      (4, 44, 444)))
+
+        self.assertEqual(mat[0], Vector((1, 11, 111)))
+        self.assertEqual(mat[1], Vector((2, 22, 222)))
+        self.assertEqual(mat[2], Vector((3, 33, 333)))
+        self.assertEqual(mat[3], Vector((4, 44, 444)))
+
+    def test_item_access(self):
+        args = ((1, 4, 0, -1),
+                (2, -1, 2, -2),
+                (0, 3, 8, 3),
+                (-2, 9, 1, 0))
+
+        mat = Matrix(args)
+
+        for i in range(4):
+            for j in range(4):
+                self.assertEqual(mat[i][j], args[i][j])
+
+        self.assertEqual(mat[0][2], 0)
+        self.assertEqual(mat[3][1], 9)
+        self.assertEqual(mat[2][3], 3)
+        self.assertEqual(mat[0][0], 1)
+        self.assertEqual(mat[3][3], 0)
+
+    def test_item_assignment(self):
+        mat = Matrix() - Matrix()
+        indices = (0, 0), (1, 3), (2, 0), (3, 2), (3, 1)
+        checked_indices = []
+        for col, row in indices:
+            mat[col][row] = 1
+
+        for col in range(4):
+            for row in range(4):
+                if mat[col][row]:
+                    checked_indices.append((col, row))
+
+        for item in checked_indices:
+            self.assertIn(item, indices)
+
+    def test_matrix_to_3x3(self):
+        #mat =
+        #[ 1  2  3  4  ]
+        #[ 2  4  6  8  ]
+        #[ 3  6  9  12 ]
+        #[ 4  8  12 16 ]
+        mat = Matrix(tuple((i, 2 * i, 3 * i, 4 * i) for i in range(1, 5)))
+        mat_correct = Matrix(((1, 2, 3), (2, 4, 6), (3, 6, 9)))
+        self.assertEqual(mat.to_3x3(), mat_correct)
+
+    def test_matrix_to_translation(self):
+        mat = Matrix()
+        mat[3] = (1, 2, 3, 4)
+        self.assertEqual(mat.to_translation(), Vector((1, 2, 3)))
+
+    def test_matrix_inverse(self):
+        mat = Matrix(((1, 4, 0, -1),
+                      (2, -1, 2, -2),
+                      (0, 3, 8, 3),
+                      (-2, 9, 1, 0)))
+
+        inv_mat = (1 / 285) * Matrix(((195, -57, 27, -102),
+                                      (50, -19, 4, 6),
+                                      (-60, 57, 18, 27),
+                                      (110, -133, 43, -78)))
+
+        self.assertEqual(mat.inverted(), inv_mat)
+
+    def test_matrix_mult(self):
+        mat = Matrix(((1, 4, 0, -1),
+                      (2, -1, 2, -2),
+                      (0, 3, 8, 3),
+                      (-2, 9, 1, 0)))
+
+        prod_mat = Matrix(((11, -9, 7, -9),
+                           (4, -3, 12, 6),
+                           (0, 48, 73, 18),
+                           (16, -14, 26, -13)))
+
+        self.assertEqual(mat * mat, prod_mat)
+
+
+def test_main():
+    try:
+        support.run_unittest(MatrixTesting)
+    except:
+        import traceback
+        traceback.print_exc()
+
+        # alert CTest we failed
+        import sys
+        sys.exit(1)
+
+if __name__ == '__main__':
+    test_main()