Revision: 20565
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20565
Author:   ben2610
Date:     2009-06-01 21:12:11 +0200 (Mon, 01 Jun 2009)

Log Message:
-----------
BGE: forgot to add files to go with rasterizer optimizations.

Added Paths:
-----------
    branches/bb_dev/source/gameengine/Ketsji/KX_MatrixFactory.cpp
    branches/bb_dev/source/gameengine/Ketsji/KX_MatrixFactory.h
    branches/bb_dev/source/gameengine/Rasterizer/RAS_IMatrixFactory.h

Added: branches/bb_dev/source/gameengine/Ketsji/KX_MatrixFactory.cpp
===================================================================
--- branches/bb_dev/source/gameengine/Ketsji/KX_MatrixFactory.cpp               
                (rev 0)
+++ branches/bb_dev/source/gameengine/Ketsji/KX_MatrixFactory.cpp       
2009-06-01 19:12:11 UTC (rev 20565)
@@ -0,0 +1,98 @@
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include "RAS_IRasterizer.h"
+#include "KX_GameObject.h"
+#include "KX_MatrixFactory.h"
+
+#include "BLI_arithb.h"
+
+void KX_MatrixFactory::UpdateModelMatrix()
+{
+       SG_Node* node = m_object->GetSGNode();
+       if (node && node->IsDirty()) {
+               const MT_Matrix3x3& rot = node->GetWorldOrientation();
+               const MT_Vector3& scaling = node->GetWorldScaling();
+
+               rot.getValue(m_model.getPointer());
+               m_model.SetScale(scaling);
+               m_model.SetPos(node->GetWorldPosition());
+               m_object->SetNegativeScaling(((scaling[0] < 0.0) ^ (scaling[1] 
< 0.0) ^ (scaling[2] < 0.0)) ? true : false);
+               // matrix is up to date
+               node->ClearDirty();
+               // this makes all other matrices dirty
+               m_dirtyFlags = RAS_MATRIX_INVMODEL_DIRTY;
+       }
+       // this function is only called during culling, assume view matrix is 
changing too
+       m_dirtyFlags |= 
RAS_MATRIX_VIEWMODEL_DIRTY|RAS_MATRIX_INVVIEWMODEL_DIRTY;
+}
+
+void KX_MatrixFactory::UpdateModelInvMatrix()
+{
+       SG_Node* node = m_object->GetSGNode();
+       if (node) {
+               // much faster to invert the matrix starting from the node than 
doing a straight 4x4 inverse
+               MT_Matrix3x3 rot = node->GetWorldOrientation();
+               MT_Vector3 scaling = node->GetWorldScaling();
+               // do we really have to worry about 0 scale?
+               scaling[0] = (MT_fuzzyZero(scaling[0])) ? 0.0 : 1.0/scaling[0];
+               scaling[1] = (MT_fuzzyZero(scaling[1])) ? 0.0 : 1.0/scaling[1];
+               scaling[2] = (MT_fuzzyZero(scaling[2])) ? 0.0 : 1.0/scaling[2];
+               rot.scale(scaling[0], scaling[1], scaling[2]);
+               rot.transpose();
+
+               rot.getValue(m_invModel->getPointer());
+               MT_Vector3 position = rot*node->GetWorldPosition();
+               position[0] = -position[0];
+               position[1] = -position[1];
+               position[2] = -position[2];
+               m_invModel->SetPos(position);
+       }
+       m_dirtyFlags &= ~RAS_MATRIX_INVMODEL_DIRTY;
+}
+
+void KX_MatrixFactory::UpdateViewModelMatrix(const RAS_IRasterizer* rasty)
+{
+       const MT_CmMatrix4x4& view = rasty->GetViewMatrix();
+       // let's use blender function, it's faster
+       Mat4MulMat4(m_viewModel->ToMat4(), m_model.ToMat4(), view.ToMat4());
+       m_dirtyFlags &= ~RAS_MATRIX_VIEWMODEL_DIRTY;
+}
+
+void KX_MatrixFactory::UpdateViewModelInvMatrix(const RAS_IRasterizer* rasty)
+{
+       const MT_CmMatrix4x4& invmodel = GetModelInvMatrix();
+       const MT_CmMatrix4x4& invview = rasty->GetViewInvMatrix();
+       // let's use blender function, it's faster
+       Mat4MulMat4(m_viewModel->ToMat4(), invview.ToMat4(), invmodel.ToMat4());
+       m_dirtyFlags &= ~RAS_MATRIX_VIEWMODEL_DIRTY;
+}
+
+
+


Property changes on: 
branches/bb_dev/source/gameengine/Ketsji/KX_MatrixFactory.cpp
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: branches/bb_dev/source/gameengine/Ketsji/KX_MatrixFactory.h
===================================================================
--- branches/bb_dev/source/gameengine/Ketsji/KX_MatrixFactory.h                 
        (rev 0)
+++ branches/bb_dev/source/gameengine/Ketsji/KX_MatrixFactory.h 2009-06-01 
19:12:11 UTC (rev 20565)
@@ -0,0 +1,67 @@
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+#ifndef __KX_MATRIXFACTORY
+#define __KX_MATRIXFACTORY
+
+#include "RAS_IMatrixFactory.h"
+
+class KX_GameObject;
+
+class KX_MatrixFactory : public RAS_IMatrixFactory
+{
+protected:
+       KX_GameObject*  m_object;
+
+       virtual void UpdateModelInvMatrix();
+       virtual void UpdateViewModelMatrix(const RAS_IRasterizer* rasty);
+       virtual void UpdateViewModelInvMatrix(const RAS_IRasterizer* rasty);
+
+public:
+       KX_MatrixFactory(KX_GameObject* object) :
+               RAS_IMatrixFactory(),
+               m_object(object)
+       {
+       };
+
+       virtual ~KX_MatrixFactory() 
+       {
+       };
+
+       void SetGameObject(KX_GameObject* object)
+       {
+               m_object = object;
+       }
+
+       virtual void UpdateModelMatrix();
+};
+
+#endif //__KX_MATRIXFACTORY
+
+
+


