Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 3, 2005, 9:55:33 PM (20 years ago)
Author:
bensch
Message:

orxonox/branches/textEngine: added bind-node ability, so now the text tries to follow a given PNode (currently trackNode)
the work is not finished, so do not expect too much

Location:
orxonox/branches/textEngine/src/lib/graphics/font
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/textEngine/src/lib/graphics/font/glfont.cc

    r3714 r3715  
    5555#include <string.h>
    5656
     57#include "p_node.h"
     58#include "vector.h"
    5759#include "debug.h"
    5860
     
    128130  this->currentText = new Text;
    129131
     132  this->currentText->bindNode = NULL;
    130133  this->currentText->text = NULL;
    131134  this->currentText->texture = 0;
     
    171174}
    172175
     176void GLFont::setBindNode(PNode* bindNode)
     177{
     178  this->currentText->bindNode = bindNode;
     179}
     180
     181
    173182/**
    174183   \brief Sets a new Text to the font
     
    245254void GLFont::draw(void)
    246255{
     256  GLdouble modMat[16];
     257  GLint viewPort[4];
     258  glGetDoublev(GL_PROJECTION_MATRIX, this->projMat);
     259  glGetDoublev(GL_MODELVIEW_MATRIX, modMat);
     260  glGetIntegerv(GL_VIEWPORT, viewPort);
    247261  this->enter2DMode();
     262
     263
     264  Vector pos;
     265  if (this->currentText->bindNode)
     266    {
     267      GLdouble x = this->currentText->bindNode->getAbsCoor().x;
     268      GLdouble y = this->currentText->bindNode->getAbsCoor().y;
     269      GLdouble z = this->currentText->bindNode->getAbsCoor().z;
     270      GLdouble tmp[3];
     271      gluProject(x, y, z, modMat, projMat, viewPort, tmp, tmp+1, tmp+2);
     272      printf("test %f %f %f,\n", tmp[0], tmp[1], tmp[2]);
     273      pos.x = tmp[0];
     274      pos.y = tmp[1];
     275      pos.z = tmp[2];
     276    }
    248277
    249278  glBindTexture(GL_TEXTURE_2D, this->currentText->texture);
    250279  glEnable(GL_TEXTURE_2D);
    251280  glBegin(GL_QUADS);
    252 
     281 
    253282  glTexCoord2f(this->currentText->texCoord.minU, this->currentText->texCoord.minV);
    254   glVertex2i(20,   20  );
     283  glVertex2i(pos.x,   pos.y  );
    255284
    256285  glTexCoord2f(this->currentText->texCoord.maxU, this->currentText->texCoord.minV);
    257   glVertex2i(20+this->currentText->textPosSize.w, 20  );
     286  glVertex2i(pos.x + this->currentText->textPosSize.w, pos.y  );
    258287
    259288  glTexCoord2f(this->currentText->texCoord.maxU, this->currentText->texCoord.maxV);
    260   glVertex2i(20+this->currentText->textPosSize.w, 20+this->currentText->textPosSize.h);
     289  glVertex2i(pos.x + this->currentText->textPosSize.w, pos.y + this->currentText->textPosSize.h);
    261290
    262291  glTexCoord2f(this->currentText->texCoord.minU, this->currentText->texCoord.maxV);
    263   glVertex2i(20, 20+this->currentText->textPosSize.h);
     292  glVertex2i(pos.x, pos.y + this->currentText->textPosSize.h);
    264293
    265294  glEnd();
     
    555584
    556585}
     586
     587
     588void m_inverse(const float *m, float *out)
     589{
     590    float det;
     591    det=  m[0]*m[5]*m[10];
     592    det+= m[4]*m[9]*m[2];
     593    det+= m[8]*m[1]*m[6];
     594    det-= m[8]*m[5]*m[2];
     595    det-= m[4]*m[1]*m[10];
     596    det-= m[0]*m[9]*m[6];
     597   
     598    if(det!= 0.0)
     599        det=1.0/det;
     600    out[0]=  (m[5]*m[10]-m[9]*m[6])*det;
     601    out[1]= -(m[1]*m[10]-m[9]*m[2])*det;
     602    out[2]=  (m[1]*m[6]-m[5]*m[2])*det;
     603    out[3]= 0.0;
     604    out[4]= -(m[4]*m[10]-m[8]*m[6])*det;
     605    out[5]=  (m[0]*m[10]-m[8]*m[2])*det;
     606    out[6]= -(m[0]*m[6]-m[4]*m[2])*det;
     607    out[7]= 0.0;
     608    out[8]=  (m[4]*m[9]-m[8]*m[5])*det;
     609    out[9]= -(m[0]*m[9]-m[8]*m[1])*det;
     610    out[10]= (m[0]*m[5]-m[4]*m[1])*det;
     611    out[11]= 0.0;
     612    out[12]=- (m[12]*out[0]+m[13]*out[4]+m[14]*out[8]);
     613    out[13]=- (m[12]*out[1]+m[13]*out[5]+m[14]*out[9]);
     614    out[14]=- (m[12]*out[2]+m[13]*out[6]+m[14]*out[10]);
     615    out[15]= 1.0;
     616}
     617
     618
     619Vector mvMult(const float *mat, const Vector* vec)
     620{
     621  Vector tmp;
     622  tmp.x = mat[0]*vec->x+mat[1]*vec->y+mat[2]*vec->z;
     623  tmp.y = mat[4]*vec->x+mat[5]*vec->y+mat[6]*vec->z;
     624  tmp.z = mat[8]*vec->x+mat[9]*vec->y+mat[10]*vec->z;
     625  return tmp;
     626}
  • orxonox/branches/textEngine/src/lib/graphics/font/glfont.h

    r3714 r3715  
    1010#include "SDL_ttf.h"
    1111
    12 // FORWARD DECLARATION
     12#include "vector.h"
     13
     14// FORWARD DECLARATION
     15class PNode;
    1316template<class T> class tList;
     17
    1418
    1519/* some default values */
     
    2024#define FONT_DEFAULT_COLOR_B    256                  //!< the default red blue (color) of the text
    2125#define FONT_NUM_COLORS         256                  //!< The number of colors.
    22 
    2326
    2427
     
    5760  virtual ~GLFont();
    5861
     62  // general
    5963  static void enableFonts(void);
    6064  static void disableFonts(void);
    6165
     66  // font
    6267  bool setFont(const char* fontFile);
    63   void setText(const char* text);
    64 
    65   void setStyle(char* renderStyle);
    6668  void setSize(unsigned int fontSize);
    6769  void setColor(Uint8 r, Uint8 g, Uint8 b);
     70
     71  // text
     72  void setBindNode(PNode* bindNode);
     73  void setText(const char* text);
     74  void setStyle(char* renderStyle);
    6875  void setPosition(int x, int y);
    69 
    7076  void createTexture(void);
    7177 
     
    7379
    7480 private:
     81  // general purpose
     82  GLdouble projMat[16];             //!< The Projection Matrix
     83
    7584  // information about the Font
    7685  TTF_Font* font;                  //!< The font we use for this.
     
    8897    SDL_Rect textPosSize;            //!< An SDL-Rectangle representing the position and size of the Text on the screen.
    8998    int renderStyle;                 //!< The Renderstyle
     99
     100    PNode* bindNode;                 //!< A node the Text is bind to. (if NULL thr node will not be bound to anything.)
    90101  };
    91102  tList<Text>* textList;
     
    113124};
    114125
     126void m_inverse(const float *m, float *out);
     127Vector mvMult(const float *mat, const Vector* vec);
    115128#endif /* _GLFONT_H */
Note: See TracChangeset for help on using the changeset viewer.