forked from yozlet/interface
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.cpp
More file actions
171 lines (157 loc) · 4.66 KB
/
Copy pathutil.cpp
File metadata and controls
171 lines (157 loc) · 4.66 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
//
// util.cpp
// interface
//
// Created by Philip Rosedale on 8/24/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <iostream>
#include "world.h"
#include "glm/glm.hpp"
float randFloat () {
return (rand()%10000)/10000.f;
}
void makeCubes(float location[3], float scale, int * index,
float * cubes_position, float * cubes_scale, float * cubes_color) {
int i;
float spot[3];
//std::cout << "loc: " << location[0] << ","
//<< location[1] << "," << location[2] << "\n";
if ((*index >= MAX_CUBES) || (scale < SMALLEST_CUBE)) return;
if (scale < 3 && (randFloat() < .1)) {
// Make a cube
for (i = 0; i < 3; i++) cubes_position[*index*3 + i] = location[i]+scale/2.0;
float color = randFloat();
cubes_scale[*index] = scale;
cubes_color[*index*3] = color;
cubes_color[*index*3 + 1] = color;
cubes_color[*index*3 + 2] = color;
*index += 1;
//std::cout << "Loc: " << location[0] << "," << location[1]
//<< "," << location[2] << " scale " << scale << "\n";
} else {
for (i = 0; i < 8; i++) {
spot[0] = location[0] + (i%2)*scale/2.0;
spot[1] = location[1] + ((i/2)%2)*scale/2.0;
spot[2] = location[2] + ((i/4)%2)*scale/2.0;
//std::cout << "called with " << spot[0] << "," << spot[1] << "," << spot[2] << "\n";
makeCubes(spot, scale/2.0, index, cubes_position, cubes_scale, cubes_color);
}
}
}
void render_vector(glm::vec3 * vec)
{
// Show edge of world
glDisable(GL_LIGHTING);
glColor4f(1.0, 1.0, 1.0, 1.0);
glLineWidth(1.0);
glBegin(GL_LINES);
// Draw axes
glColor3f(1,0,0);
glVertex3f(-1,0,0);
glVertex3f(1,0,0);
glColor3f(0,1,0);
glVertex3f(0,-1,0);
glVertex3f(0, 1, 0);
glColor3f(0,0,1);
glVertex3f(0,0,-1);
glVertex3f(0, 0, 1);
// Draw vector
glColor3f(1,1,1);
glVertex3f(0,0,0);
glVertex3f(vec->x, vec->y, vec->z);
// Draw marker dots for magnitude
glEnd();
float particle_attenuation_quadratic[] = { 0.0f, 0.0f, 2.0f }; // larger Z = smaller particles
glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, particle_attenuation_quadratic );
glEnable(GL_POINT_SMOOTH);
glPointSize(10.0);
glBegin(GL_POINTS);
glColor3f(1,0,0);
glVertex3f(vec->x,0,0);
glColor3f(0,1,0);
glVertex3f(0,vec->y,0);
glColor3f(0,0,1);
glVertex3f(0,0,vec->z);
glEnd();
}
void render_world_box()
{
// Show edge of world
glDisable(GL_LIGHTING);
glColor4f(1.0, 1.0, 1.0, 1.0);
glLineWidth(1.0);
glBegin(GL_LINES);
glColor3f(1,0,0);
glVertex3f(0,0,0);
glVertex3f(WORLD_SIZE,0,0);
glColor3f(0,1,0);
glVertex3f(0,0,0);
glVertex3f(0, WORLD_SIZE, 0);
glColor3f(0,0,1);
glVertex3f(0,0,0);
glVertex3f(0, 0, WORLD_SIZE);
glEnd();
}
void outstring(char * string, int length) {
char out[length];
memcpy(out, string, length);
std::cout << out << "\n";
}
double diffclock(timeval clock1,timeval clock2)
{
double diffms = (clock2.tv_sec - clock1.tv_sec) * 1000.0;
diffms += (clock2.tv_usec - clock1.tv_usec) / 1000.0; // us to ms
return diffms;
}
void drawtext(int x, int y, float scale, float rotate, float thick, int mono, char *string,
float r=1.0, float g=1.0, float b=1.0)
{
//
// Draws text on screen as stroked so it can be resized
//
int len, i;
glPushMatrix();
glTranslatef(x, y, 0);
glColor3f(r,g,b);
glRotated(180+rotate,0,0,1);
glRotated(180,0,1,0);
glLineWidth(thick);
glScalef(scale, scale, 1.0);
len = (int) strlen(string);
for (i = 0; i < len; i++)
{
if (!mono) glutStrokeCharacter(GLUT_STROKE_ROMAN, int(string[i]));
else glutStrokeCharacter(GLUT_STROKE_MONO_ROMAN, int(string[i]));
}
glPopMatrix();
}
void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, glm::vec3 vec,
float r=1.0, float g=1.0, float b=1.0)
{
//
// Draws text on screen as stroked so it can be resized
//
char vectext[20];
sprintf(vectext,"%3.1f,%3.1f,%3.1f", vec.x, vec.y, vec.z);
int len, i;
glPushMatrix();
glTranslatef(x, y, 0);
glColor3f(r,g,b);
glRotated(180+rotate,0,0,1);
glRotated(180,0,1,0);
glLineWidth(thick);
glScalef(scale, scale, 1.0);
len = (int) strlen(vectext);
for (i = 0; i < len; i++)
{
if (!mono) glutStrokeCharacter(GLUT_STROKE_ROMAN, int(vectext[i]));
else glutStrokeCharacter(GLUT_STROKE_MONO_ROMAN, int(vectext[i]));
}
glPopMatrix();
}