mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 21:17:01 +02:00
Added utility function for angle_to object
This commit is contained in:
parent
ab50a4dd7c
commit
3ecc09b7b2
5 changed files with 35 additions and 11 deletions
Binary file not shown.
|
@ -11,7 +11,7 @@
|
||||||
Lattice::Lattice(int w, int h) {
|
Lattice::Lattice(int w, int h) {
|
||||||
width = w;
|
width = w;
|
||||||
height = h;
|
height = h;
|
||||||
tilegap = 3;
|
tilegap = 2;
|
||||||
lastindex = -1;
|
lastindex = -1;
|
||||||
tiles = new Tile[width*height];
|
tiles = new Tile[width*height];
|
||||||
for (int i = 0; i < (width*height); i++) {
|
for (int i = 0; i < (width*height); i++) {
|
||||||
|
|
30
main.cpp
30
main.cpp
|
@ -110,7 +110,7 @@ Cloud cloud(0, // Particles
|
||||||
|
|
||||||
VoxelSystem voxels(0, box);
|
VoxelSystem voxels(0, box);
|
||||||
|
|
||||||
Lattice lattice(15,10);
|
Lattice lattice(160,100);
|
||||||
Finger myFinger(WIDTH, HEIGHT);
|
Finger myFinger(WIDTH, HEIGHT);
|
||||||
|
|
||||||
#define RENDER_FRAME_MSECS 8
|
#define RENDER_FRAME_MSECS 8
|
||||||
|
@ -119,7 +119,7 @@ int steps_per_frame = 0;
|
||||||
|
|
||||||
float yaw =0.f; // The yaw, pitch for the avatar head
|
float yaw =0.f; // The yaw, pitch for the avatar head
|
||||||
float pitch = 0.f; //
|
float pitch = 0.f; //
|
||||||
float start_yaw = 135.0;
|
float start_yaw = 116;
|
||||||
float render_yaw = start_yaw;
|
float render_yaw = start_yaw;
|
||||||
float render_pitch = 0.f;
|
float render_pitch = 0.f;
|
||||||
float render_yaw_rate = 0.f;
|
float render_yaw_rate = 0.f;
|
||||||
|
@ -129,7 +129,10 @@ float lateral_vel = 0.f;
|
||||||
// Manage speed and direction of motion
|
// Manage speed and direction of motion
|
||||||
GLfloat fwd_vec[] = {0.0, 0.0, 1.0};
|
GLfloat fwd_vec[] = {0.0, 0.0, 1.0};
|
||||||
//GLfloat start_location[] = { WORLD_SIZE*1.5, -WORLD_SIZE/2.0, -WORLD_SIZE/3.0};
|
//GLfloat start_location[] = { WORLD_SIZE*1.5, -WORLD_SIZE/2.0, -WORLD_SIZE/3.0};
|
||||||
GLfloat start_location[] = { 0.1, -0.15, 0.1};
|
//GLfloat start_location[] = { 0.1, -0.15, 0.1};
|
||||||
|
|
||||||
|
GLfloat start_location[] = {6.1, -2.0, 1.4};
|
||||||
|
|
||||||
GLfloat location[] = {start_location[0], start_location[1], start_location[2]};
|
GLfloat location[] = {start_location[0], start_location[1], start_location[2]};
|
||||||
float fwd_vel = 0.0f;
|
float fwd_vel = 0.0f;
|
||||||
|
|
||||||
|
@ -253,10 +256,12 @@ void display_stats(void)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
char adc[200];
|
char adc[200];
|
||||||
sprintf(adc, "location = %3.1f,%3.1f,%3.1f",
|
sprintf(adc, "location = %3.1f,%3.1f,%3.1f, angle_to 0,0,0 = %3.1f, head yaw = %3.1f, render_yaw = %3.1f, together = %3.1f",
|
||||||
location[0], location[1], location[2]
|
-location[0], -location[1], -location[2],
|
||||||
|
azimuth_to(myHead.getPos()*-1.f, glm::vec3(0,0,0)),
|
||||||
|
myHead.getYaw(), render_yaw,
|
||||||
|
angle_to(myHead.getPos()*-1.f, glm::vec3(0,0,0), render_yaw, myHead.getYaw())
|
||||||
);
|
);
|
||||||
drawtext(10, 50, 0.10, 0, 1.0, 0, adc);
|
drawtext(10, 50, 0.10, 0, 1.0, 0, adc);
|
||||||
|
|
||||||
|
@ -560,7 +565,7 @@ void display(void)
|
||||||
glMaterialfv(GL_FRONT, GL_SPECULAR, specular_color);
|
glMaterialfv(GL_FRONT, GL_SPECULAR, specular_color);
|
||||||
glMateriali(GL_FRONT, GL_SHININESS, 96);
|
glMateriali(GL_FRONT, GL_SHININESS, 96);
|
||||||
|
|
||||||
// Rotate, translate to camera location
|
// Rotate, translate to camera location
|
||||||
glRotatef(render_pitch, 1, 0, 0);
|
glRotatef(render_pitch, 1, 0, 0);
|
||||||
glRotatef(render_yaw, 0, 1, 0);
|
glRotatef(render_yaw, 0, 1, 0);
|
||||||
glTranslatef(location[0], location[1], location[2]);
|
glTranslatef(location[0], location[1], location[2]);
|
||||||
|
@ -592,11 +597,16 @@ void display(void)
|
||||||
|
|
||||||
|
|
||||||
if (!display_head) balls.render();
|
if (!display_head) balls.render();
|
||||||
|
|
||||||
// Render the world box
|
// Render the world box
|
||||||
if (!display_head && stats_on) render_world_box();
|
if (!display_head && stats_on) render_world_box();
|
||||||
|
|
||||||
//glm::vec3 test(0.5, 0.5, 0.5);
|
glPushMatrix();
|
||||||
|
glTranslatef(2,2,2);
|
||||||
|
glColor3f(1,0,0);
|
||||||
|
glutSolidCube(1.0);
|
||||||
|
glPopMatrix();
|
||||||
|
//glm::vec3 test(0.5, 0.5, 0.5);
|
||||||
//render_vector(&test);
|
//render_vector(&test);
|
||||||
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
@ -609,7 +619,7 @@ void display(void)
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
glDisable(GL_LIGHTING);
|
glDisable(GL_LIGHTING);
|
||||||
|
|
||||||
lattice.render(WIDTH, HEIGHT);
|
//lattice.render(WIDTH, HEIGHT);
|
||||||
//drawvec3(100, 100, 0.15, 0, 1.0, 0, myHead.getPos(), 0, 1, 0);
|
//drawvec3(100, 100, 0.15, 0, 1.0, 0, myHead.getPos(), 0, 1, 0);
|
||||||
glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, pointer_attenuation_quadratic );
|
glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, pointer_attenuation_quadratic );
|
||||||
|
|
||||||
|
|
11
util.cpp
11
util.cpp
|
@ -19,6 +19,17 @@ float randFloat () {
|
||||||
return (rand()%10000)/10000.f;
|
return (rand()%10000)/10000.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return the azimuth angle in degrees between a head position and a sound source,
|
||||||
|
// given the two positions.
|
||||||
|
float azimuth_to(glm::vec3 head_pos, glm::vec3 source_pos) {
|
||||||
|
return atan2(head_pos.x - source_pos.x, head_pos.z - source_pos.z) * 180 / PI;
|
||||||
|
}
|
||||||
|
|
||||||
|
float angle_to(glm::vec3 head_pos, glm::vec3 source_pos, float render_yaw, float head_yaw) {
|
||||||
|
return atan2(head_pos.x - source_pos.x, head_pos.z - source_pos.z) * 180 / PI + render_yaw + head_yaw;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void render_vector(glm::vec3 * vec)
|
void render_vector(glm::vec3 * vec)
|
||||||
{
|
{
|
||||||
|
|
3
util.h
3
util.h
|
@ -11,6 +11,9 @@
|
||||||
|
|
||||||
#include "glm/glm.hpp"
|
#include "glm/glm.hpp"
|
||||||
|
|
||||||
|
float azimuth_to(glm::vec3 head_pos, glm::vec3 source_pos);
|
||||||
|
float angle_to(glm::vec3 head_pos, glm::vec3 source_pos, float render_yaw, float head_yaw);
|
||||||
|
|
||||||
void outstring(char * string, int length);
|
void outstring(char * string, int length);
|
||||||
float randFloat();
|
float randFloat();
|
||||||
void render_world_box();
|
void render_world_box();
|
||||||
|
|
Loading…
Reference in a new issue