File: cuboid.cpp

package info (click to toggle)
gem 1%3A0.94-10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 25,704 kB
  • sloc: cpp: 174,301; ansic: 42,132; makefile: 3,867; sh: 1,096; objc: 389
file content (185 lines) | stat: -rw-r--r-- 6,107 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
////////////////////////////////////////////////////////
//
// GEM - Graphics Environment for Multimedia
//
// mark@danks.org
//
// Implementation file
//
//    Copyright (c) 1997-2000 Mark Danks.
//    For information on usage and redistribution, and for a DISCLAIMER OF ALL
//    WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution.
//
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
//
// modified cube geos into cuboid by erich berger 2001 rat@telecoma.net
//
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////

#include "cuboid.h"
#include "Gem/State.h"
#include <string.h>

CPPEXTERN_NEW_WITH_THREE_ARGS(cuboid, t_floatarg, A_DEFFLOAT, t_floatarg,
                              A_DEFFLOAT, t_floatarg, A_DEFFLOAT );

/////////////////////////////////////////////////////////
//
// cuboid
//
/////////////////////////////////////////////////////////
// Constructor
//
/////////////////////////////////////////////////////////
cuboid :: cuboid(t_floatarg sizex, t_floatarg sizey, t_floatarg sizez)
  : GemShape(sizex), m_sizey(sizey), m_sizez(sizez)
{
  if (m_sizey == 0.f) {
    m_sizey = 1.f;
  }
  if (m_sizez == 0.f) {
    m_sizez = 0.f;
  }

  m_inletY = inlet_new(this->x_obj, &this->x_obj->ob_pd, &s_float,
                       gensym("ft2"));
  m_inletZ = inlet_new(this->x_obj, &this->x_obj->ob_pd, &s_float,
                       gensym("ft3"));
}

/////////////////////////////////////////////////////////
// Destructor
//
/////////////////////////////////////////////////////////
cuboid :: ~cuboid(void)
{
  inlet_free(m_inletY);
  inlet_free(m_inletZ);
}

