![](/media/cache/profiles/68a15b5278e4f7c4c056df9d5f1d3b1f.jpg.50x50_q85.jpg)
Laser Sensing Display for UI interfaces in the real world
Fork of skinGames_forktest by
Revision 47:199042980678, committed 2014-04-17
- Comitter:
- mbedalvaro
- Date:
- Thu Apr 17 08:04:14 2014 +0000
- Parent:
- 46:e0dd2d1d07c1
- Commit message:
- publishing for sharing with Ken Iwasaki
Changed in this revision
diff -r e0dd2d1d07c1 -r 199042980678 Scene.h --- a/Scene.h Sun Mar 30 08:58:59 2014 +0000 +++ b/Scene.h Thu Apr 17 08:04:14 2014 +0000 @@ -85,6 +85,12 @@ // have a clear separation between sensing parameters "tweaking" (like mirror delays, setting methods and variables) and the more pure graphical BaseObject Box3d enclosingBox; // this will be filled when rendering the object or when explicitly computing the enclosing box + + // FUTURE WORK: + // - OBJECTS should have their own transformation matrix, and methods (inherited from a base class?) to modify it or recreate it. This way we will + // avoid transforming the object 3d points independently, which will create problems because approximations. Eventually, these objects will have + // behaviours that will affect this transformation matrix (as a function of time). When rendering an object, the object original 3d points will be first modified by + // the object's own RT, THEN by the global modelview. This is exactly like in an openGL program... }; // ==============================================================================================================================================
diff -r e0dd2d1d07c1 -r 199042980678 WrapperFunctions.cpp --- a/WrapperFunctions.cpp Sun Mar 30 08:58:59 2014 +0000 +++ b/WrapperFunctions.cpp Thu Apr 17 08:04:14 2014 +0000 @@ -168,10 +168,10 @@ // I will implement both, because even the first option can be useful (to create more complex scenes by rotating already created objects for instance - but it will be trickier to understand though) // (1) applying a transformation on the 3d points (NOTE: we could also apply transformations on the projected points! this is however a work for the "viewport"). -// NOTE: I am not going to create new transform methods (rotation and translations), but instead use the lsr stack. So, I assume the user has set RT to what she wants. Then, we will +// NOTE: I may later create specific transform methods (rotation and translations), but in general we can use the lsr stack. So, I assume the user has set RT to what she wants. Then, we will // just apply RT to the object or whole scene. This method can be used to RESIZE the object (in particular when it is centered). //(a) Objects: -void trasformObject(int _id) // use maps in the future!!! +void transformObject(int _id) // use maps in the future!!! { BaseObject* ptr_object=NULL; for (int i=0; i<scene.totalObjects(); i++) if ((scene.objectArray[i]->ID())==_id) ptr_object=scene.objectArray[i]; @@ -195,6 +195,49 @@ // lsr.renderScene(&scene); } +// Some elementary transformations (again, note that this if applied too much will make the object eventually deform - it would be much better to do the +// rotation/translation actions as part of a program IN the mbed, instead of sending commands: +void translateObject(int _id, int xx, int yy, int zz) { + lsr.pushPoseMatrix(); + lsr.setIdentityPose(); // we could use a wrapper, but I won't for the time being. + lsr.flipY(); // there is a pb here... + //lsr.flipX(); + lsr.translate(xx,yy,zz); + transformObject(_id); + lsr.popPoseMatrix(); +} + +void rotateObjectX(int _id, float alpha) { + lsr.pushPoseMatrix(); + lsr.setIdentityPose(); // we could use a wrapper, but I won't for the time being. + lsr.flipY(); + //lsr.flipX(); + lsr.rotateX(alpha); + transformObject(_id); + lsr.popPoseMatrix(); + } + +void rotateObjectY(int _id, float alpha){ + lsr.pushPoseMatrix(); + lsr.setIdentityPose(); // we could use a wrapper, but I won't for the time being. + lsr.flipY(); + //lsr.flipX(); + lsr.rotateY(alpha); + transformObject(_id); + lsr.popPoseMatrix(); + } + +void rotateObjectZ(int _id, float alpha) { lsr.pushPoseMatrix(); + lsr.setIdentityPose(); // we could use a wrapper, but I won't for the time being. + lsr.flipY(); + //lsr.flipX(); + lsr.rotateZ(alpha); + transformObject(_id); + lsr.popPoseMatrix(); + } + +// ======================================================================================================= + //(2) Apply current RT transformation and render but KEEPING the original values of the 3d points: //(a) Objects: void drawObject(int _id) // use maps in the future!!!
diff -r e0dd2d1d07c1 -r 199042980678 WrapperFunctions.h --- a/WrapperFunctions.h Sun Mar 30 08:58:59 2014 +0000 +++ b/WrapperFunctions.h Thu Apr 17 08:04:14 2014 +0000 @@ -105,6 +105,11 @@ // ================================= OTHER auxiliary GLOBAL SCENE/OBJECT TRANSFORMATIONS ========================================== void trasformObject(int _id) ; +void translateObject(int _id, int xx, int yy, int zz=0); +void rotateObjectX(int _id, float alpha); +void rotateObjectY(int _id, float alpha); +void rotateObjectZ(int _id, float alpha); + void transformObject(BaseObject* ptr_object) ; void transformScene(); void changeColorScene(unsigned char _color);
diff -r e0dd2d1d07c1 -r 199042980678 main.cpp --- a/main.cpp Sun Mar 30 08:58:59 2014 +0000 +++ b/main.cpp Thu Apr 17 08:04:14 2014 +0000 @@ -140,7 +140,7 @@ // this is a hack for the time being: int objectID; -int xx, yy; // initial position of object +int xx, yy; // initial position of object or displacement bool firstTimeDisplay=true; // ============================================================================================================== @@ -626,11 +626,6 @@ indexStringData = 0; objectID=atoi(receivedStringData); } - - else if (command1=="initialPosition") { // this is for setting the POSITION of the object to be created: - xx=auxDataBuffer[0]; yy=auxDataBuffer[1]; - auxDataBuffer_index=0; - } else if (command1 == "mbedReset" ) mbed_reset(); @@ -674,7 +669,7 @@ } -// =================== CREATION and DESTRUCTION of objects ========================================================= +// =================== CREATION and DESTRUCTION of objects ===================================================== else if (command1 == "clearScene") { clearScene(); } @@ -682,6 +677,22 @@ else if (command1 =="deleteObject") { // second address is object identifier (a string that will be converted deleteObject(objectID); } + + else if (command1=="initialPosition") { // this is for setting the POSITION of the object to be created (or displacement): + xx=auxDataBuffer[0]; yy=auxDataBuffer[1]; + auxDataBuffer_index=0; + } + +// =================== TRANSFORMATION OF OBJECT POINTS ========================================================= +// NOTE: this may in the end destroy the object rigidity because approximations... but without an RT per object, this is the only way to +// modify object pose independently of the whole scene... +else if (command1 =="moveObject") { + translateObject(objectID, xx, yy, 0); + } + + +// ============================================================================================================== + // Produce a grid of points. The projection is ORTHOGRAPHIC. Also, POSE is reset to identity (i.e., the sent points should have // been translated previously - this may be optional, we could first send the pose, then the points...) @@ -1046,11 +1057,21 @@ command1="objectID"; interpretCommand(); } + + else if (incomingByte == '[') { + command1 =="deleteObject"; + interpretCommand(); + } + + else if (incomingByte == '}') { + command1 =="moveObject"; + interpretCommand();; // xx, yy contains already the necessary displacement + } + else if (incomingByte == '~') { // this is for setting the POSITION of the object to be created: command1="initialPosition"; interpretCommand(); - }