mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 14:03:55 +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) {
|
||||
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
|
||||
glm::vec3 v(_position - otherAvatar->_position);
|
||||
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;
|
||||
}
|
||||
|
||||
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 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 );
|
||||
// Helper function returns the positive angle in degrees between two 3D vectors
|
||||
float angleBetween(glm::vec3 * v1, glm::vec3 * v2) {
|
||||
return acos((glm::dot(*v1, *v2)) / (glm::length(*v1) * glm::length(*v2))) * 180.f / PI;
|
||||
}
|
||||
|
||||
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
|
||||
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);
|
||||
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);
|
||||
glColor3f(0, 0, 1);
|
||||
glVertex3f(0, 0, 0);
|
||||
glVertex3f(0, 0, WORLD_SIZE);
|
||||
glEnd();
|
||||
// Draw little marker dots along the axis
|
||||
glEnable(GL_LIGHTING);
|
||||
glPushMatrix();
|
||||
glTranslatef(WORLD_SIZE,0,0);
|
||||
glColor3f(1,0,0);
|
||||
glutSolidSphere(0.125,10,10);
|
||||
glTranslatef(WORLD_SIZE, 0, 0);
|
||||
glColor3f(1, 0, 0);
|
||||
glutSolidSphere(0.125, 10, 10);
|
||||
glPopMatrix();
|
||||
glPushMatrix();
|
||||
glTranslatef(0,WORLD_SIZE,0);
|
||||
glColor3f(0,1,0);
|
||||
glutSolidSphere(0.125,10,10);
|
||||
glTranslatef(0, WORLD_SIZE, 0);
|
||||
glColor3f(0, 1, 0);
|
||||
glutSolidSphere(0.125, 10, 10);
|
||||
glPopMatrix();
|
||||
glPushMatrix();
|
||||
glTranslatef(0,0,WORLD_SIZE);
|
||||
glColor3f(0,0,1);
|
||||
glutSolidSphere(0.125,10,10);
|
||||
glTranslatef(0, 0, WORLD_SIZE);
|
||||
glColor3f(0, 0, 1);
|
||||
glutSolidSphere(0.125, 10, 10);
|
||||
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,
|
||||
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
|
||||
//
|
||||
|
@ -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) {
|
||||
//
|
||||
// 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();
|
||||
}
|
||||
|
||||
|
||||
void drawGroundPlaneGrid(float size) {
|
||||
glColor3f( 0.4f, 0.5f, 0.3f );
|
||||
glLineWidth(2.0);
|
||||
|
|
|
@ -33,13 +33,17 @@ float angle_to(glm::vec3 head_pos, glm::vec3 source_pos, float render_yaw, float
|
|||
|
||||
float randFloat();
|
||||
void render_world_box();
|
||||
void render_vector(glm::vec3 * vec);
|
||||
int widthText(float scale, int mono, char const* string);
|
||||
float widthChar(float scale, int mono, char ch);
|
||||
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);
|
||||
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);
|
||||
|
||||
void drawVector(glm::vec3* vector);
|
||||
|
||||
float angleBetween(glm::vec3 * v1, glm::vec3 * v2);
|
||||
|
||||
double diffclock(timeval *clock1,timeval *clock2);
|
||||
|
||||
void drawGroundPlaneGrid(float size);
|
||||
|
|
|
@ -1067,7 +1067,17 @@ void display(void)
|
|||
}
|
||||
|
||||
// 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
|
||||
// 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