-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample.cpp
More file actions
233 lines (211 loc) · 7.01 KB
/
sample.cpp
File metadata and controls
233 lines (211 loc) · 7.01 KB
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
// The sample model. You should build a file
// very similar to this for when you make your model.
#include "modelerview.h"
#include "modelerapp.h"
#include "modelerdraw.h"
#include "modelerglobals.h"
#include "mat.h"
#include "vec.h"
#include <FL/gl.h>
#include <math.h>
#include <GL/glu.h>
#include <cstdio>
#include <vector>
#include <iostream>
using namespace std;
// To make a SampleModel, we inherit off of ModelerView
class SampleModel : public ModelerView
{
public:
SampleModel(int x, int y, int w, int h, char *label)
: ModelerView(x,y,w,h,label) { }
virtual void draw();
void addCustomLighting();
// void drawTextureBox(double x, double y, double z);
// void drawTextureCylinder(double h, double r1, double r2);
};
// We need to make a creator function, mostly because of
// nasty API stuff that we'd rather stay away from.
ModelerView* createSampleModel(int x, int y, int w, int h, char *label)
{
return new SampleModel(x,y,w,h,label);
}
// We are going to override (is that the right word?) the draw()
// method of ModelerView to draw out SampleModel
void SampleModel::draw()
{
// This call takes care of a lot of the nasty projection
// matrix stuff. Unless you want to fudge directly with the
// projection matrix, don't bother with this ...
ModelerView::draw();
addCustomLighting(); //Whistle No.1
// draw the floor
setAmbientColor(.1f,.1f,.1f);
setDiffuseColor(COLOR_RED);
glPushMatrix();
glTranslated(-5,0,-5);
drawBox(10,0.01f,10);
glPopMatrix();
// draw the sample model
setAmbientColor(.1f,.1f,.1f);
setDiffuseColor(COLOR_GREEN);
glPushMatrix();
glTranslated(VAL(XPOS), VAL(YPOS), VAL(ZPOS));
// draw base
glPushMatrix();
glTranslated(-1.5, 0, -1.5);
glScaled(3, 0.3, 3);
drawTextureBox(1, 1, 1);
// drawBox(1, 1, 1);
glPopMatrix();
// draw central column
glPushMatrix();
glRotated(VAL(ROTATE), 0.0, 1.0, 0.0);
glRotated(-90, 1.0, 0.0, 0.0);
drawTextureCylinder(5+VAL(HEIGHT), 0.1, 0.1);
glTranslated(0.0, 0.0, 5+VAL(HEIGHT));
// draw hat
drawCylinder(1, 5, 0.1);
glTranslated(0,0,2);
drawSphere(1);
//draw 8 arms
glTranslated(0.0, 3.5, -5-sin(VAL(ROTATE)*M_PI/180));
drawTextureCylinder(3+sin(VAL(ROTATE)*M_PI/180), 0.1, 0.2); //sin(VAL(ROTATE)*M_PI/180);
// drawSphere(0.5);
glPushMatrix();
glRotated(VAL(SEAT_ROTATE), 0, 0, 1);
glTranslated(-0.5, -0.5, -0.2);
drawBox(1, 1, 0.2);
drawBox(0.2, 1, 1);
drawBox(1, 0.1, 0.4);
glTranslated(0, 1, 0);
drawBox(1, 0.1, 0.4);
glPopMatrix();
glTranslated(3.5, -3.5, sin(VAL(ROTATE)*M_PI/180) - sin((VAL(ROTATE)+90)*M_PI/180));
drawTextureCylinder(3+sin((VAL(ROTATE)+90)*M_PI/180), 0.1, 0.2);
// drawSphere(0.5);
glPushMatrix();
glRotated(VAL(SEAT_ROTATE), 0, 0, 1);
glTranslated(-0.5, -0.5, -0.2);
drawBox(1, 1, 0.2);
drawBox(0.1, 1, 0.4);
glTranslated(0, 1, 0);
drawBox(0.9, 0.1, 1);
glTranslated(1, 0, 0);
drawBox(0.1, -1, 0.4);
glPopMatrix();
glTranslated(-7, 0, sin((VAL(ROTATE)+90)*M_PI/180) - sin((VAL(ROTATE)-90)*M_PI/180));
drawTextureCylinder(3+sin((VAL(ROTATE)-90)*M_PI/180), 0.1, 0.2);
// drawSphere(0.5);
glPushMatrix();
glRotated(VAL(SEAT_ROTATE), 0, 0, 1);
glTranslated(-0.5, -0.5, -0.2);
drawBox(1, 1, 0.2);
drawBox(1, 0.2, 1);
drawBox(0.1, 1, 0.4);
glTranslated(1, 0, 0);
drawBox(0.1, 1, 0.4);
glPopMatrix();
glTranslated(3.5, -3.5, sin((VAL(ROTATE)-90)*M_PI/180) - sin((VAL(ROTATE)+180)*M_PI/180));
drawTextureCylinder(3+sin((VAL(ROTATE)+180)*M_PI/180), 0.1, 0.2);
// drawSphere(0.5);
glPushMatrix();
glRotated(VAL(SEAT_ROTATE), 0, 0, 1);
glTranslated(-0.5, -0.5, -0.2);
drawBox(1, 1, 0.2);
drawBox(1, 0.1, 0.4);
glTranslated(1, 1, 0);
drawBox(-1, -0.1, 0.4);
drawBox(-0.2, -1, 1);
glPopMatrix();
glTranslated(2.47487, 1.02513, sin((VAL(ROTATE)+180)*M_PI/180) - sin((VAL(ROTATE)+135)*M_PI/180));
drawTextureCylinder(3+sin((VAL(ROTATE)+135)*M_PI/180), 0.1, 0.2);
// drawSphere(0.5);
glPushMatrix();
glRotated(VAL(SEAT_ROTATE), 0, 0, 1);
glRotated(135, 0, 0, 1);
glTranslated(-0.5, -0.5, -0.2);
drawBox(1, 1, 0.2);
drawBox(1, 0.2, 1);
drawBox(0.1, 1, 0.4);
glTranslated(1, 0, 0);
drawBox(0.1, 1, 0.4);
glPopMatrix();
glTranslated(-4.94974, 0, sin((VAL(ROTATE)+135)*M_PI/180) - sin((VAL(ROTATE)-135)*M_PI/180));
drawTextureCylinder(3+sin((VAL(ROTATE)-135)*M_PI/180), 0.1, 0.2);
// drawSphere(0.5);
glPushMatrix();
glRotated(VAL(SEAT_ROTATE), 0, 0, 1);
glRotated(45, 0, 0, 1);
glTranslated(-0.5, -0.5, -0.2);
drawBox(1, 1, 0.2);
drawBox(1, 0.2, 1);
drawBox(0.1, 1, 0.4);
glTranslated(1, 0, 0);
drawBox(0.1, 1, 0.4);
glPopMatrix();
glTranslated(0, 4.94974, sin((VAL(ROTATE)-135)*M_PI/180) - sin((VAL(ROTATE)-45)*M_PI/180));
drawTextureCylinder(3+sin((VAL(ROTATE)-45)*M_PI/180), 0.1, 0.2);
// drawSphere(0.5);
glPushMatrix();
glRotated(VAL(SEAT_ROTATE), 0, 0, 1);
glRotated(-45, 0, 0, 1);
glTranslated(-0.5, -0.5, -0.2);
drawBox(1, 1, 0.2);
drawBox(1, 0.2, 1);
drawBox(0.1, 1, 0.4);
glTranslated(1, 0, 0);
drawBox(0.1, 1, 0.4);
glPopMatrix();
glTranslated(4.94974, 0, sin((VAL(ROTATE)-45)*M_PI/180) - sin((VAL(ROTATE)+45)*M_PI/180));
drawTextureCylinder(3+sin((VAL(ROTATE)+45)*M_PI/180), 0.1, 0.2);
// drawSphere(0.5);
glPushMatrix();
glRotated(VAL(SEAT_ROTATE), 0, 0, 1);
glRotated(-135, 0, 0, 1);
glTranslated(-0.5, -0.5, -0.2);
drawBox(1, 1, 0.2);
drawBox(1, 0.2, 1);
drawBox(0.1, 1, 0.4);
glTranslated(1, 0, 0);
drawBox(0.1, 1, 0.4);
glPopMatrix();
glPopMatrix();
glPopMatrix();
}
void SampleModel::addCustomLighting()
{
//Configuring the customized light
glEnable(GL_LIGHTING);
GLfloat* lightPos = new GLfloat[4];
lightPos[0] = VAL(LIGHT_X);
lightPos[1] = VAL(LIGHT_Y);
lightPos[2] = VAL(LIGHT_Z);
lightPos[3] = 1; //w value of light - not alpha! let lightsource be a point in space
glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
//reference cube to show the position of light
glPushMatrix();
glTranslated(lightPos[0], lightPos[1], lightPos[2]);
setDiffuseColor(1.0, 1.0, 0.0);
drawBox(0.5, 0.5, 0.5);
glPopMatrix();
}
//int main()
//{
// // Initialize the controls
// // Constructor is ModelerControl(name, minimumvalue, maximumvalue,
// // stepsize, defaultvalue)
// ModelerControl controls[NUMCONTROLS];
// controls[XPOS] = ModelerControl("X Position", -5, 5, 0.1f, 0);
// controls[YPOS] = ModelerControl("Y Position", 0, 5, 0.1f, 0);
// controls[ZPOS] = ModelerControl("Z Position", -5, 5, 0.1f, 0);
// controls[HEIGHT] = ModelerControl("Height", 1, 2.5, 0.1f, 1);
// controls[ROTATE] = ModelerControl("Rotate", -180, 180, 1, 0);
// controls[SEAT_ROTATE] = ModelerControl("Seat Rotate", -180, 180, 1, 0);
// controls[LIGHT_X] = ModelerControl("Light PosX", 0, 10, 0.1f, 5);
// controls[LIGHT_Y] = ModelerControl("Light PosY", 0, 10, 0.1f, 5);
// controls[LIGHT_Z] = ModelerControl("Light PosZ", 0, 10, 0.1f, 5);
//
// ModelerApplication::Instance()->Init(&createSampleModel, controls, NUMCONTROLS);
// return ModelerApplication::Instance()->Run();
//}