/////////////////////////////////////////////////////////
// renderShape
//
/////////////////////////////////////////////////////////
void cuboid :: renderShape(GemState *state)
{
  if(m_drawType==GL_DEFAULT_GEM) {
    m_drawType=GL_QUADS;
  }

  static GLfloat n[6][3] = {
    { 0.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 0.0f}, {0.0f,  0.0f, -1.0f},
    {-1.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, -1.0f,  0.0f}
  };
  static GLfloat v[8][3] = {
    {-1.0f, -1.0f,  1.0f}, { 1.0f, -1.0f,  1.0f}, { 1.0f, 1.0f,  1.0f}, {-1.0f, 1.0f,  1.0f},
    { 1.0f, -1.0f, -1.0f}, {-1.0f, -1.0f, -1.0f}, {-1.0f, 1.0f, -1.0f}, { 1.0f, 1.0f, -1.0f}
  };
  static GLint faces[6][4] = {
    { 0, 1, 2, 3 }, { 1, 4, 7, 2 }, { 4, 5, 6, 7 },
    { 5, 0, 3, 6 }, { 3, 2, 7, 6 }, { 1, 0, 5, 4 }
  };
  if (m_drawType == GL_LINE_LOOP) {
    for (int i = 0; i < 6; i++) {
      glBegin(m_drawType);
      glNormal3f(0.0f, 0.0f, 1.0f);
      glVertex3d(v[faces[i][0]][0] * m_size, v[faces[i][0]][1] * m_sizey,
                 v[faces[i][0]][2] * m_sizez);
      glVertex3d(v[faces[i][1]][0] * m_size, v[faces[i][1]][1] * m_sizey,
                 v[faces[i][1]][2] * m_sizez);
      glVertex3d(v[faces[i][2]][0] * m_size, v[faces[i][2]][1] * m_sizey,
                 v[faces[i][2]][2] * m_sizez);
      glVertex3d(v[faces[i][3]][0] * m_size, v[faces[i][3]][1] * m_sizey,
                 v[faces[i][3]][2] * m_sizez);
      glEnd();
    }
    glLineWidth(1.0);
  } else if (GemShape::m_texType && GemShape::m_texNum) {
    glBegin(m_drawType);
    for (int i = 0; i < 6; i++) {
      int curCoord = 0;
      glNormal3fv(&n[i][0]);
      glTexCoord2f(GemShape::m_texCoords[curCoord].s,
                   GemShape::m_texCoords[curCoord].t);
      //              glTexCoord2f(0.0, 0.0);
      glVertex3f(v[faces[i][0]][0] * m_size, v[faces[i][0]][1] * m_sizey,
                 v[faces[i][0]][2] * m_sizez);

      if (GemShape::m_texNum > 1) {
        curCoord = 1;
      }
      glTexCoord2f(GemShape::m_texCoords[curCoord].s,
                   GemShape::m_texCoords[curCoord].t);
      //              glTexCoord2f(1.0, 0.0);
      glVertex3f(v[faces[i][1]][0] * m_size, v[faces[i][1]][1] * m_sizey,
                 v[faces[i][1]][2] * m_sizez);

      if (GemShape::m_texNum > 2) {
        curCoord = 2;
      }
      glTexCoord2f(GemShape::m_texCoords[curCoord].s,
                   GemShape::m_texCoords[curCoord].t);
      //              glTexCoord2f(1.0, 1.0);
      glVertex3f(v[faces[i][2]][0] * m_size, v[faces[i][2]][1] * m_sizey,
                 v[faces[i][2]][2] * m_sizez);

      if (GemShape::m_texNum > 3) {
        curCoord = 3;
      }
      glTexCoord2f(GemShape::m_texCoords[curCoord].s,
                   GemShape::m_texCoords[curCoord].t);
      //              glTexCoord2f(0.0, 1.0);
      glVertex3f(v[faces[i][3]][0] * m_size, v[faces[i][3]][1] * m_sizey,
                 v[faces[i][3]][2] * m_sizez);
    }
    glEnd();
  } else {
    glBegin(m_drawType);
    for (int i = 0; i < 6; i++) {
      glNormal3fv(&n[i][0]);
      glTexCoord2f(0.0, 0.0);
      glVertex3f(v[faces[i][0]][0] * m_size, v[faces[i][0]][1] * m_sizey,
                 v[faces[i][0]][2] * m_sizez);
      glTexCoord2f(1.0, 0.0);
      glVertex3f(v[faces[i][1]][0] * m_size, v[faces[i][1]][1] * m_sizey,
                 v[faces[i][1]][2] * m_sizez);
      glTexCoord2f(1.0, 1.0);
      glVertex3f(v[faces[i][2]][0] * m_size, v[faces[i][2]][1] * m_sizey,
                 v[faces[i][2]][2] * m_sizez);
      glTexCoord2f(0.0, 1.0);
      glVertex3f(v[faces[i][3]][0] * m_size, v[faces[i][3]][1] * m_sizey,
                 v[faces[i][3]][2] * m_sizez);
    }
    glEnd();
  }
}
/////////////////////////////////////////////////////////
// heightMess
//
/////////////////////////////////////////////////////////
void cuboid :: heightMess(float sizey)
{
  m_sizey = sizey;
  setModified();
}
/////////////////////////////////////////////////////////
// widthMess
//
/////////////////////////////////////////////////////////
void cuboid :: widthMess(float sizez)
{
  m_sizez = sizez;
  setModified();
}

/////////////////////////////////////////////////////////
// static member function
//
/////////////////////////////////////////////////////////
void cuboid :: obj_setupCallback(t_class *classPtr)
{
  CPPEXTERN_MSG1(classPtr, "ft2", heightMess, float);
  CPPEXTERN_MSG1(classPtr, "ft3", widthMess, float);
}