mirror of
https://github.com/overte-org/overte.git
synced 2025-07-10 20:58:36 +02:00
Merge pull request #221 from PhilipRosedale/master
Added utility function for angleBetween() to help with audio attenuation and other code
This commit is contained in:
commit
0de9afeef1
5 changed files with 88 additions and 63 deletions
|
@ -453,6 +453,14 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) {
|
||||||
if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) {
|
if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) {
|
||||||
Avatar *otherAvatar = (Avatar *)agent->getLinkedData();
|
Avatar *otherAvatar = (Avatar *)agent->getLinkedData();
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Test: Show angle between your fwd vector and nearest avatar
|
||||||
|
glm::vec3 vectorBetweenUs = otherAvatar->getJointPosition(AVATAR_JOINT_PELVIS) -
|
||||||
|
getJointPosition(AVATAR_JOINT_PELVIS);
|
||||||
|
glm::vec3 myForwardVector = _orientation.getFront();
|
||||||
|
printLog("Angle between: %f\n", angleBetween(&vectorBetweenUs, &myForwardVector));
|
||||||
|
*/
|
||||||
|
|
||||||
// test whether shoulders are close enough to allow for reaching to touch hands
|
// test whether shoulders are close enough to allow for reaching to touch hands
|
||||||
glm::vec3 v(_position - otherAvatar->_position);
|
glm::vec3 v(_position - otherAvatar->_position);
|
||||||
float distance = glm::length(v);
|
float distance = glm::length(v);
|
||||||
|
|
|
@ -65,81 +65,85 @@ float angle_to(glm::vec3 head_pos, glm::vec3 source_pos, float render_yaw, float
|
||||||
return atan2(head_pos.x - source_pos.x, head_pos.z - source_pos.z) * 180.0f / PIf + render_yaw + head_yaw;
|
return atan2(head_pos.x - source_pos.x, head_pos.z - source_pos.z) * 180.0f / PIf + render_yaw + head_yaw;
|
||||||
}
|
}
|
||||||
|
|
||||||
void render_vector(glm::vec3 * vec)
|
// Helper function returns the positive angle in degrees between two 3D vectors
|
||||||
{
|
float angleBetween(glm::vec3 * v1, glm::vec3 * v2) {
|
||||||
// Show edge of world
|
return acos((glm::dot(*v1, *v2)) / (glm::length(*v1) * glm::length(*v2))) * 180.f / PI;
|
||||||
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 particleAttenuationQuadratic[] = { 0.0f, 0.0f, 2.0f }; // larger Z = smaller particles
|
|
||||||
float particleAttenuationConstant[] = { 1.0f, 0.0f, 0.0f };
|
|
||||||
|
|
||||||
glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, particleAttenuationQuadratic );
|
|
||||||
|
|
||||||
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();
|
|
||||||
|
|
||||||
glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, particleAttenuationConstant );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void render_world_box()
|
// Draw a 3D vector floating in space
|
||||||
{
|
void drawVector(glm::vec3 * vector) {
|
||||||
|
glDisable(GL_LIGHTING);
|
||||||
|
glEnable(GL_POINT_SMOOTH);
|
||||||
|
glPointSize(3.0);
|
||||||
|
glLineWidth(2.0);
|
||||||
|
|
||||||
|
// Draw axes
|
||||||
|
glBegin(GL_LINES);
|
||||||
|
glColor3f(1,0,0);
|
||||||
|
glVertex3f(0,0,0);
|
||||||
|
glVertex3f(1,0,0);
|
||||||
|
glColor3f(0,1,0);
|
||||||
|
glVertex3f(0,0,0);
|
||||||
|
glVertex3f(0, 1, 0);
|
||||||
|
glColor3f(0,0,1);
|
||||||
|
glVertex3f(0,0,0);
|
||||||
|
glVertex3f(0, 0, 1);
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
// Draw the vector itself
|
||||||
|
glBegin(GL_LINES);
|
||||||
|
glColor3f(1,1,1);
|
||||||
|
glVertex3f(0,0,0);
|
||||||
|
glVertex3f(vector->x, vector->y, vector->z);
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
// Draw spheres for magnitude
|
||||||
|
glPushMatrix();
|
||||||
|
glColor3f(1,0,0);
|
||||||
|
glTranslatef(vector->x, 0, 0);
|
||||||
|
glutSolidSphere(0.02, 10, 10);
|
||||||
|
glColor3f(0,1,0);
|
||||||
|
glTranslatef(-vector->x, vector->y, 0);
|
||||||
|
glutSolidSphere(0.02, 10, 10);
|
||||||
|
glColor3f(0,0,1);
|
||||||
|
glTranslatef(0, -vector->y, vector->z);
|
||||||
|
glutSolidSphere(0.02, 10, 10);
|
||||||
|
glPopMatrix();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void render_world_box() {
|
||||||
// Show edge of world
|
// Show edge of world
|
||||||
glDisable(GL_LIGHTING);
|
glDisable(GL_LIGHTING);
|
||||||
glColor4f(1.0, 1.0, 1.0, 1.0);
|
glColor4f(1.0, 1.0, 1.0, 1.0);
|
||||||
glLineWidth(1.0);
|
glLineWidth(1.0);
|
||||||
glBegin(GL_LINES);
|
glBegin(GL_LINES);
|
||||||
glColor3f(1,0,0);
|
glColor3f(1, 0, 0);
|
||||||
glVertex3f(0,0,0);
|
glVertex3f(0, 0, 0);
|
||||||
glVertex3f(WORLD_SIZE,0,0);
|
glVertex3f(WORLD_SIZE, 0, 0);
|
||||||
glColor3f(0,1,0);
|
glColor3f(0, 1, 0);
|
||||||
glVertex3f(0,0,0);
|
glVertex3f(0, 0, 0);
|
||||||
glVertex3f(0, WORLD_SIZE, 0);
|
glVertex3f(0, WORLD_SIZE, 0);
|
||||||
glColor3f(0,0,1);
|
glColor3f(0, 0, 1);
|
||||||
glVertex3f(0,0,0);
|
glVertex3f(0, 0, 0);
|
||||||
glVertex3f(0, 0, WORLD_SIZE);
|
glVertex3f(0, 0, WORLD_SIZE);
|
||||||
glEnd();
|
glEnd();
|
||||||
// Draw little marker dots along the axis
|
// Draw little marker dots along the axis
|
||||||
glEnable(GL_LIGHTING);
|
glEnable(GL_LIGHTING);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glTranslatef(WORLD_SIZE,0,0);
|
glTranslatef(WORLD_SIZE, 0, 0);
|
||||||
glColor3f(1,0,0);
|
glColor3f(1, 0, 0);
|
||||||
glutSolidSphere(0.125,10,10);
|
glutSolidSphere(0.125, 10, 10);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glTranslatef(0,WORLD_SIZE,0);
|
glTranslatef(0, WORLD_SIZE, 0);
|
||||||
glColor3f(0,1,0);
|
glColor3f(0, 1, 0);
|
||||||
glutSolidSphere(0.125,10,10);
|
glutSolidSphere(0.125, 10, 10);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glTranslatef(0,0,WORLD_SIZE);
|
glTranslatef(0, 0, WORLD_SIZE);
|
||||||
glColor3f(0,0,1);
|
glColor3f(0, 0, 1);
|
||||||
glutSolidSphere(0.125,10,10);
|
glutSolidSphere(0.125, 10, 10);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,8 +170,7 @@ float widthChar(float scale, int mono, char ch) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawtext(int x, int y, float scale, float rotate, float thick, int mono,
|
void drawtext(int x, int y, float scale, float rotate, float thick, int mono,
|
||||||
char const* string, float r, float g, float b)
|
char const* string, float r, float g, float b) {
|
||||||
{
|
|
||||||
//
|
//
|
||||||
// Draws text on screen as stroked so it can be resized
|
// Draws text on screen as stroked so it can be resized
|
||||||
//
|
//
|
||||||
|
@ -184,7 +187,6 @@ void drawtext(int x, int y, float scale, float rotate, float thick, int mono,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, glm::vec3 vec, float r, float g, float b) {
|
void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, glm::vec3 vec, float r, float g, float b) {
|
||||||
//
|
//
|
||||||
// Draws text on screen as stroked so it can be resized
|
// Draws text on screen as stroked so it can be resized
|
||||||
|
@ -207,6 +209,7 @@ void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, gl
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void drawGroundPlaneGrid(float size) {
|
void drawGroundPlaneGrid(float size) {
|
||||||
glColor3f( 0.4f, 0.5f, 0.3f );
|
glColor3f( 0.4f, 0.5f, 0.3f );
|
||||||
glLineWidth(2.0);
|
glLineWidth(2.0);
|
||||||
|
|
|
@ -33,13 +33,17 @@ float angle_to(glm::vec3 head_pos, glm::vec3 source_pos, float render_yaw, float
|
||||||
|
|
||||||
float randFloat();
|
float randFloat();
|
||||||
void render_world_box();
|
void render_world_box();
|
||||||
void render_vector(glm::vec3 * vec);
|
|
||||||
int widthText(float scale, int mono, char const* string);
|
int widthText(float scale, int mono, char const* string);
|
||||||
float widthChar(float scale, int mono, char ch);
|
float widthChar(float scale, int mono, char ch);
|
||||||
void drawtext(int x, int y, float scale, float rotate, float thick, int mono,
|
void drawtext(int x, int y, float scale, float rotate, float thick, int mono,
|
||||||
char const* string, float r=1.0, float g=1.0, float b=1.0);
|
char const* string, float r=1.0, float g=1.0, float b=1.0);
|
||||||
void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, glm::vec3 vec,
|
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);
|
float r=1.0, float g=1.0, float b=1.0);
|
||||||
|
|
||||||
|
void drawVector(glm::vec3* vector);
|
||||||
|
|
||||||
|
float angleBetween(glm::vec3 * v1, glm::vec3 * v2);
|
||||||
|
|
||||||
double diffclock(timeval *clock1,timeval *clock2);
|
double diffclock(timeval *clock1,timeval *clock2);
|
||||||
|
|
||||||
void drawGroundPlaneGrid(float size);
|
void drawGroundPlaneGrid(float size);
|
||||||
|
|
|
@ -1067,7 +1067,17 @@ void display(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// important...
|
// important...
|
||||||
myCamera.update(1.f/FPS);
|
|
||||||
|
myCamera.update( 1.f/FPS );
|
||||||
|
|
||||||
|
// Render anything (like HUD items) that we want to be in 3D but not in worldspace
|
||||||
|
const float HUD_Z_OFFSET = -5.f;
|
||||||
|
glPushMatrix();
|
||||||
|
glm::vec3 test(0.5, 0.5, 0.5);
|
||||||
|
glTranslatef(1, 1, HUD_Z_OFFSET);
|
||||||
|
drawVector(&test);
|
||||||
|
glPopMatrix();
|
||||||
|
|
||||||
|
|
||||||
// Note: whichCamera is used to pick between the normal camera myCamera for our
|
// Note: whichCamera is used to pick between the normal camera myCamera for our
|
||||||
// main camera, vs, an alternate camera. The alternate camera we support right now
|
// main camera, vs, an alternate camera. The alternate camera we support right now
|
||||||
|
|
0
libraries/voxels/src/AABox.cpp
Executable file → Normal file
0
libraries/voxels/src/AABox.cpp
Executable file → Normal file
Loading…
Reference in a new issue