Alvaro Cassinelli / Mbed 2 deprecated laserUI

Dependencies:   mbed

Fork of skinGames_forktest by Alvaro Cassinelli

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers WrapperFunctions.h Source File

WrapperFunctions.h

00001 /* Name: WrapperFunctions.h
00002     
00003    * DESCRIPTION: 
00004     
00005     The following file defines a set of "WRAPPER" functions to simplify creating, rendering and displaying objects and scenes. 
00006     Basically, to display something we have to: 
00007   
00008        (1) BUILD A "SCENE" by creating and adding Objects. The rendering stack (lsr) will be used to modify the "modeling transformation RT".
00009        (2) Set the PERSPECTIVE TRANSFORMATION, and the VIEWING TRANSFORMATION (again, this is just playing with lsr), and then DRAW THE SCENE. 
00010                 
00011     * NOTE THAT: 
00012     
00013        (1) BUILDING the SCENE is done ONLY ONCE (or at least, each time we have a completely new scene to show), and not all the time as 
00014         in OpenGL (well, the equivalent in OpenGL is the vertex arrays sent to the graphic card). 
00015        (2) DRAWING THE SCENE is ALSO DONE ONLY WHEN WE GET A NEW VIEWING TRANSFORMATION (i.e., a new "POSE"). This is because 
00016                
00017     * HOW DOES IT WORK:
00018      
00019        (1) (a) Building a scene start by a call to "beginScene()". This routine first stoping the displaying engine (lsd) if it was working, and then deleting all data in it. 
00020        The reason is that we will modify the number of points/objects in it, and the "laser sensing display" engine (lsd) would fail trying to access arrays that have been deleted. 
00021            (b) then, we can add objects (using the objects primitives, or begin/end keywords). In so doing, we can use the modelview matrix stack liberaly, to place things
00022         where they need to be. Note that the objects are NOT yet rendered. 
00023            (C) We finish by calling "updateScene()", which has an important function: it tells the (dormant) displaying engine to update the size and structure of the "scene" in its 
00024         internal variables. BUT WE DON'T REATTACH THE INTERRUPT for the lsd again, because we did NOT yet render anything! 
00025         
00026        (2) Time for drawing: the first thing is to set the PROJECTION MATRIX (this in principle can be done once, at the very start of the program and is likely not to change). 
00027        Then, each time we have a new POSE, we need to set the VIEWING TRANSFORMATION (again, using the modelview stack lsr). 
00028        When both things are done, a call to "drawScene()" will apply the global viewing transformation to each point in the scene, and RENDER them too (using the projection matrix). 
00029        By DEFAULT, a call to "drawScene()" will ACTIVATE the DISPLAYING ENGINE if it was not working. 
00030        
00031        IMPORTANT: Note that we don't NEED to STOP the displaying interrupt when just changing the pose or even the projection matrix - this is because the STRUCTURE of the scene
00032                   did not change, and then the displaying engine will not fail. However, there may be some strange graphical "anomalies" (the equivalent of problems with 
00033                   vertical synch on normal displays). This is because I am not using DOUBLE BUFFERING, but I will address this in future versions. 
00034        
00035     * AN EXAMPLE: 
00036                 
00037     (a) In a setting function:  
00038     
00039     //(A) First, set the modelview and projection matrices: 
00040     // Typically, the projection matrix is set from the PC side, or loaded by default (from file system).
00041     // The modelview matrix may be, say, the identity:
00042     lsr.setIdentityPose(); // we could use a wrapper, but I won't for the time being. 
00043 
00044     //(B) Start building the "scene" with objects in it (now I will use wrapper functions - note that "objectPrimitives" are sort of wrapper functions too):    
00045     
00046     beginScene(); // stop displaying (in the future we can have double buffering...). then clear the scene.  
00047     // we can start adding objects: 
00048     
00049     // (a) in OpenGL like style:
00050     begin(1); // start creating object with identifier = 1
00051     vertex(10,10,0); vertex(10,100,0); vertex(100,100,0); vertex(10,100,0); vertex(10,10,0); // closed square
00052     end();
00053     
00054     // (b) example of adding an object using objectPrimitives: 
00055     buildLine(10,10,0,100,100,0,10, 1);
00056     
00057     endScene(); // this is important: rendering is done here, and the display engine (lsd) is reattached to the interrupt timer. 
00058     
00059     
00060 */
00061 
00062 #include "Scene.h"
00063 #include "laserSensingDisplay.h"
00064 #include "LaserRenderer.h"
00065 
00066 #include <string> 
00067 //using namespace std; // should not be in a header (we will bring to any other cpp that includes this file!!
00068 
00069 // Special classes of derived objects: 
00070 // #include ...
00071 
00072 //class laserSensingDisplay; // will produce "incomplete type not allowed" 
00073 
00074 // ====================================================================================================================================================
00075 
00076 // enum typeObject {GENERIC_OBJECT, LETTER}; // this will be useful for adding derived objects from BaseObject using the being() method, such as letters, and in the future objects
00077 // that can have an "update" method of their own (and move around...)
00078 
00079 // =================================   BASIC "OPENGL-like" object/scene builders and query functions ("sense") ==========================================
00080 
00081 // Creating a "scene" (a collection of "objects"). 
00082 // NOTE: the advantage of having clustered points into "objects" and then a "scene" is that we may have handles for each of them, to modify their appearance, or query for touch, etc.  
00083 void clearScene();
00084 void updateScene();
00085 
00086 // Create objects "a-la" OpenGL (for other ways, see objectPrimitives.h). 
00087 //BaseObject* begin(typeObject _type, unsigned char _id); // This will add a new object with or without identifier _id. In the future, we can have modes - lines, bezier, and points.
00088 BaseObject* begin(unsigned char _id); // This will add a new object with or without identifier _id. In the future, we can have modes - lines, bezier, and points.
00089 void vertex(float x, float y, float z); // add a point, but do not RENDER it yet (no final projection computed)
00090 void vertex(V3& _v3);
00091 void end(); // (this is meaningless if there is no polygon or bezier mode... but even now it is good to have for clarity - and to look like opengl)
00092 
00093 // Delete object from current scenembed_reset (in the future, let's use also strings as IDs):
00094 void deleteObject(int _id); 
00095 
00096 // Rendering methods: 
00097 void drawObject(int _id) ;
00098 void drawObject(BaseObject* ptr_object) ;
00099 void drawScene();
00100 
00101 // Sensing methods (query and process sensed data):
00102 bool senseObject(int _id);
00103 bool senseScene();
00104 
00105 // =================================   OTHER auxiliary GLOBAL SCENE/OBJECT TRANSFORMATIONS ==========================================
00106 
00107 void trasformObject(int _id) ;
00108 void translateObject(int _id, int xx, int yy, int zz=0);
00109 void rotateObjectX(int _id, float alpha);
00110 void rotateObjectY(int _id, float alpha);
00111 void rotateObjectZ(int _id, float alpha);
00112 
00113 void transformObject(BaseObject* ptr_object) ;
00114 void transformScene();
00115 void changeColorScene(unsigned char _color);
00116 
00117 // =================================   OBJECT PRIMITIVES (this could be in a different file) ============================================================
00118 
00119 // These are some primitive sensing-displaying objects (in the future, kind of UIButtons - would be nice if they could produce "events"...)
00120 // Note that the only way (for now) to query if some object has been "touched" is through the knowledge of its "unique" ID... which acts as a handler. In fact, 
00121 // we can keep track of its pointer in the main program - and this means it will be exactly a handler... 
00122 void line(float x0, float y0, float z0, float x1, float y1, float z1, int npoints);
00123 void line(V3& v0, V3& v1, int npoints);
00124 void square(float sideSize, int npointsSide);
00125 void rectangle(float sideSizeX, float sideSizeY, int interPointDistance);
00126 void circle(float radius, int numpoints);
00127 void cube(float sideSize, int npointsSide);   // not really a cube...
00128 void grid(int nx, int ny, int repeatpoint); // normalized (0-1)x(0-1)
00129 void grid(float sizeX, float sizeY, int nx, int ny, int repeatpoint);
00130 void gridCircles(int nx, int ny, float radius, int nbpointsCircle);
00131 void gridCircles(float sizeX, float sizeY, int nx, int ny, float radius, int nbpointsCircle);
00132      
00133 // LETTERS and STRINGS:
00134 void letter3d(char _letter, float width, float height);
00135 void string3d(string text, float fontSize, float spaceWidth);
00136 
00137 // =================================   WRAPPERS TO LOAD OBJECTS FROM SYSTEM FILE ========================================================================
00138  // ... to do   
00139  //void buildRawTrajectory(float * auxbuffer, int arraySize);
00140     
00141 // =================================   WRAPPERS TO LOAD MATRICES FROM SYSTEM FILE =======================================================================
00142 // ...to do
00143 
00144 // ================================= WRAPPERS FOR MORE BASIC IO FUNCTIONS   =================================
00145 void scanSerial(unsigned short pointsPerLine);
00146 void showLimitsMirrors(unsigned short pointsPerLine, unsigned short durationSecs);
00147 void recomputeLookUpTable();
00148 void startDisplay();
00149 void stopDisplay();
00150 void toggleDisplay();
00151 void resumeDisplay();
00152 // =============================== HARDWARE KNOBS: switches, potentiometers... =================================================
00153 void hardwareKnobs();
00154