home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Amiga / Jeux / demos / crystalPPC.lha / vertex.cpp < prev    next >
C/C++ Source or Header  |  1998-02-05  |  2KB  |  115 lines

  1. #include <math.h>
  2. #include <time.h>
  3. #include "system.h"
  4.  
  5. #ifndef DEF_H
  6. #include "def.h"
  7. #endif
  8.  
  9. #ifndef VERTEX_H
  10. #include "vertex.h"
  11. #endif
  12.  
  13. #ifndef TOKEN_H
  14. #include "token.h"
  15. #endif
  16.  
  17. //---------------------------------------------------------------------------
  18.  
  19. Vertex::Vertex (Vector3& v)
  20. {
  21.   set (v);
  22. }
  23.  
  24. Vertex::Vertex (float x, float y, float z)
  25. {
  26.   set (x, y, z);
  27. }
  28.  
  29. Vertex::Vertex ()
  30. {
  31. }
  32.  
  33. void Vertex::set (Vector3& v)
  34. {
  35.   Vertex::v = v;
  36. }
  37.  
  38. void Vertex::set (float x, float y, float z)
  39. {
  40.   v.x = x;
  41.   v.y = y;
  42.   v.z = z;
  43. }
  44.  
  45. void Vertex::set_t (Vector3& vr)
  46. {
  47.   Vertex::vr = vr;
  48. }
  49.  
  50. void Vertex::set_t (float x, float y, float z)
  51. {
  52.   vr.x = x;
  53.   vr.y = y;
  54.   vr.z = z;
  55. }
  56.  
  57. void Vertex::set_o (Vector3& vo)
  58. {
  59.   Vertex::vo = vo;
  60. }
  61.  
  62. void Vertex::set_o (float x, float y, float z)
  63. {
  64.   vo.x = x;
  65.   vo.y = y;
  66.   vo.z = z;
  67. }
  68.  
  69. void Vertex::dump ()
  70. {
  71.   MSG (("v:(%2.2f,%2.2f,%2.2f) vr:(%2.2f,%2.2f,%2.2f) vis=%d",
  72.     v.x, v.y, v.z, vr.x, vr.y, vr.z, visible));
  73. }
  74.  
  75. void Vertex::save (FILE* fp, int indent)
  76. {
  77.   char sp[100]; strcpy (sp, spaces); sp[indent] = 0;
  78.   fprintf (fp, "%sVERTEX (%f,%f,%f)\n", sp, vo.x, vo.y, vo.z);
  79. }
  80.  
  81. void Vertex::load (char** buf)
  82. {
  83.   skip_token (buf, "VERTEX");
  84.   skip_token (buf, "(", "Expected '%s' instead of '%s' after VERTEX statement!\n");
  85.   vo.x = get_token_float (buf);
  86.   skip_token (buf, ",", "Expected '%s' instead of '%s' for VERTEX statement!\n");
  87.   vo.y = get_token_float (buf);
  88.   skip_token (buf, ",", "Expected '%s' instead of '%s' for VERTEX statement!\n");
  89.   vo.z = get_token_float (buf);
  90.   skip_token (buf, ")", "Expected '%s' instead of '%s' to conclude VERTEX statement!\n");
  91.   v = vo;
  92. }
  93.  
  94. void Vertex::world_to_camera (Matrix3& m_w2c, Vector3& v_w2c)
  95. {
  96.   Vector3 u = v;
  97.   u -= v_w2c;
  98.   m_w2c.transform (u, vr);
  99. }
  100.  
  101. void Vertex::object_to_world (Matrix3& m_o2w, Matrix3& m_w2o, Vector3& v_o2w)
  102. {
  103.   (void)m_w2o;
  104.   m_o2w.transform (vo, v);
  105.   v -= v_o2w;
  106. }
  107.  
  108. void Vertex::translate (Vector3& trans)
  109. {
  110.   vr = v;
  111.   vr -= trans;
  112. }
  113.  
  114. //---------------------------------------------------------------------------
  115.