mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
Added test routine makecubes() and key handlers
This commit is contained in:
parent
2b62adce6c
commit
6172b38f49
6 changed files with 96 additions and 6 deletions
Binary file not shown.
|
@ -16,5 +16,18 @@
|
|||
landmarkName = "field_avg_neighbors(int index, glm::vec3 * result)"
|
||||
landmarkType = "7">
|
||||
</FileBreakpoint>
|
||||
<FileBreakpoint
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "util.cpp"
|
||||
timestampString = "375575185.217506"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "28"
|
||||
endingLineNumber = "28"
|
||||
landmarkName = "makeCubes(float location[3], float scale, int * index, float * cubes_position, float * cubes_scale, float * cubes_color)"
|
||||
landmarkType = "7">
|
||||
</FileBreakpoint>
|
||||
</FileBreakpoints>
|
||||
</Bucket>
|
||||
|
|
53
main.cpp
53
main.cpp
|
@ -95,11 +95,16 @@ ParticleSystem balls(0,
|
|||
0.0 // Gravity
|
||||
);
|
||||
|
||||
Cloud cloud(300000, // Particles
|
||||
Cloud cloud(0, // Particles
|
||||
box, // Bounding Box
|
||||
false // Wrap
|
||||
);
|
||||
|
||||
float cubes_position[MAX_CUBES*3];
|
||||
float cubes_scale[MAX_CUBES];
|
||||
float cubes_color[MAX_CUBES*3];
|
||||
int cube_count = 0;
|
||||
|
||||
#define RENDER_FRAME_MSECS 10
|
||||
#define SLEEP 0
|
||||
|
||||
|
@ -271,6 +276,18 @@ void init(void)
|
|||
myHead.setNoise(noise);
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
float location[] = {0,0,0};
|
||||
float scale = 10.0;
|
||||
int j = 0;
|
||||
while (index < (MAX_CUBES/2)) {
|
||||
index = 0;
|
||||
j++;
|
||||
makeCubes(location, scale, &index, cubes_position, cubes_scale, cubes_color);
|
||||
std::cout << "Run " << j << " Made " << index << " cubes\n";
|
||||
cube_count = index;
|
||||
}
|
||||
|
||||
//load_png_as_texture(texture_filename);
|
||||
|
||||
if (serial_on)
|
||||
|
@ -491,6 +508,20 @@ void display(void)
|
|||
glRotatef(render_pitch, 1, 0, 0);
|
||||
glRotatef(render_yaw, 0, 1, 0);
|
||||
glTranslatef(location[0], location[1], location[2]);
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(WORLD_SIZE/2, WORLD_SIZE/2, WORLD_SIZE/2);
|
||||
int i = 0;
|
||||
while (i < cube_count) {
|
||||
glPushMatrix();
|
||||
glTranslatef(cubes_position[i*3], cubes_position[i*3+1], cubes_position[i*3+2]);
|
||||
glColor3fv(&cubes_color[i*3]);
|
||||
glutSolidCube(cubes_scale[i]);
|
||||
glPopMatrix();
|
||||
i++;
|
||||
}
|
||||
glPopMatrix();
|
||||
|
||||
|
||||
/* Draw Point Sprites */
|
||||
|
||||
|
@ -587,7 +618,20 @@ void display(void)
|
|||
glutSwapBuffers();
|
||||
framecount++;
|
||||
}
|
||||
|
||||
void specialkey(int k, int x, int y)
|
||||
{
|
||||
if (k == GLUT_KEY_UP) fwd_vel += 0.05;
|
||||
if (k == GLUT_KEY_DOWN) fwd_vel -= 0.05;
|
||||
if (k == GLUT_KEY_LEFT) {
|
||||
if (glutGetModifiers() == GLUT_ACTIVE_SHIFT) lateral_vel -= 0.02;
|
||||
else render_yaw_rate -= 0.25;
|
||||
}
|
||||
if (k == GLUT_KEY_RIGHT) {
|
||||
if (glutGetModifiers() == GLUT_ACTIVE_SHIFT) lateral_vel += 0.02;
|
||||
else render_yaw_rate += 0.25;
|
||||
}
|
||||
|
||||
}
|
||||
void key(unsigned char k, int x, int y)
|
||||
{
|
||||
// Process keypresses
|
||||
|
@ -728,8 +772,8 @@ void reshape(int width, int height)
|
|||
glLoadIdentity();
|
||||
gluPerspective(45, //view angle
|
||||
1.0, //aspect ratio
|
||||
1.0, //near clip
|
||||
200.0);//far clip
|
||||
0.1, //near clip
|
||||
50.0);//far clip
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
|
@ -810,6 +854,7 @@ int main(int argc, char** argv)
|
|||
glutDisplayFunc(display);
|
||||
glutReshapeFunc(reshape);
|
||||
glutKeyboardFunc(key);
|
||||
glutSpecialFunc(specialkey);
|
||||
glutMotionFunc(motionFunc);
|
||||
glutMouseFunc(mouseFunc);
|
||||
glutIdleFunc(idle);
|
||||
|
|
28
util.cpp
28
util.cpp
|
@ -15,11 +15,37 @@
|
|||
#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 (randFloat() < 0.5) {
|
||||
// Make a cube
|
||||
for (i = 0; i < 3; i++) cubes_position[*index*3 + i] = location[i];
|
||||
cubes_scale[*index] = scale;
|
||||
cubes_color[*index*3] = randFloat();
|
||||
cubes_color[*index*3 + 1] = randFloat();
|
||||
cubes_color[*index*3 + 2] = randFloat();
|
||||
*index += 1;
|
||||
//std::cout << "Quad made at 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 << 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
|
||||
|
|
4
util.h
4
util.h
|
@ -8,6 +8,7 @@
|
|||
|
||||
#ifndef interface_util_h
|
||||
#define interface_util_h
|
||||
|
||||
#include "glm/glm.hpp"
|
||||
|
||||
void outstring(char * string, int length);
|
||||
|
@ -20,4 +21,7 @@ void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, gl
|
|||
float r=1.0, float g=1.0, float b=1.0);
|
||||
double diffclock(timeval clock1,timeval clock2);
|
||||
|
||||
void makeCubes(float location[3], float scale, int * index,
|
||||
float * cubes_position, float * cubes_scale, float * cubes_color);
|
||||
|
||||
#endif
|
||||
|
|
4
world.h
4
world.h
|
@ -6,7 +6,7 @@
|
|||
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
// Simulation happens in positive cube with edge of size WORLD_SIZE
|
||||
// Simulation happens in positive cube with edge of size WORLD_SIZE
|
||||
|
||||
#ifndef interface_world_h
|
||||
#define interface_world_h
|
||||
|
@ -14,5 +14,7 @@
|
|||
const float WORLD_SIZE = 10.0;
|
||||
#define PI 3.14159265
|
||||
|
||||
#define MAX_CUBES 2000
|
||||
#define SMALLEST_CUBE 0.01
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue