00001
00002
00003 #ifndef RENDERER_H
00004 #define RENDERER_H
00005
00006 #include "params.h"
00007 #include "color.h"
00008 #include "linkedlist.cpp"
00009 #include "line.h"
00010 #include "sphere.h"
00011 #include "cylinder.h"
00012 #include "BitMapImage.h"
00013 #include "vr.h"
00014 #include "wrl.h"
00015
00016 class Mesh;
00017
00024 class Renderer {
00025
00026 friend Mesh;
00027
00028 public:
00029
00030 #ifndef SKIP_THIS
00031 Renderer();
00032 ~Renderer();
00033 #endif
00034
00035
00038
00043 RESULT setRenderMode(RENDER_MODE mode = WIREFRAME);
00048 RESULT getRenderMode(RENDER_MODE &mode);
00049
00054 RESULT setPerspective(bool perspective = true);
00059 RESULT getPerspective(bool &perspective);
00060
00065 RESULT setBackfaceCulling(bool enable = true);
00070 RESULT getBackfaceCulling(bool &enable);
00071
00076 RESULT setLineDrawing(bool enable = true);
00081 RESULT getLineDrawing(bool &enable);
00082
00087 RESULT setSphereDrawing(bool enable = true);
00092 RESULT getSphereDrawing(bool &enable);
00093
00098 RESULT setCylinderDrawing(bool enable = true);
00103 RESULT getCylinderDrawing(bool &enable);
00104
00117 RESULT displayText(const char* text = NULL, const Coord2D *coord = NULL);
00118
00126 RESULT setAutoRefresh(bool enable = true);
00131 RESULT refreshScreen();
00132
00140 RESULT setAutoScale(bool enable = true);
00141
00146 RESULT setMouseInteraction(bool enable = true);
00147
00148 #ifndef SKIP_THIS
00149 bool interactionEnabled;
00150 #endif
00151
00152
00153
00156
00157
00158
00159
00165 RESULT rotate(AXIS axis, int angle);
00172 RESULT translate(int dx, int dy, int dz=0);
00177 RESULT scale(int dy);
00178
00179 #ifndef SKIP_THIS
00180
00181 RESULT screen_rotate(float angle, int axisx, int axisy, int axisz);
00182 RESULT screen_translate(int dx, int dy, int dz=0);
00183 RESULT screen_scale(int dy);
00184 #endif
00185
00186
00187
00190
00195 RESULT setBgColor(Color color);
00200 RESULT getBgColor(Color& color);
00201
00206 RESULT setVerticesDefaultColor(Color color);
00211 RESULT getVerticesDefaultColor(Color& color);
00212
00217 RESULT setEdgesDefaultColor(Color color);
00222 RESULT getEdgesDefaultColor(Color& color);
00223
00228 RESULT setFacesDefaultColor(const Color color);
00233 RESULT getFacesDefaultColor(Color& color);
00234
00239 RESULT setLinesDefaultColor(const Color color);
00244 RESULT getLinesDefaultColor(Color& color);
00245
00250 RESULT setSpheresDefaultColor(const Color color);
00255 RESULT getSpheresDefaultColor(Color& color);
00256
00261 RESULT setCylindersDefaultColor(const Color color);
00266 RESULT getCylindersDefaultColor(Color& color);
00267
00274 RESULT setVertexColor(VertexID vID, const Color* color = NULL);
00281 RESULT getVertexColor(VertexID vID, Color& color);
00282
00289 RESULT setEdgeColor(EdgeID eID, const Color* color = NULL);
00296 RESULT getEdgeColor(EdgeID eID, Color& color);
00297
00304 RESULT setFaceColor(FaceID fID, const Color* color = NULL);
00311 RESULT getFaceColor(FaceID fID, Color& color);
00312
00319 RESULT setLineColor(LineID lID, const Color* color = NULL);
00326 RESULT getLineColor(LineID lID, Color& color);
00327
00334 RESULT setSphereColor(SphereID sID, const Color* color = NULL);
00341 RESULT getSphereColor(SphereID sID, Color& color);
00342
00349 RESULT setCylinderColor(CylinderID cID, const Color* color = NULL);
00356 RESULT getCylinderColor(CylinderID cID, Color& color);
00357
00363 RESULT setAllVerticesColor(Color color);
00369 RESULT setAllEdgesColor(Color color);
00375 RESULT setAllFacesColor(Color color);
00381 RESULT setAllLinesColor(Color color);
00387 RESULT setAllSpheresColor(Color color);
00393 RESULT setAllCylindersColor(Color color);
00394
00399 RESULT setTextColor(Color color);
00404 RESULT getTextColor(Color& color);
00405
00411 RESULT colorFaces(const LinkedList<FaceID>* faces = NULL);
00413
00414
00417
00423 RESULT highlightAllVertices(bool highlight=true);
00429 RESULT highlightAllEdges(bool highlight=true);
00435 RESULT highlightAllFaces(bool highlight=true);
00436
00441 RESULT getHighlightAllVertices(bool &highlight);
00446 RESULT getHighlightAllEdges(bool &highlight);
00451 RESULT getHighlightAllFaces(bool &highlight);
00452
00459 RESULT highlightVertex(VertexID vID, bool highlight=true);
00466 RESULT highlightEdge(EdgeID eID, bool highlight=true);
00473 RESULT highlightFace(FaceID fID, bool highlight=true);
00475
00476
00479
00487 RESULT pickVertex(VertexID& vID, unsigned int timeOut = 0);
00495 RESULT pickEdge(EdgeID& eID, unsigned int timeOut = 0);
00503 RESULT pickFace(FaceID& fID, unsigned int timeOut = 0);
00504 #ifndef SKIP_THIS
00505 RESULT processSelection(GLint hits, GLuint selectBuf[512]);
00506 bool inPickingMode;
00507 #endif
00508
00509
00510
00513
00518 RESULT setTextureMapping(bool enable=true);
00523 RESULT getTextureMapping(bool &enable);
00531 RESULT setTextureImage(const char* fileName);
00538 RESULT getTextureImage(char* fileName);
00550 RESULT setVertexUV(VertexID vID, double u, double v);
00565 RESULT setVerticesUV(const LinkedList<VertexID> *vertices, const LinkedList<Coord2D> *coords);
00573 RESULT getVertexUV(VertexID vID, double &u, double &v);
00575
00576
00578 #ifndef SKIP_THIS
00579
00580 RESULT setProjection();
00581
00582 RESULT setSize(int cx, int cy);
00583
00584 RESULT reset();
00585 RESULT resetModel();
00586
00587
00588 RESULT setMesh(Mesh* mesh);
00589 RESULT render(bool selectionMode=false);
00590 #endif
00591
00592 private:
00593
00594
00595 Mesh* mesh;
00596 RENDER_MODE renderMode;
00597 bool perspective;
00598 bool backfaceRemoval;
00599 bool autoRefresh;
00600 bool refreshCalled;
00601 bool autoScale;
00602 RESULT renderFaces(VRIndexedFaceSet *vrIFS, bool selectionMode);
00603 RESULT renderWireframe(VRIndexedFaceSet *vrIFS, bool selectionMode);
00604 RESULT renderVertices(VRIndexedFaceSet *vrIFS, bool selectionMode);
00605 RESULT renderHighlightedFaces(VRIndexedFaceSet *vrIFS, bool selectionMode);
00606 RESULT renderHighlightedEdges(VRIndexedFaceSet *vrIFS, bool selectionMode);
00607 RESULT renderHighlightedVertices(VRIndexedFaceSet *vrIFS, bool selectionMode);
00608 RESULT renderLines(bool selectionMode);
00609 RESULT renderSpheres(bool selectionMode);
00610 RESULT renderCylinders(bool selectionMode);
00611 void findOrthonormalVectors(Coord &z, Coord &x, Coord &y);
00612
00613
00614 bool drawLines;
00615 double lineDefaultWidth;
00616
00617
00618 bool drawSpheres;
00619
00620
00621 bool drawCylinders;
00622
00623 char text[MAX_STRING_SIZE];
00624 Coord2D textCoord;
00625 bool newText;
00626 void drawText(double TR);
00627
00628
00629 Color bgColor;
00630 Color vertexDefaultColor;
00631 Color edgeDefaultColor;
00632 Color faceDefaultColor;
00633 Color lineDefaultColor;
00634 Color sphereDefaultColor;
00635 Color cylinderDefaultColor;
00636 Color textColor;
00637 double ambient, diffuse;
00638
00639
00640 bool doHighlightAllVertices;
00641 bool doHighlightAllEdges;
00642 bool doHighlightAllFaces;
00643 LinkedList<VertexID> *verticesToHighlight;
00644 LinkedList<EdgeID> *edgesToHighlight;
00645 LinkedList<FaceID> *facesToHighlight;
00646
00647
00648 Coord centerRot;
00649 float transformMatrix[16];
00650 float rotateMatrix[16];
00651 void unifyTransformMatrix();
00652 void unifyRotateMatrix();
00653 float scalingParameter;
00654 void initialTranslate(double x, double y, double z);
00655 void initialScale(double val);
00656 void drawBox(GLfloat size);
00657
00658
00659
00660
00661
00662 bool textureMapping;
00663 CBitMapImage img;
00664
00665
00666
00667 HANDLE pickingMutex;
00668 PICKING_MODE pickingMode;
00669 long pickedItem;
00670 bool processHits(GLint hits, GLuint buffer[]);
00671 };
00672
00673 #ifndef SKIP_THIS
00674
00675
00676 extern HWND getHWND();
00677 extern void refresh();
00678 extern RECT getClientRect();
00679
00680 #endif
00681
00682 extern Renderer *renderer;
00683
00684 #endif