libmoldeo (Moldeo 1.0 Core)  1.0
libmoldeo is the group of objects and functions that executes the basic operations of Moldeo 1.0 Platform.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
moGUIManager.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2 
3  moGUIManager.cpp
4 
5  ****************************************************************************
6  * *
7  * This source is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This code is distributed in the hope that it will be useful, but *
13  * WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
15  * General Public License for more details. *
16  * *
17  * A copy of the GNU General Public License is available on the World *
18  * Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
19  * obtain it by writing to the Free Software Foundation, *
20  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  * *
22  ****************************************************************************
23 
24  Copyright(C) 2006 Fabricio Costa
25 
26  Authors:
27  Fabricio Costa
28 
29 *******************************************************************************/
30 
31 #include "moGUIManager.h"
32 #include <moFontManager.h>
33 
34 #include "moArray.h"
35 moDefineDynamicArray(moGuiObjectArray)
36 moDefineDynamicArray(moAttributeArray)
37 
38 moCamera3D::moCamera3D( const moCamera3D& p_src ) : moCamera3DBase() {
39  (*this) = p_src;
40 }
41 
44  m_Position = p_src.m_Position;
45  m_Center = p_src.m_Center;
46  return (*this);
47 }
48 
51  moCamera3DBase& m( (*this) );
52  m = p_src;
53  return (*this);
54 }
55 
56 
57 
58 
59 
62 
63  m_VerticesBuffer = NULL;
64  m_VerticesUVBuffer = NULL;
65  m_ColorBuffer = NULL;
66  m_NormalsBuffer = NULL;
67 }
68 
70  m_Type = p_type;
71  m_VerticesBuffer = NULL;
72  m_VerticesUVBuffer = NULL;
73  m_ColorBuffer = NULL;
74  m_NormalsBuffer = NULL;
75 }
76 
78 
79 }
80 
83 
84  m_Vertices = p_src.m_Vertices;
86  m_Colors = p_src.m_Colors;
87  m_Normals = p_src.m_Normals;
88 /*
89  m_ColorBuffer = p_src.m_ColorBuffer;
90  m_VerticesBuffer = p_src.m_VerticesBuffer;
91  m_VerticesUVBuffer = p_src.m_VerticesUVBuffer;
92 */
93  m_Faces = p_src.m_Faces;
95  m_Name = p_src.m_Name;
96  m_Type = p_src.m_Type;
97  return (*this);
98 }
99 
101  return moAbstract::Init();
102 }
103 
105  SetResourceManager(pResourceManager);
106  return pResourceManager!=NULL;
107 }
108 
110  return true;
111 }
112 
113 void
114 moGeometry::applyMatrix( const moGLMatrixf &p_ModelMatrix ) {
115  moGLMatrixf tf = p_ModelMatrix;
116 }
117 
118 moText
120 
121  moText result;
122 
123  switch(p_type) {
124  case MO_GEOMETRY_POINT:
125  result = moText("PointGeometry");
126  break;
127  case MO_GEOMETRY_CIRCLE:
128  result = moText("CircleGeometry");
129  break;
131  result = moText("CylinderGeometry");
132  break;
134  result = moText("DodecahedronGeometry");
135  break;
136  case MO_GEOMETRY_EXTRUDE:
137  result = moText("ExtrudeGeometry");
138  break;
140  result = moText("IcosahedronGeometry");
141  break;
142  case MO_GEOMETRY_PLANE:
143  result = moText("PlaneGeometry");
144  break;
146  result = moText("PolyhedronGeometry");
147  break;
148  case MO_GEOMETRY_RING:
149  result = moText("RingGeometry");
150  break;
151  case MO_GEOMETRY_SHAPE:
152  result = moText("ShapeGeometry");
153  break;
154  case MO_GEOMETRY_SPHERE:
155  result = moText("SphereGeometry");
156  break;
158  result = moText("TetrahedronGeometry");
159  break;
160  case MO_GEOMETRY_TEXT:
161  result = moText("TextGeometry");
162  break;
163  case MO_GEOMETRY_TUBE:
164  result = moText("TubeGeometry");
165  break;
166  case MO_GEOMETRY_BOX:
167  result = moText("BoxGeometry");
168  break;
169 
171  result = moText("undefined Geometry");
172  break;
173 
174  default:
175  result = moText("unset");
176  break;
177  }
178  return result;
179 }
180 
181 moText
183  moText JSON;
184  moText comma("");
185  JSON = "{";
186  JSON+= "'name': "+m_Name;
187  JSON+= ",'type': "+TypeToStr(m_Type);
188 
189  //concatenate all Vertices
190  JSON+= "',vertices': [";
191  for( MOuint i=0; i<m_Vertices.Count(); i++) {
192 
193  moVector3f pt = m_Vertices[i];
194 
195  JSON+= comma;
196  JSON+= " {";
197  JSON+= FloatToStr(pt.X(),2,2) + moText(",");
198  JSON+= FloatToStr(pt.Y(),2,2) + moText(",");
199  JSON+= FloatToStr(pt.Z(),2,2);
200  JSON+= "}";
201  comma = ",";
202  }
203  JSON+= "],";
204  JSON+= "'verticesBuffer': [";
205  comma = "";
206  if (m_VerticesBuffer)
207  for( MOuint i=0; i<m_Vertices.Count(); i++) {
208 
209  JSON+= comma;
210  JSON+= " {";
211  JSON+= FloatToStr(m_VerticesBuffer[i*3],2,2) + moText(",");
212  JSON+= FloatToStr(m_VerticesBuffer[i*3+1],2,2) + moText(",");
213  JSON+= FloatToStr(m_VerticesBuffer[i*3+2],2,2);
214  JSON+= "}";
215  comma = ",";
216  }
217  JSON+= "],";
218  //JSON+= " { 0.0, 0.0, 0.0 }";
219  JSON+= "}";
220 
221  return JSON;
222 }
223 
224 
225 float*
227 
228  if (m_Faces.Count()==0) return NULL;
229 
230  m_VerticesBuffer = new float [ m_Faces.Count()*3*3 ];
231  m_VerticesUVBuffer = new float [ m_Faces.Count()*3*2 ];
232  m_ColorBuffer = new float [ m_Faces.Count()*3*3 ];
233  m_NormalsBuffer = new float [ m_Faces.Count()*3*3 ];
234 
236 
237  for( MOuint fi=0;fi<m_Faces.Count(); fi++) {
238 
239  moFace& Face( m_Faces[fi] );
240 
241  for( int pi=0; pi<3; pi++ ) {
242 
243  int vpos = Face[pi];
244  int indexv3 = fi*9+pi*3;
245  int indexv2 = fi*6+pi*2;
247  m_VerticesBuffer[ indexv3 ] = m_Vertices[ vpos ].X();
248  m_VerticesBuffer[ indexv3 + 1 ] = m_Vertices[ vpos ].Y();
249  m_VerticesBuffer[ indexv3 + 2 ] = m_Vertices[ vpos ].Z();
251  m_VerticesUVBuffer[ indexv2 ] = m_VerticesUvs[vpos].X();
252  m_VerticesUVBuffer[ indexv2 + 1 ] = m_VerticesUvs[vpos].Y();
254  m_ColorBuffer[ indexv3 ] = m_Colors[vpos].X();
255  m_ColorBuffer[ indexv3 + 1 ] = m_Colors[vpos].Y();
256  m_ColorBuffer[ indexv3 + 2 ] = m_Colors[vpos].Z();
257 
258  m_NormalsBuffer[ indexv3 ] = m_Normals[vpos].X();
259  m_NormalsBuffer[ indexv3 + 1 ] = m_Normals[vpos].Y();
260  m_NormalsBuffer[ indexv3 + 2 ] = m_Normals[vpos].Z();
261 
262  }
263  }
264  } else return NULL;
265 
266  return &m_VerticesBuffer[0];
267 }
268 
269 float*
271  return m_ColorBuffer;
272 }
273 
274 float*
276  return m_VerticesUVBuffer;
277 }
278 
279 float*
281  return m_NormalsBuffer;
282 }
283 
284 
285 moBoxGeometry::moBoxGeometry( float width, float height,float depth, int wsegments, int hsegments, int dsegments ) : moGeometry( MO_GEOMETRY_BOX ) {
286 
287  m_Name = "oneBox";
289 
290  //m_Vertices.Init( 0, moVector3f( 0.0, 0.0, 0.0) );
291  //m_VerticesUvs.Init( 0, moTCoord( 0.0, 0.0 ) );
292  m_Faces.Init( 0, moFace( 0, 0, 0 ) );
293  m_FaceVertexUvs.Init( 0, moTCoord( 0.0, 0.0 ) );
294  //m_Colors.Init( 0, moColor( 0.0, 0.0, 0.0 ) );
295 
296 
297 
299  //radius = ;
300  wsegments = max( 1, wsegments );
301  hsegments = max( 1, hsegments );
302  dsegments = max( 1, dsegments );
303  int vertexCount = ( wsegments * hsegments * 2 ) + ( wsegments * dsegments * 2 ) + ( wsegments * hsegments * 2 );
304  m_Vertices.Init( vertexCount, moVector3f( 0.0, 0.0, 0.0) );
305  m_VerticesUvs.Init( vertexCount, moTCoord( 0.0, 0.0) );
306  m_Colors.Init( vertexCount, moColor( 1.0, 1.0, 1.0 ) );
307  m_Normals.Init( vertexCount, moColor( 0.0, 0.0, 1.0 ) );
308 
309 /*
310  int vertexCount = 4;
311 
312  m_Vertices.Set( 0, moVector3f( -1.0*radius, -1.0*radius, 0.0) );
313  m_VerticesUvs.Set( 0, moTCoord( 0.0, 1.0 ) );
314  m_Colors.Set( 0, moColor( 1.0, 1.0, 1.0 ) );
315 
316  m_Vertices.Set( 1, moVector3f( -1.0*radius, 1.0*radius, 0.0) );
317  m_VerticesUvs.Set( 1, moTCoord( 0.0, 0.0 ) );
318  m_Colors.Set( 1, moColor( 1.0, 1.0, 1.0 ) );
319 
320  m_Vertices.Set( 2, moVector3f( 1.0*radius, 1.0*radius, 0.0) );
321  m_VerticesUvs.Set( 2, moTCoord( 1.0, 0.0 ) );
322  m_Colors.Set( 2, moColor( 1.0, 1.0, 1.0 ) );
323 
324  m_Vertices.Set( 3, moVector3f( 1.0*radius, -1.0*radius, 0.0) );
325  m_VerticesUvs.Set( 3, moTCoord( 1.0, 1.0 ) );
326  m_Colors.Set( 3, moColor( 1.0, 1.0, 1.0 ) );
327 
328  m_Faces.Add( moFace( 0, 1, 2 ) );
329  m_Faces.Add( moFace( 2, 3, 0 ) );
330 */
331 
333  int index = 0;
334  int ixline = 0;
335  float px=0.0f,py=0.0f,pz = 0.0f;
336  int fk = 0;
337  float u=0.0f, v=0.0f, w = -0.5f + (float)fk / (float)dsegments ;
338 
339  for ( int j = 0; j <= hsegments; j++ ) {
340 
341  v = -0.5f + (float)j / (float)hsegments;
342 
343  for ( int i = 0; i <= wsegments; i++ ) {
344 
345  u = -0.5f + (float)i / (float)wsegments;
346 
347  px = u;
348  py = v;
349  pz = w;
350 
351  moVector3f normal( px, py, pz );
352  normal.Normalize();
353  moVector3f position( px, py, pz );
354  moTCoord tcoord( u, 1-v );
355 
357  m_Vertices.Set( index, position );
358  m_VerticesUvs.Set( index, tcoord );
359  m_Normals.Set( index, normal );
360  index ++;
361 
363  position.Z() = w + 1.0f;
364  normal.Z() = w + 1.0f;
365  m_Vertices.Set( index, position );
366  m_VerticesUvs.Set( index, tcoord );
367  m_Normals.Set( index, normal );
368  index ++;
369 
370  if ( j>0 && (i%2)==0) {
371  ixline = index - (j-1)*wsegments;
372  m_Faces.Add( moFace( ixline, ixline+1, index ) );
373  }
374  if ( j>0 && (i%2)==1) {
375  ixline = index - (j-1)*wsegments;
376  m_Faces.Add( moFace( index, index+1, ixline+1 ) );
377  }
378  }
379  }
380 
381  u = -0.5f;
382  for ( int k = 0; k <= dsegments; k++ ) {
383 
384  w = -0.5f + (float)k / (float)dsegments;
385 
386  for ( int i = 0; i <= wsegments; i++ ) {
387 
388  u = -0.5f + (float)i / (float)wsegments;
389 
390  px = u;
391  py = v;
392  pz = w;
393 
394  moVector3f normal( px, py, pz );
395  normal.Normalize();
396  moVector3f position( px, py, pz );
397  moTCoord tcoord( u, 1-v );
398 
400  m_Vertices.Set( index, position );
401  m_VerticesUvs.Set( index, tcoord );
402  m_Normals.Set( index, normal );
403  index++;
404 
406  position.X() = u + 1.0f;
407  normal.X() = u + 1.0f;
408  m_Vertices.Set( index, position );
409  m_VerticesUvs.Set( index, tcoord );
410  m_Normals.Set( index, normal );
411  index++;
412 
413  if ( k>0 && (i%2)==0) {
414  ixline = index - (k-1)*wsegments;
415  m_Faces.Add( moFace( ixline, ixline+1, index ) );
416  }
417  if ( k>0 && (i%2)==1) {
418  ixline = index - (k-1)*wsegments;
419  m_Faces.Add( moFace( index, index+1, ixline+1 ) );
420  }
421 
422  }
423  }
424 
425  u = -0.5f;
426  for ( int k = 0; k <= dsegments; k++ ) {
427 
428  w = -0.5f + (float)k / (float)dsegments;
429 
430  for ( int j = 0; j <= hsegments; j++ ) {
431 
432  v = -0.5f + (float)j / (float)hsegments;
433 
434  px = u;
435  py = v;
436  pz = w;
437 
438  moVector3f normal( px, py, pz );
439  normal.Normalize();
440  moVector3f position( px, py, pz );
441  moTCoord tcoord( u, 1-v );
442 
444  m_Vertices.Set( index, position );
445  m_VerticesUvs.Set( index, tcoord );
446  m_Normals.Set( index, normal );
447  index ++;
448 
450  position.X() = u + 1.0f;
451  normal.X() = u + 1.0f;
452  m_Vertices.Set( index, position );
453  m_VerticesUvs.Set( index, tcoord );
454  m_Normals.Set( index, normal );
455  index ++;
456 
457  if ( k>0 && (k%2)==0) {
458  ixline = index - (k-1)*wsegments;
459  m_Faces.Add( moFace( ixline, ixline+1, index ) );
460  }
461  if ( k>0 && (j%2)==1) {
462  ixline = index - (k-1)*wsegments;
463  m_Faces.Add( moFace( index, index+1, ixline+1 ) );
464  }
465 
466 
467  }
468  }
469 
470 /*
471  for ( int k = 0; k <= dsegments; k++ ) {
472 
473  float w = -0.5f + (((float)j) / (float)hsegments );
474 
475  for ( int j = 0; j <= hsegments; j++ ) {
476 
477  float v = -0.5f + (((float)j) / (float)hsegments );
478 
479  for ( int i = 0; i <= wsegments; i++ ) {
480 
481  float u = -0.5f + ((float)i) / ((float)wsegments);
482 
483  if (k==0) {
484 
485  moVector3f normal( px, py, pz );
486  normal.Normalize();
487  moVector3f position( px, py, pz );
488  moTCoord tcoord( u, 1-v );
489  m_Vertices.Set( index, position );
490  m_VerticesUvs.Set( index, tcoord );
491  m_Normals.Set( index, normal );
492 
493  } else ( k==(dsegments-1) ) {
494 
495  moVector3f normal( px, py, pz );
496  normal.Normalize();
497  moVector3f position( px, py, pz );
498  moTCoord tcoord( u, 1-v );
499  m_Vertices.Set( index, position );
500  m_VerticesUvs.Set( index, tcoord );
501  m_Normals.Set( index, normal );
502 
503  }
504  index ++;
505  }
506  }
507  }
508  */
509 }
510 
512 
513 }
514 
515 
516 
517 moPlaneGeometry::moPlaneGeometry( float width, float height, int widthSegments, int heightSegments )
519 
520  m_VerticesBuffer = NULL;
521  m_VerticesUVBuffer = NULL;
522  m_ColorBuffer = NULL;
523 
524  m_Name = "MyPlane";
526 
527  m_Vertices.Init( 0, moVector3f( 0.0, 0.0, 0.0) );
528  m_VerticesUvs.Init( 0, moTCoord( 0.0, 0.0 ) );
529  m_Normals.Init( 0, moVector3f( 0.0, 0.0, 0.0) );
530 
531  m_Faces.Init( 0, moFace( 0, 0, 0 ) );
532  m_FaceVertexUvs.Init( 0, moTCoord( 0.0, 0.0 ) );
533  m_Colors.Init( 0, moColor( 0.0, 0.0, 0.0 ) );
534 
535 
536  float dw = 0.5*width;
537  float dh = 0.5*height;
538 
557  m_Vertices.Add( moVector3f( -dw, -dh, 0.0) );
558  m_Vertices.Add( moVector3f( -dw, dh, 0.0) );
559  m_Vertices.Add( moVector3f( dw, -dh, 0.0) );
560  m_Vertices.Add( moVector3f( dw, dh, 0.0) );
561 
562  m_VerticesUvs.Add( moVector2f( 0.0, 1.0) );
563  m_VerticesUvs.Add( moVector2f( 0.0, 0.0) );
564  m_VerticesUvs.Add( moVector2f( 1.0, 1.0) );
565  m_VerticesUvs.Add( moVector2f( 1.0, 0.0) );
566 
567  m_Normals.Add( moVector3f( 0.0, 0.0, 1.0) );
568  m_Normals.Add( moVector3f( 0.0, 0.0, 1.0) );
569  m_Normals.Add( moVector3f( 0.0, 0.0, 1.0) );
570  m_Normals.Add( moVector3f( 0.0, 0.0, 1.0) );
571 
572  m_Colors.Add( moColor( 1.0, 0.0, 0.0 ) );
573  m_Colors.Add( moColor( 0.0, 1.0, 0.0 ) );
574  m_Colors.Add( moColor( 0.0, 0.0, 1.0 ) );
575  m_Colors.Add( moColor( 1.0, 1.0, 1.0 ) );
576 
579  m_Faces.Add( moFace( 0, 1, 2 ) );
580  m_Faces.Add( moFace( 2, 3, 1 ) );
581 
582  m_FaceVertexUvs.Add( moVector2f( 0.0, 1.0) );
583  m_FaceVertexUvs.Add( moVector2f( 0.0, 0.0) );
584  m_FaceVertexUvs.Add( moVector2f( 1.0, 1.0) );
585 
586  m_FaceVertexUvs.Add( moVector2f( 1.0, 1.0) );
587  m_FaceVertexUvs.Add( moVector2f( 1.0, 0.0) );
588  m_FaceVertexUvs.Add( moVector2f( 0.0, 0.0) );
589 /*
590  //set buffers for shaders
591  m_VerticesBuffer = new float [ m_Vertices.Count()*3 ];
592  if (m_VerticesBuffer)
593  for( MOuint i=0;i<m_Vertices.Count(); i++) {
594  m_VerticesBuffer[i*3] = m_Vertices[i].X();
595  m_VerticesBuffer[i*3+1] = m_Vertices[i].Y();
596  m_VerticesBuffer[i*3+2] = m_Vertices[i].Z();
597  }
598 
599 
600  m_VerticesUVBuffer = new float [ m_VerticesUvs.Count()*2 ];
601  if (m_VerticesUVBuffer)
602  for( MOuint i=0;i<m_VerticesUvs.Count(); i++) {
603  m_VerticesUVBuffer[i*2] = m_VerticesUvs[i].X();
604  m_VerticesUVBuffer[i*2+1] = m_VerticesUvs[i].Y();
605  }
606 
607  m_ColorBuffer = new float [ m_Vertices.Count()*3 ];
608  if (m_ColorBuffer)
609  for( MOuint i=0;i<m_Colors.Count(); i++) {
610  m_ColorBuffer[i*2] = m_Colors[i].X();
611  m_ColorBuffer[i*2+1] = m_Colors[i].Y();
612  }
613 */
614 }
615 
617 /*
618  if (m_VerticesBuffer) { delete[] m_VerticesBuffer; m_VerticesBuffer = NULL; }
619  if (m_VerticesUVBuffer) { delete[] m_VerticesUVBuffer; m_VerticesUVBuffer = NULL; }
620  if (m_ColorBuffer) { delete[] m_ColorBuffer; m_ColorBuffer = NULL; }
621  */
622 }
623 
624 
626 
627 }
628 moPolyhedronGeometry::moPolyhedronGeometry( const moVector3fArray& p_Vertices,
629  const moVector3iArray& p_Faces,
630  float radius,
631  float detail ) : moGeometry( MO_GEOMETRY_POLYHEDRON ) {
632 
633  //radius, detail
634  m_Vertices = p_Vertices;
635  m_Faces = p_Faces;
636  //calculate projection to sphere with radius
637  //tesselate using "detail" factor: 0 (no tesselation), 1 (1 subdivision), 2 (2 subdivisions), N (N subdivisions)
638 }
639 
641 
642 }
643 
644 #include "moDebugManager.h"
645 
646 moSphereGeometry::moSphereGeometry( float radius, int widthSegments, int heightSegments, float phiStart, float phiLength, float thetaStart, float thetaLength )
648 
649 
650  m_Name = "MySphere";
652 
653  //m_Vertices.Init( 0, moVector3f( 0.0, 0.0, 0.0) );
654  //m_VerticesUvs.Init( 0, moTCoord( 0.0, 0.0 ) );
655  m_Faces.Init( 0, moFace( 0, 0, 0 ) );
656  m_FaceVertexUvs.Init( 0, moTCoord( 0.0, 0.0 ) );
657  //m_Colors.Init( 0, moColor( 0.0, 0.0, 0.0 ) );
658 
659 
660 
662  //radius = ;
663  widthSegments = max( 3, widthSegments );
664  heightSegments = max( 2, heightSegments );
665  int vertexCount = ( ( widthSegments + 1 ) * ( heightSegments + 1 ) );
666  m_Vertices.Init( vertexCount, moVector3f( 0.0, 0.0, 0.0) );
667  m_VerticesUvs.Init( vertexCount, moTCoord( 0.0, 0.0) );
668  m_Colors.Init( vertexCount, moColor( 1.0, 1.0, 1.0 ) );
669  m_Normals.Init( vertexCount, moColor( 0.0, 0.0, 1.0 ) );
670 
671 /*
672  int vertexCount = 4;
673 
674  m_Vertices.Set( 0, moVector3f( -1.0*radius, -1.0*radius, 0.0) );
675  m_VerticesUvs.Set( 0, moTCoord( 0.0, 1.0 ) );
676  m_Colors.Set( 0, moColor( 1.0, 1.0, 1.0 ) );
677 
678  m_Vertices.Set( 1, moVector3f( -1.0*radius, 1.0*radius, 0.0) );
679  m_VerticesUvs.Set( 1, moTCoord( 0.0, 0.0 ) );
680  m_Colors.Set( 1, moColor( 1.0, 1.0, 1.0 ) );
681 
682  m_Vertices.Set( 2, moVector3f( 1.0*radius, 1.0*radius, 0.0) );
683  m_VerticesUvs.Set( 2, moTCoord( 1.0, 0.0 ) );
684  m_Colors.Set( 2, moColor( 1.0, 1.0, 1.0 ) );
685 
686  m_Vertices.Set( 3, moVector3f( 1.0*radius, -1.0*radius, 0.0) );
687  m_VerticesUvs.Set( 3, moTCoord( 1.0, 1.0 ) );
688  m_Colors.Set( 3, moColor( 1.0, 1.0, 1.0 ) );
689 
690  m_Faces.Add( moFace( 0, 1, 2 ) );
691  m_Faces.Add( moFace( 2, 3, 0 ) );
692 */
693 
695  int index = 0;
696  float thetaEnd = thetaStart + thetaLength;
697  for ( int j = 0; j <= heightSegments; j++ ) {
698 
699  float v = (float)j / (float)heightSegments;
700 
701  for ( int i = 0; i <= widthSegments; i++ ) {
702 
703  float u = ((float)i) / ((float)widthSegments);
704 
705  float px = - radius * moMathf::Cos( phiStart + u * phiLength ) * moMathf::Sin( thetaStart + v * thetaLength );
706  float py = radius * moMathf::Cos( thetaStart + v * thetaLength );
707  float pz = radius * moMathf::Sin( phiStart + u * phiLength ) * moMathf::Sin( thetaStart + v * thetaLength );
708 
709  moVector3f normal( px, py, pz );
710  normal.Normalize();
711  moVector3f position( px, py, pz );
712  moTCoord tcoord( u, 1-v );
713  m_Vertices.Set( index, position );
714  m_VerticesUvs.Set( index, tcoord );
715  m_Normals.Set( index, normal );
716  index ++;
717  }
718  }
719 
720  for ( int j = 0; j < heightSegments; j ++ ) {
721 
722  for ( int i = 0; i < widthSegments; i ++ ) {
723 
724  int i1 = j*(widthSegments+1) + i + 1;
725  int i2 = j*(widthSegments+1) + i;
726  int i3 = (j + 1)*(widthSegments+1) + i;
727  int i4 = (j + 1)*(widthSegments+1) + i + 1;
728 
729  if ( j != 0 || thetaStart > 0 ) {
730  m_Faces.Add( moFace( i1, i2, i4 ) );
731  }
732  if ( j != heightSegments - 1 || thetaEnd < moMathf::PI ) {
733  m_Faces.Add( moFace( i2, i3, i4 ) );
734  }
735 
736  }
737 
738  }
739 /*
740  this.setIndex( new ( positions.count > 65535 ? THREE.Uint32Attribute : THREE.Uint16Attribute )( indices, 1 ) );
741  this.addAttribute( 'position', positions );
742  this.addAttribute( 'normal', normals );
743  this.addAttribute( 'uv', uvs );
744 
745  this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
746 
747  */
748 
762  /*
763  m_VerticesBuffer = new float [ m_Faces.Count()*3*3 ];
764  m_VerticesUVBuffer = new float [ m_Faces.Count()*3*2 ];
765  m_ColorBuffer = new float [ m_Faces.Count()*3*3 ];
766 
767  if (m_VerticesBuffer && m_VerticesUVBuffer && m_ColorBuffer ) {
768  for( MOuint i=0;i<m_Faces.Count(); i++) {
769  moFace& Face( m_Faces[i] );
770  for( int pi=0; pi<3; pi++ ) {
771  int vpos = Face[pi];
772  int indexv3 = i*9+pi;///i*9 = each face is a triangle, 3 components * 3 vertices
773  int indexv2 = i*6+pi;
775  m_VerticesBuffer[ indexv3 ] = m_Vertices[ vpos ].X();
776  m_VerticesBuffer[ indexv3 + 1 ] = m_Vertices[ vpos ].Y();
777  m_VerticesBuffer[ indexv3 + 2 ] = m_Vertices[ vpos ].Z();
779  m_VerticesUVBuffer[ indexv2 ] = m_VerticesUvs[vpos].X();
780  m_VerticesUVBuffer[ indexv2 + 1 ] = m_VerticesUvs[vpos].Y();
782  m_ColorBuffer[ indexv3 ] = m_Colors[vpos].X();
783  m_ColorBuffer[ indexv3 + 1 ] = m_Colors[vpos].Y();
784  m_ColorBuffer[ indexv3 + 2 ] = m_Colors[vpos].Z();
785 
786  }
787  }
788  }
789  */
790 
791 /*
792  moDebugManager::Message( " SphereGeometry :" + IntToStr(vertexCount));
793  for( int i=0; i<vertexCount; i++ ) {
794 
795  moVertex& vv( m_Vertices[i] );
796  moColor& cc( m_Colors[i] );
797  moTCoord& tc( m_VerticesUvs[i] );
798 
799  moDebugManager::Message( " i:" + IntToStr(i)
800  + " px: " + FloatToStr(vv.X(),2,2)
801  + " py: " + FloatToStr(vv.Y(),2,2)
802  + " pz: " + FloatToStr(vv.Z(),2,2)
803  + " cr: " + FloatToStr( cc.X(),2,2)
804  + " cg: " + FloatToStr( cc.Y(),2,2)
805  + " cb: " + FloatToStr( cc.Z(),2,2)
806  + " tu: " + FloatToStr( tc.X(),2,2)
807  + " tv: " + FloatToStr( tc.Y(),2,2)
808 
809  );
810  }
811 
812  for( int i=0; i<m_Faces.Count(); i++ ) {
813  for( int pi=0; pi<3; pi++ ) {
814  int indexv3 = i*9+pi;///i*9 = each face is a triangle, 3 components * 3 vertices
815  int indexv2 = i*6+pi;
816  moVertex vv( m_VerticesBuffer[indexv3],
817  m_VerticesBuffer[indexv3+1],
818  m_VerticesBuffer[indexv3+2]
819  );
820  moColor cc( m_ColorBuffer[indexv3],
821  m_ColorBuffer[indexv3+1],
822  m_ColorBuffer[indexv3+2] );
823  moTCoord tc( m_VerticesUVBuffer[indexv2],
824  m_VerticesUVBuffer[indexv2+1] );
825 
826  moDebugManager::Message( " Face i:" + IntToStr(i)
827  + " px: " + FloatToStr(vv.X(),2,2)
828  + " py: " + FloatToStr(vv.Y(),2,2)
829  + " pz: " + FloatToStr(vv.Z(),2,2)
830  + " cr: " + FloatToStr( cc.X(),2,2)
831  + " cg: " + FloatToStr( cc.Y(),2,2)
832  + " cb: " + FloatToStr( cc.Z(),2,2)
833  + " tu: " + FloatToStr( tc.X(),2,2)
834  + " tv: " + FloatToStr( tc.Y(),2,2)
835 
836  );
837  }
838  }
839 */
840 }
841 
843 /*
844  if (m_VerticesBuffer) { delete[] m_VerticesBuffer; m_VerticesBuffer = NULL; }
845  if (m_VerticesUVBuffer) { delete[] m_VerticesUVBuffer; m_VerticesUVBuffer = NULL; }
846  if (m_ColorBuffer) { delete[] m_ColorBuffer; m_ColorBuffer = NULL; }
847  */
848 }
849 
850 
851 
852 
853 
855 
857 
858  m_Position = moPosition( 0.0, 0.0, 0.0 );
859  m_Rotation = moVector3f( 0.0, 0.0, 0.0 );
860  m_Scale = moVector3f( 1.0, 1.0, 1.0 );
862  m_Parent = NULL;
863  m_Id = 0;
864 
865 }
866 
867 
873  m_Id = -1;
874  m_Name = "";
875  m_Type = "MaterialBase";
876  m_fOpacity = 1.0;
877  m_bDepthTest = true;
878  m_bDepthWrite = true;
879  m_bInitialized = true;
881  m_bTransparent = true;
882  m_iBlendEquation = 0;
883  m_fAlphaTest = true;
884  m_iBlendDst = 0;
885  m_iBlendSrc = 0;
886  m_fWireframeWidth = 0.0;
887  m_fTextWSegments = 1.0;
888  m_fTextHSegments = 1.0;
889  m_vLight = moVector3f( -1, -1, -1 );
890 }
891 moMaterialBase::moMaterialBase(int p_Id, const moText& p_Name) {
892  (*this) = moMaterialBase();
893  m_Id = p_Id;
894  m_Name = p_Name;
895 }
896 
897 const moMaterialBase&
899  m_Id = p_src.m_Id;
900  m_Name = p_src.m_Name;
901  m_fOpacity = p_src.m_fOpacity;
903  m_iBlending = p_src.m_iBlending;
904  m_iBlendSrc = p_src.m_iBlendSrc;
905  m_iBlendDst = p_src.m_iBlendDst;
907  m_bDepthTest = p_src.m_bDepthTest;
912  m_vLight = p_src.m_vLight;
913 
917  m_fAlphaTest = p_src.m_fAlphaTest;
918  m_fOverdraw = p_src.m_fOverdraw;
919  m_iSides = p_src.m_iSides;
920  m_Type = p_src.m_Type;
921  return (*this);
922 }
923 
924 
931  m_Map = NULL;
932  m_Type = "Material";
933  m_Color = moColor( 1.0, 1.0, 1.0 );
934  m_MapGLId = -1;
935 }
936 
937 const moMaterial&
939  m_Id = p_src.m_Id;
940  m_Name = p_src.m_Name;
941  m_fOpacity = p_src.m_fOpacity;
943  m_iBlending = p_src.m_iBlending;
944  m_iBlendSrc = p_src.m_iBlendSrc;
945  m_iBlendDst = p_src.m_iBlendDst;
947  m_bDepthTest = p_src.m_bDepthTest;
952  m_vLight = p_src.m_vLight;
953 
957  m_fAlphaTest = p_src.m_fAlphaTest;
958  m_fOverdraw = p_src.m_fOverdraw;
959  m_iSides = p_src.m_iSides;
960  m_Type = p_src.m_Type;
961 
962  m_Map = p_src.m_Map;
963  m_MapGLId = p_src.m_MapGLId;
964  m_Color = p_src.m_Color;
967 
969  m_Blending = p_src.m_Blending;
970  return (*this);
971 }
972 
973 
974 //===========================================
975 //
976 // moGUIManager
977 //
978 //===========================================
979 
980 
982 
985 
986  SetName("guimanager");
987  SetLabelName("guimanager");
988 /*
989  hOpWnd = NULL;
990  hVisWnd = NULL;
991  */
992  m_OpHandle = (MO_HANDLE) NULL;
993  m_VisHandle = (MO_HANDLE) NULL;
994 }
995 
996 
998 
999  Finish();
1000 
1001 }
1002 
1003 MOboolean
1004 moGUIManager::Init(/*HWND p_hOpWnd, HWND p_hVisWnd*/) {
1005 /*
1006  if (p_hOpWnd != NULL)
1007  {
1008  hOpWnd = p_hOpWnd;
1009  }
1010  else
1011  {
1012  SDL_SysWMinfo wmInfo;
1013  if (SDL_GetWMInfo(&wmInfo)) hOpWnd = wmInfo.window;
1014  }
1015 
1016  if (p_hVisWnd != NULL)
1017  {
1018  hVisWnd = p_hVisWnd;
1019  }
1020  else
1021  {
1022  }
1023 
1024  MODebug2->Push("Handle of Operation Window = " + IntToStr((int)hOpWnd));
1025  MODebug2->Push("Handle of Visualization Window = " + IntToStr((int)hVisWnd));
1026 */
1027  return true;
1028 }
1029 
1030 MOboolean
1031 moGUIManager::Init( MO_HANDLE p_OpWindowHandle, MO_DISPLAY p_Display ) {
1032  SetDisplay( p_Display );
1033  SetOpWindowHandle( p_OpWindowHandle );
1034  return true;
1035 }
1036 
1037 MOboolean
1039  return true;
1040 }
1041 
1042 moWindow*
1044 
1045  MODebug2->Message("moGUIManager::NewWindow NOT IMPLEMENTED > x: " + FloatToStr(x)
1046  + " y: " + FloatToStr(y)
1047  + " width: " + FloatToStr(width)
1048  + " height: " + FloatToStr(height) );
1049  textheap.Push("NewWindow");
1050  return NULL;
1051 }
1052 
1053 void
1054 moGUIManager::DisplayInfoWindow( MOfloat x, MOfloat y, MOfloat width, MOfloat height, moTextArray &pTexts ) {
1055 
1056  moWindow* pWindow = NULL;
1057  pWindow = new moWindow();
1058  if (pWindow) {
1059  if (pWindow->Init( m_pResourceManager, x, y , width, height)) {
1060  pWindow->SetInfo( pTexts );
1061  pWindow->Draw();
1062  }
1063  }
1064 
1065  delete pWindow;
1066 }
1067 
1068 void
1069 moGUIManager::SetDisplay( MO_DISPLAY p_Display ) {
1070 
1071  m_Display = p_Display;
1072 
1073 }
1074 
1075 void
1076 moGUIManager::SetOpWindowHandle( MO_HANDLE p_OpHandle ) {
1077 
1078  m_OpHandle = p_OpHandle;
1079 
1080 }
1081 
1082 void
1083 moGUIManager::SetVisWindowHandle( MO_HANDLE p_VisHandle ) {
1084 
1085  m_VisHandle = p_VisHandle;
1086 
1087 }
1088 
1089 MO_DISPLAY
1091 
1092  return m_Display;
1093 
1094 }
1095 
1096 
1097 MO_HANDLE
1099 
1100  return m_OpHandle;
1101 
1102 }
1103 
1104 MO_HANDLE
1106 
1107  return m_VisHandle;
1108 
1109 }
1110 
1111 //===========================================
1112 //
1113 // moGUIObject
1114 //
1115 //===========================================
1116 
1118  m_pResourceManager = NULL;
1119 }
1120 
1122  Finish();
1123 }
1124 
1125 MOboolean
1126 moGuiObject::Init( moResourceManager* pResourceManager ) {
1127  m_pResourceManager = pResourceManager;
1128  if (m_pResourceManager)
1129  m_bInitialized = true;
1130  return moAbstract::Init();
1131 }
1132 
1133 MOboolean
1135  return false;
1136 }
1137 
1138 
1139 //===========================================
1140 //
1141 // moWidget
1142 //
1143 //===========================================
1144 
1146 
1147 }
1148 
1150  Finish();
1151 }
1152 
1153 
1154 //===========================================
1155 //
1156 // moWindow
1157 //
1158 //===========================================
1159 
1161 
1162 }
1163 
1165  Finish();
1166 }
1167 
1168 MOboolean
1169 moWindow::Init( moResourceManager* pResourceManager, MOfloat x, MOfloat y, MOfloat width, MOfloat height ) {
1170 
1171  m_bInitialized = moWidget::Init(pResourceManager);
1172 
1173  m_X = x;
1174  m_Y = y;
1175  m_Width = width;
1176  m_Height = height;
1177 
1178  return moAbstract::Init();
1179 
1180 }
1181 
1182 void
1183 moWindow::SetInfo( moTextArray &pTexts ) {
1184 
1185  MOuint i;
1186 
1187  m_Texts.Empty();
1188 
1189  for(i=0; i<pTexts.Count(); i++) {
1190  m_Texts.Add(pTexts[i]);
1191  }
1192 
1193 }
1194 
1195 void
1197 
1198  glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
1199 
1200  glBindTexture( GL_TEXTURE_2D, 0 );
1201  glColor4f( 0.3, 0.3, 0.3, 0.75 );
1202 
1203 #ifndef OPENGLESV2
1204  glBegin(GL_QUADS);
1205  glTexCoord2f( 0, 0);
1206  glVertex2f( m_X, m_Y);
1207 
1208  glTexCoord2f( 0, 1);
1209  glVertex2f( m_X+m_Width, m_Y);
1210 
1211  glTexCoord2f( 1, 1);
1212  glVertex2f( m_X+m_Width, m_Y+m_Height);
1213 
1214  glTexCoord2f( 1, 0);
1215  glVertex2f( m_X, m_Y+m_Height);
1216  glEnd();
1217 #endif
1218  moFont* pFont = NULL;
1219  pFont = m_pResourceManager->GetFontMan()->GetFonts()->Get(0);
1220 
1221  if (pFont) {
1222  //pFont->SetForegroundColor( 0.0, 1.0, 0.0 );
1224  if (m_Texts.Count()>0 && m_Height>0) {
1225  float size = (float)m_Height / (float)m_Texts.Count();
1226  glColor4f( 1.0, 1.0, 1.0, 1.0 );
1227 #ifndef OPENGLESV2
1228  glScalef( size, size, size);
1229 #endif
1230  //MODebug2->Push("size:"+FloatToStr(size));
1231  for( MOuint i=0; i<m_Texts.Count(); i++ ) {
1232  //MODebug2->Push("text: i " + m_Texts[i]+ "m_X:"+FloatToStr(m_X)+ "m_Y:"+FloatToStr(m_Y) );
1233  //pFont->Draw( m_X , m_Y + m_Height - (size*1.5)*(i+1) , m_Texts[i], size);
1234  pFont->Draw( m_X/size , m_Y/size + i*1.2 , m_Texts[i], 1 );
1235  }
1236  }
1237  }
1238 
1239 }
1240 
1241 void
1243 
1244 }
1245 
1246 void
1248 
1249 
1250 }
1251 
1252 //===========================================
1253 //
1254 // mo3dWidget
1255 //
1256 //===========================================
1257 
1259 
1260 }
1261 
1263 
1264 }
1265 
1266 void
1268 
1269 }
1270 
1271 void
1273 
1274 }
1275 
1276 void
1278 
1279 
1280 }
moVector3f m_vLight
Definition: moGUIManager.h:250
virtual ~moSphereGeometry()
void SetVisWindowHandle(MO_HANDLE p_VisHandle)
virtual float * GetVerticesUVBuffer()
virtual float * GetColorBuffer()
float m_fTextHSegments
Definition: moGUIManager.h:249
moVector3f m_Scale
Definition: moGUIManager.h:319
moBoxGeometry(float width=1.0, float height=1.0, float depth=1.0, int wsegments=1, int hsegments=1, int dsegments=1)
void SetName(const moText &p_name)
void SetOpWindowHandle(MO_HANDLE p_OpHandle)
clase base para una fuente 3d o 2d
Definition: moFontManager.h:63
float m_fTextWSegments
Definition: moGUIManager.h:248
virtual ~moWindow()
MO_HANDLE GetVisWindowHandle()
moVertexArray m_Normals
Definition: moGUIManager.h:192
MO_DISPLAY GetDisplay()
void SetInfo(moTextArray &pTexts)
LIBMOLDEO_API moText0 FloatToStr(double a)
Definition: moText.cpp:1134
#define MOboolean
Definition: moTypes.h:385
Matrices para transformaciones en Open GL.
Definition: moGLManager.h:71
virtual float * GetVerticesBuffer()
moFontManager * GetFontMan()
moColor m_AmbientColor
Definition: moGUIManager.h:272
moVertex3f moPosition
Definition: moGUIManager.h:43
int m_iPolygonOffsetFactor
Definition: moGUIManager.h:253
moWindow * NewWindow(MOfloat x, MOfloat y, MOfloat width, MOfloat height, moTextHeap &textheap)
void SetResourceType(moResourceType p_restype)
static Real Sin(Real fValue)
Definition: moMath.h:260
Real Z() const
Definition: moMathVector3.h:77
virtual MOboolean Init(moResourceManager *pResourceManager, MOfloat x, MOfloat y, MOfloat width, MOfloat height)
virtual void Interaction()
int m_iPolygonOffsetUnits
Definition: moGUIManager.h:254
void SetDisplay(MO_DISPLAY p_Display)
virtual MOboolean Init()
Inicializa el objeto.
Definition: moAbstract.cpp:141
static moText TypeToStr(moGeometryType p_type)
moPointArray m_Vertices
Definition: moGUIManager.h:190
Real X() const
Definition: moMathVector3.h:73
moVector2< MOfloat > moVector2f
Definition: moMathVector.h:423
virtual moText ToJSON()
#define MOfloat
Definition: moTypes.h:403
moResourceManager * m_pResourceManager
Definition: moGUIManager.h:566
moPolygonModes m_PolygonMode
Definition: moGUIManager.h:276
virtual ~moGuiObject()
clase de para manejar textos
Definition: moText.h:75
virtual MOboolean Finish()
moResourceManager * m_pResourceManager
Puntero al administrador de recursos.
virtual ~moGUIManager()
Dispositivo de entrada/salida, típicamente, interfaces humanas de IO y datos ( teclado, mouse, tableta, tcp, udp, serial )
Definition: moTypes.h:532
moGLMatrixf & MakeIdentity()
Definition: moGLManager.cpp:79
moGLMatrixf m_ModelMatrix
virtual void SetResourceManager(moResourceManager *p_rm)
virtual void Update()
moText0 moText
Definition: moText.h:291
const moMaterial & operator=(const moMaterial &p_src)
MOfloat m_Y
Definition: moGUIManager.h:612
moColorRGB moColor
Definition: moGUIManager.h:49
moVector3f m_Rotation
Definition: moGUIManager.h:320
moPosition m_Center
Definition: moGUIManager.h:67
moGeometryType
Definition: moGUIManager.h:81
moTexture * m_Map
Definition: moGUIManager.h:274
MOfloat * m_VerticesUVBuffer
Definition: moGUIManager.h:197
moColor m_Color
Definition: moGUIManager.h:273
MOfloat * m_NormalsBuffer
Definition: moGUIManager.h:196
moVector2f moTCoord
Definition: moGUIManager.h:46
virtual MOboolean Init()
virtual MOboolean Finish()
Finaliza el objeto, libera recursos.
moFonts * GetFonts()
virtual ~moGeometry()
Administrador de recursos.
const MOlong PI
Definition: moMath.cpp:44
MOfloat m_X
Definition: moGUIManager.h:611
Real Normalize()
void SetLabelName(const moText &p_labelname)
lista de textos
Definition: moText.h:306
virtual ~moWidget()
void Draw(MOfloat x, MOfloat y, moText &text)
moColorArray m_Colors
Definition: moGUIManager.h:193
float m_fWireframeWidth
Definition: moGUIManager.h:247
void Push(const moText &p_text)
Definition: moText.h:316
Base abstracta de base para las geometrías.
Definition: moGUIManager.h:127
static moDebug * MODebug2
Clase de impresión de errores para depuración
Definition: moAbstract.h:225
MOfloat * m_VerticesBuffer
Definition: moGUIManager.h:195
static Real Cos(Real fValue)
Definition: moMath.h:160
moVector3i moFace
Definition: moGUIManager.h:44
moCamera3D & operator=(const moCamera3D &p_src)
moSphereGeometry(float radius=1.0, int widthSegments=8, int heightSegments=8, float phiStart=0.0, float phiLength=moMathf::TWO_PI, float thetaStart=0.0, float thetaLength=moMathf::PI)
MOfloat m_Width
Definition: moGUIManager.h:613
void applyMatrix(const moGLMatrixf &p_ModelMatrix)
Real Y() const
Definition: moMathVector3.h:75
moGeometry & operator=(const moGeometry &p_src)
virtual void Draw()
MOfloat m_Height
Definition: moGUIManager.h:614
virtual MOboolean Finish()
Finaliza el objeto, libera recursos.
moPlaneGeometry(float width=1.0, float height=1.0, int widthSegments=1.0, int heightSegments=1.0)
MOfloat * m_ColorBuffer
Definition: moGUIManager.h:198
moTCoordArray m_VerticesUvs
Definition: moGUIManager.h:191
const moMaterialBase & operator=(const moMaterialBase &p_src)
virtual MOboolean Init()
Inicializa el objeto.
moBlendingModes m_Blending
Definition: moGUIManager.h:277
moPosition m_Position
Definition: moGUIManager.h:318
moTextArray m_Texts
Definition: moGUIManager.h:609
moColor m_SpecularColor
Definition: moGUIManager.h:271
virtual ~moBoxGeometry()
virtual ~moPlaneGeometry()
#define MOuint
Definition: moTypes.h:387
moVector3< MOfloat > moVector3f
Ventana simple.
Definition: moGUIManager.h:596
virtual ~moPolyhedronGeometry()
MO_HANDLE GetOpWindowHandle()
virtual ~mo3dWidget()
virtual void Draw()
MOboolean m_bInitialized
Valor de inicialización
Definition: moAbstract.h:223
moText m_Name
Definition: moGUIManager.h:187
moTCoordArray m_FaceVertexUvs
Definition: moGUIManager.h:201
moPosition m_Position
Definition: moGUIManager.h:66
moSceneNode * m_Parent
void DisplayInfoWindow(MOfloat x, MOfloat y, MOfloat width, MOfloat height, moTextArray &pTexts)
virtual void Interaction()
void Message(moText p_text)
Anuncia un mensaje al usuario además de guardarlo en el log de texto.
Definition: moAbstract.cpp:114
void SetType(moMoldeoObjectType p_type)
virtual float * GetNormalsBuffer()
moFaceArray m_Faces
Definition: moGUIManager.h:200
MOint m_MapGLId
Definition: moGUIManager.h:275
moDefineDynamicArray(moGuiObjectArray) moDefineDynamicArray(moAttributeArray) moCamera3D
moGeometryType m_Type
Definition: moGUIManager.h:188
virtual void Update()