Commits

dbacchet committed d4123a7

ported the trackball manipulator improvements into the test7 prog

Comments (0)

Files changed (14)

3rdparty/chrome_event_trace/SConscript

 
 # build library
 chrome_tracing_lib  = env_local.StaticLibrary('chrome_tracing',files)
+
+# build library
+if sys.platform == 'win32':
+    prgfiles = Glob('win_test/*.c*')
+    env_local.AppendUnique(LIBS=[chrome_tracing_lib])
+    env_local.Program('chrome_tracing_test',prgfiles,PDB='chrome_tracing_test.pdb')
+
+
 Return('chrome_tracing_lib')
-

3rdparty/chrome_event_trace/event_trace_plat.h

 
 
 #include <time.h>
-#ifdef OS_WIN
+#ifdef _WIN32
 #include <windows.h>
 #elif defined(__GNUC__)
 #include <sys/time.h>
 typedef unsigned int uint32;
 
 
-#ifdef OS_WIN
+#ifdef _WIN32
 
 typedef __int64 int64;
 typedef unsigned __int64 uint64;
 ////////////////////////////////
 typedef unsigned long long timer_ticks;
 typedef  timer_ticks TimeTicks;
-#if defined(OS_WIN) 
+#if defined(_WIN32) 
 inline void query_counter(timer_ticks *pTicks){
    QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER*>(pTicks));
 }
 class Lock
 {
 
-#if defined(OS_WIN) 
+#if defined(_WIN32) 
 public:
 	Lock(){InitializeCriticalSectionAndSpinCount(&mCrit, 0); };
 	~Lock(){DeleteCriticalSection(&mCrit); };
 //threading
 inline uint32 getCurrentProcId()
 {
-#ifdef OS_WIN
+#ifdef _WIN32
 	return GetCurrentProcessId();
 #elif defined(__GNUC__)
 	return getpid();
 
 inline uint32 getCurrentThreadId()
 {
-#ifdef OS_WIN
+#ifdef _WIN32
 	return GetCurrentThreadId();
 #elif defined(__GNUC__)
 	return (size_t)pthread_self();

sources/opengl2_samples/test7_simplerenderer/GLMesh.cpp

 #include <vector>
 #include <string>
 
-#include "GLTransform.h"
 #include "GLMaterial.h"
 #include "GLMesh.h"
     

sources/opengl2_samples/test7_simplerenderer/GLMesh.h

 // ///////////////// //
 
 /// apply a transformation to the mesh nodes
-template <typename real_type>
-inline void applyTransform(GLMesh *mesh, const GLTransform<real_type> &tr)
+inline void applyTransform(GLMesh *mesh, const GLTransformf &tr)
 {
     Matrix4f M = tr.getTransformationMatrix();
     Matrix3f R = tr.getRotationMatrix();
 }
 
 
+/// apply a transformation to the mesh nodes
+inline void applyTransform(GLMesh *mesh, const Matrix4f &M)
+{
+    Matrix3f R;
+      R(1,1) = M(1,1); R(1,2) = M(1,2); R(1,3) = M(1,3); 
+      R(2,1) = M(2,1); R(2,2) = M(2,2); R(2,3) = M(2,3); 
+      R(3,1) = M(3,1); R(3,2) = M(3,2); R(3,3) = M(3,3); 
+    for(unsigned int k=0; k<mesh->submeshes.size(); k++)
+    {
+        for (unsigned int i=0; i<mesh->submeshes[k].vertices.size(); i++)
+        {
+            mesh->submeshes[k].vertices[i].pos  = M*mesh->submeshes[k].vertices[i].pos;
+            mesh->submeshes[k].vertices[i].norm = R*mesh->submeshes[k].vertices[i].norm;
+            mesh->submeshes[k].vertices[i].tang = R*mesh->submeshes[k].vertices[i].tang;
+        }
+    }
+}
+
+
 #endif //__GLMesh_H__
 

sources/opengl2_samples/test7_simplerenderer/GLMeshTools.cpp

 #include "aiScene.h"
 
 #include "vmath.h"
-#include "mathutils.h"
 #include "vertex.h"
 #include "GLMesh.h"
 #include "GLMaterial.h"

sources/opengl2_samples/test7_simplerenderer/GLRenderer.cpp

 }
 
 
+// add some data to render, applying a transformation
+bool GLRenderer::addRenderData( const std::string &shaderName, const std::string &materialName,
+                                const std::vector<Vertex_t> &vert, const std::vector<unsigned int> &ind,
+                                const Matrix4f &tr )
+{
+    std::vector<Vertex_t> trvert = vert;
+    Matrix3f Rot;
+      Rot(1,1) = tr(1,1); Rot(1,2) = tr(1,2); Rot(1,3) = tr(1,3); 
+      Rot(2,1) = tr(2,1); Rot(2,2) = tr(2,2); Rot(2,3) = tr(2,3); 
+      Rot(3,1) = tr(3,1); Rot(3,2) = tr(3,2); Rot(3,3) = tr(3,3); 
+    for (unsigned int i=0; i<vert.size(); i++)
+    {
+        trvert[i].pos  = tr*vert[i].pos;
+        trvert[i].norm = Rot*vert[i].norm;
+        trvert[i].tang = Rot*vert[i].tang;
+    }
+
+    return addRenderData(shaderName, materialName, trvert, ind);
+}
+
+
 
 GLCamera *__cam;
 // render a batch

sources/opengl2_samples/test7_simplerenderer/GLRenderer.h

     virtual ~GLRenderer()
     {}
     
-    // /// register a shader in the renderer map  
-    // unsigned int registerShader( GLShader *sh );
-    // /// register a material in the renderer map  
-    // unsigned int registerMaterial( GLMaterial *mat );
-
-
-    // /// lookup for registered shaders  
-    // GLShader*   getShader( unsigned int id );
-    // /// lookup for registered materials
-    // GLMaterial* getMaterial( unsigned int id );
-
     /// add some data to render
     bool addRenderData( const std::string &shaderName, const std::string &materialName,
                         const std::vector<Vertex_t> &vert, const std::vector<unsigned int> &ind );
+    /// add some data to render, applying a transformation
+    bool addRenderData( const std::string &shaderName, const std::string &materialName,
+                        const std::vector<Vertex_t> &vert, const std::vector<unsigned int> &ind,
+                        const Matrix4f &tr );
 
     /// render all the current batches
     bool render( GLCamera *cam );

sources/opengl2_samples/test7_simplerenderer/GLTrackball.h

     /// standard constructor
     GLTrackball()
     : screenRadius(1.0)
-    {}
+    {
+        incremRot.identity();
+        currentRot.identity();
+    }
     /// destructor
     virtual ~GLTrackball()
     {}
         angle = 0.0;
         axis = Vector3<real_type>();
         // set transf matrices
-        anchorTransf = currentTransf;   // to keep previous transform
-        incremTransf.identity();
-        currentTransf.identity();
+        anchorRot = currentRot;   // to keep previous transform
         // set anchor pos on sphere
         anchor = projectOnSurface(x,y);
         current = anchor;
     {
         current = projectOnSurface(x,y);
         computeIncremental();
+        currentRot = incremRot*anchorRot;
     }
     
     /// get current transformation
     Matrix4<real_type> getRotation( void ) 
     {
-        currentTransf = incremTransf*anchorTransf;  // current transform is updated here to prevent trasforms when not asked by the applications
-        return currentTransf;
+        return currentRot;
     }
 
 protected:
     Vector3<real_type>  anchor;         ///< anchor position  
     Vector3<real_type>  current;        ///< current position
     Vector3<real_type>  axis;           ///< rotation axis
-    Matrix4<real_type>  anchorTransf;   ///< transformation matrix of the anchor point
-    Matrix4<real_type>  incremTransf;   ///< transformation matrix of the increment
-    Matrix4<real_type>  currentTransf;  ///< current transformation matrix
     real_type           angle;          ///< rotation angle
+    Matrix4<real_type>  anchorRot;   ///< transformation matrix of the anchor point
+    Matrix4<real_type>  incremRot;   ///< transformation matrix of the increment
+    Matrix4<real_type>  currentRot;  ///< current transformation matrix
 
     
     /// compute the incremental transformation
         angle = atan2(axis.length(), anchor.dotProduct(current) );
         axis.normalize();
         Quaternion<real_type> incremQuat = Quaternion<real_type>::fromAxisRot(axis, angle);
-        incremTransf = incremQuat.transform();
+        incremRot = incremQuat.transform();
     }
 
     /// project the given point on the sphere surface, combined with an hyperbole when dist>R/sqrt(2)

sources/opengl2_samples/test7_simplerenderer/GLTrackballManipulator.h

 /// @class GLTrackballManipulator 
 /// trackball 
 template <typename real_type=float>
-class GLTrackballManipulator: public GLTrackball<real_type>
+class GLTrackballManipulator
 {
 public:
 
 
     /// standard constructor
     GLTrackballManipulator()
-    : GLTrackball<real_type>()
+    : trackball()
     , currMode(evRotate)
     , radius(1.0)
     {}
     virtual void beginDrag(real_type x, real_type y)
     {
         if (currMode==evRotate)
-            GLTrackball<real_type>::beginDrag(x,y);
-        else if (currMode==evPan)
+            trackball.beginDrag(x,y);
+        else if (currMode==evPan || currMode==evZoom)
         {
             anchorPan = center; // set anchor point to the current position
             anchorPanSS = Vector3<real_type>(x,y,0.0);
+            incremPan = Vector3<real_type>(0,0,0);
         }
-        // // reset angle and axis
-        // angle = 0.0;
-        // axis = Vector3<real_type>();
-        // // set transf matrices
-        // anchorTransf = currentTransf;   // to keep previous transform
-        // incremTransf.identity();
-        // currentTransf.identity();
-        // // set anchor pos on sphere
-        // anchor = projectOnSurface(x,y);
-        // current = anchor;
     }
     
     /// mouse drag
     virtual void drag(real_type x, real_type y)
     {
         if (currMode==evRotate)
-            GLTrackball<real_type>::drag(x,y);
+            trackball.drag(x,y);
         else if (currMode==evPan)
         {
             Vector3<real_type> delta = Vector3<real_type>(x,y,0.0)-anchorPanSS;
-            printf("delta: %f %f %f\n",delta.x,delta.y,delta.z);
+            incremPan = delta*radius; // compensate with radius to 'normalize' the translation (effective when connected to a camera) 
+            incremPan = trackball.getRotation()*incremPan; // to use object local orientation
+            center = anchorPan+incremPan;
         }
-        // current = projectOnSurface(x,y);
-        // computeIncremental();
+        else if (currMode==evZoom)
+        {
+            radius += radius*(anchorPanSS.y-y)/100; // too minimalistic zoom implementation
+        }
     }
     
+    /// get current center
+    Vector3<real_type> getCenter( void ) 
+    {
+        return center;
+    }
+    /// get current rotation
+    Matrix4<real_type> getRotation( void ) 
+    {
+        return trackball.getRotation();
+    }
     /// get current transformation
     Matrix4<real_type> getTransformation( void ) 
     {
-        return GLTrackball<real_type>::currentTransf;
+        currentTransf = trackball.getRotation();
+        Vector3<real_type> offsetRad = currentTransf*Vector3<real_type>(0.0,0.0,radius); // radius offset in local orientation
+        currentTransf.setTranslation(center+offsetRad);
+        return currentTransf;
     }
 
     void setMode( eMode mode )
     eMode currMode;               ///< manipulator current mode
     
     real_type           radius;      ///< trackball radius
-    Vector3<real_type>  center;      ///< trackball center 
+    Vector3<real_type>  center;      ///< trackball center (current pan value)
     Vector3<real_type>  anchorPan;   ///< anchor point for pan
     Vector3<real_type>  anchorPanSS; ///< anchor point for pan (screen-space)
-    // Vector3<real_type>  anchor;         ///< anchor position  
-    // Vector3<real_type>  current;        ///< current position
-    // Vector3<real_type>  axis;           ///< rotation axis
-    // Matrix4<real_type>  anchorTransf;   ///< transformation matrix of the anchor point
-    // Matrix4<real_type>  incremTransf;   ///< transformation matrix of the increment
-    // Matrix4<real_type>  currentTransf;  ///< current transformation matrix
-    // real_type           angle;          ///< rotation angle
+    Vector3<real_type>  incremPan;   ///< increment for pan
 
-    
+    Matrix4<real_type>  currentTransf;  ///< current transformation matrix
+
+    GLTrackball<real_type> trackball;   ///< manage rotations
+        
 };
 
 

sources/opengl2_samples/test7_simplerenderer/glfw_utils.cpp

     else
     {
         context.mouse_button = 0;
+        context.dragging = false;
     }
 }
 