Property changes on: branches/bb_dev/source/gameengine/Ketsji/KX_MatrixFactory.h
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: branches/bb_dev/source/gameengine/Rasterizer/RAS_IMatrixFactory.h
===================================================================
--- branches/bb_dev/source/gameengine/Rasterizer/RAS_IMatrixFactory.h           
                (rev 0)
+++ branches/bb_dev/source/gameengine/Rasterizer/RAS_IMatrixFactory.h   
2009-06-01 19:12:11 UTC (rev 20565)
@@ -0,0 +1,133 @@
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+#ifndef __RAS_IMATRIXFACTORY
+#define __RAS_IMATRIXFACTORY
+
+#include "MT_CmMatrix4x4.h"
+
+class          RAS_IRasterizer;
+
+class RAS_IMatrixFactory
+{
+protected:
+       MT_CmMatrix4x4   m_model;               // this is the main openGL 
matrix
+       MT_CmMatrix4x4*  m_invModel;    // inverse or m_model, only allocated 
if needed
+       MT_CmMatrix4x4*  m_viewModel;   // = view matrix * model matrix, only 
allocated if needed
+       MT_CmMatrix4x4*  m_invViewModel;// = inverse of view matrix m_viewmodel
+
+       int                              m_dirtyFlags;  // flags 
+
+       enum RAS_MATRIX_DIRTY {
+               RAS_MATRIX_MODEL_DIRTY = 1,
+               RAS_MATRIX_INVMODEL_DIRTY = 2,
+               RAS_MATRIX_VIEWMODEL_DIRTY = 4,
+               RAS_MATRIX_INVVIEWMODEL_DIRTY = 8,
+               RAS_MATRIX_ALL_DIRTY = 15
+       };
+
+       virtual void UpdateModelInvMatrix() = 0;
+       virtual void UpdateViewModelMatrix(const RAS_IRasterizer* rasty) = 0;
+       virtual void UpdateViewModelInvMatrix(const RAS_IRasterizer* rasty) = 0;
+
+public:
+       enum RAS_MATRIX_MODE {
+               RAS_MATRIX_MODEL = 0,
+               RAS_MATRIX_INVMODEL,
+               RAS_MATRIX_VIWEWMODEL,
+               RAS_MATRIX_INVVIEWMODEL,
+       };
+
+       RAS_IMatrixFactory() :
+               m_invModel(NULL),
+               m_viewModel(NULL),
+               m_invViewModel(NULL),
+               m_dirtyFlags(RAS_MATRIX_ALL_DIRTY)
+       {
+       };
+
+       // copy constructor, needed for object replication
+       RAS_IMatrixFactory(const RAS_IMatrixFactory& other) :
+               m_model(other.m_model),
+               m_invModel(NULL),
+               m_viewModel(NULL),
+               m_invViewModel(NULL),
+               m_dirtyFlags(RAS_MATRIX_ALL_DIRTY)
+       {
+       }
+
+       virtual ~RAS_IMatrixFactory() 
+       {
+               if (m_invModel)
+                       delete m_invModel;
+               if (m_viewModel)
+                       delete m_viewModel;
+               if (m_invViewModel)
+                       delete m_invViewModel;
+       };
+
+       virtual void UpdateModelMatrix() = 0;
+
+       MT_CmMatrix4x4& GetModelMatrix()
+       {
+               // assume always up to date
+               return m_model;
+       }
+       MT_CmMatrix4x4& GetModelInvMatrix()
+       {
+               if (!(m_dirtyFlags & RAS_MATRIX_INVMODEL_DIRTY))
+                       return *m_invModel;
+               if (!m_invModel)
+                       m_invModel = new MT_CmMatrix4x4();
+               UpdateModelInvMatrix();
+               return *m_invModel;
+       }
+       MT_CmMatrix4x4& GetViewModelMatrix(const RAS_IRasterizer* rasty)
+       {
+               if (!(m_dirtyFlags & RAS_MATRIX_VIEWMODEL_DIRTY))
+                       return *m_viewModel;
+               if (!m_viewModel)
+                       m_viewModel = new MT_CmMatrix4x4();
+               UpdateViewModelMatrix(rasty);
+               return *m_viewModel;
+       }
+       MT_CmMatrix4x4& GetViewModelInvMatrix(const RAS_IRasterizer* rasty)
+       {
+               if (!(m_dirtyFlags & RAS_MATRIX_INVVIEWMODEL_DIRTY))
+                       return *m_invViewModel;
+               if (!m_invViewModel)
+                       m_invViewModel = new MT_CmMatrix4x4();
+               UpdateViewModelInvMatrix(rasty);
+               return *m_invViewModel;
+       }
+};
+
+#endif //__RAS_IMATRIXFACTORY
+
+
+


Property changes on: 
branches/bb_dev/source/gameengine/Rasterizer/RAS_IMatrixFactory.h
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native


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

Reply via email to