sources/opengl2_samples/test7_simplerenderer/main.cpp

     }
     else // use trackball to manage camera
     {
-        Matrix4f trackballTransf = trackball.getRotation().inverse();
+        Matrix4f trackballTransf = trackball.getTransformation();
         camera.transform.setTransformationMatrix(trackballTransf);
-        camera.transform.translate(Vector3f(0.0f,0.0f,10.0f));
+        //camera.transform.translate(Vector3f(0.0f,0.0f,10.0f));
     }
 
     // add render data
 std::cin >> dbidx;
 #endif //__Debug__
 
-    trackball.setMode(GLTrackballManipulatorf::evPan);
-
     // Initialize GLFW and Glee
     if( !glfw_Init(width,height) )
     {
         running = !glfwGetKey( GLFW_KEY_ESC ) && glfwGetWindowParam( GLFW_OPENED );
 
         // manage autorotate
-        if (glfwGetKey('R')) autorotate = true;
-        if (glfwGetKey('T')) autorotate = false;
+        if (glfwGetKey('A')) {  autorotate = true;  }
+        if (glfwGetKey('R')) {  autorotate = false;  trackball.setMode(GLTrackballManipulatorf::evRotate);  }
+        if (glfwGetKey('T')) {  autorotate = false;  trackball.setMode(GLTrackballManipulatorf::evPan);  }
+        if (glfwGetKey('Z')) {  autorotate = false;  trackball.setMode(GLTrackballManipulatorf::evZoom);  }
 
         // update fps
         if (frames%100==0)

sources/opengl2_samples/test7b_trackballmanipulator/GLMeshTools.cpp

 #include "aiScene.h"
 
 #include "vmath.h"
-// #include "mathutils.h"
 #include "vertex.h"
 #include "GLMesh.h"
 #include "GLMaterial.h"

var/scons/thirdparty/__init__.py

 import unittestpp
 import amp
 import jsoncpp
+import chrometracing
 
 
 __all__ = ['']

var/scons/thirdparty/chrometracing.py

+# coding: utf-8
+# define the Chrome event tracing library include/obj/link flags for the various platforms
+
+
+import sys, os
+
+def getChromeTracingParameters():
+    """get platforma dependent parameters"""
+    # variables
+    params = dict()
+    params['defines']     = []
+    params['objs']        = []
+    params['libs']        = []
+    params['includePath'] = []
+    params['libPath']     = []
+    
+    # fill needed params for each supported platform
+    # common defs
+    params['includePath'].append('chrome_event_trace')
+    params['libPath'].append('3rdparty/chrome_event_trace')
+    params['libs'].append('chrome_tracing')
+
+    # platform specific
+    if sys.platform=='win32':
+        # ChromeTracing settings for win32
+        pass
+    elif sys.platform=='darwin':
+        # ChromeTracing settings for osx
+        pass
+    elif sys.platform=='linux2':
+        # ChromeTracing settings for linux
+        pass
+    
+    return params
+
+
+def addChromeTracingToEnv(env):
+    """ add ChromeTracing parameters to the build environment"""
+    # retrieve params
+    params = getChromeTracingParameters()
+    # convert includepath to the complete 3rdparty dir
+    vincludepath = []
+    for pth in params['includePath']:
+        vincludepath.append(os.path.join(env['thirdpartydir'],pth))
+    # convert libpath to the corresponding variant dir
+    vlibpath = []
+    for pth in params['libPath']:
+        buildpath = os.path.join(env['builddir'],pth)
+        vlibpath.append(buildpath)
+    # append specific params to the build environment
+    env.AppendUnique(CPPPATH = vincludepath)
+    env.AppendUnique(LIBPATH = vlibpath)
+    env.AppendUnique(LIBS = params['libs'])
+    pass
+
+
+if __name__ == '__main__':
+    params = getChromeTracingParameters()
+    print '  --- Values ---'
+    print 'ChromeTracing Defines:      ' + str(params['defines'])
+    print 'ChromeTracing Objs:         ' + str(params['objs'])
+    print 'ChromeTracing Include Path: ' + str(params['includePath'])
+    print 'ChromeTracing Lib Path:     ' + str(params['libPath'])
+    print 'ChromeTracing Libs:         ' + str(params['libs'])
+