mirror of
https://github.com/JulianGro/overte.git
synced 2025-08-08 02:47:37 +02:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
1aac3eb0df
9 changed files with 330 additions and 55 deletions
|
@ -9,40 +9,34 @@
|
|||
|
||||
#include "Camera.h"
|
||||
|
||||
|
||||
|
||||
//------------------------
|
||||
Camera::Camera()
|
||||
{
|
||||
_mode = CAMERA_MODE_THIRD_PERSON;
|
||||
_tightness = DEFAULT_CAMERA_TIGHTNESS;
|
||||
_fieldOfView = 60.0; // default
|
||||
_nearClip = 0.1; // default
|
||||
_farClip = 50.0; // default
|
||||
_nearClip = 0.01; // default
|
||||
_farClip = 50.0; // default
|
||||
_yaw = 0.0;
|
||||
_pitch = 0.0;
|
||||
_roll = 0.0;
|
||||
_up = 0.0;
|
||||
_distance = 0.0;
|
||||
_idealYaw = 0.0;
|
||||
_targetPosition = glm::vec3( 0.0, 0.0, 0.0 );
|
||||
_position = glm::vec3( 0.0, 0.0, 0.0 );
|
||||
_idealPosition = glm::vec3( 0.0, 0.0, 0.0 );
|
||||
_orientation.setToIdentity();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//------------------------------------
|
||||
void Camera::update( float deltaTime )
|
||||
{
|
||||
float radian = ( _yaw / 180.0 ) * PIE;
|
||||
|
||||
//these need to be checked to make sure they correspond to the cordinate system.
|
||||
float x = _distance * -sin( radian );
|
||||
float z = _distance * cos( radian );
|
||||
float y = _up;
|
||||
|
||||
//these need to be checked to make sure they correspond to the coordinate system.
|
||||
double x = _distance * -sin( radian );
|
||||
double z = _distance * cos( radian );
|
||||
double y = _up;
|
||||
|
||||
_idealPosition = _targetPosition + glm::vec3( x, y, z );
|
||||
float t = _tightness * deltaTime;
|
||||
|
||||
|
@ -51,13 +45,12 @@ void Camera::update( float deltaTime )
|
|||
}
|
||||
|
||||
_position += ( _idealPosition - _position ) * t;
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//geterate the ortho-normals for the orientation based on the Euler angles
|
||||
//------------------------------------------------------------------------
|
||||
_yaw += ( _idealYaw - _yaw ) * t;
|
||||
|
||||
// generate the ortho-normals for the orientation based on the Euler angles
|
||||
_orientation.setToIdentity();
|
||||
_orientation.yaw ( _yaw );
|
||||
_orientation.pitch ( _pitch );
|
||||
_orientation.roll ( _roll );
|
||||
_orientation.yaw ( _yaw );
|
||||
_orientation.pitch ( _pitch );
|
||||
_orientation.roll ( _roll );
|
||||
}
|
||||
|
||||
|
|
|
@ -28,9 +28,9 @@ public:
|
|||
Camera();
|
||||
|
||||
void update( float deltaTime );
|
||||
|
||||
|
||||
void setMode ( CameraMode m ) { _mode = m; }
|
||||
void setYaw ( float y ) { _yaw = y; }
|
||||
void setYaw ( float y ) { _idealYaw = y; }
|
||||
void setPitch ( float p ) { _pitch = p; }
|
||||
void setRoll ( float r ) { _roll = r; }
|
||||
void setUp ( float u ) { _up = u; }
|
||||
|
@ -57,23 +57,22 @@ public:
|
|||
|
||||
private:
|
||||
|
||||
CameraMode _mode;
|
||||
glm::vec3 _position;
|
||||
CameraMode _mode;
|
||||
glm::vec3 _position;
|
||||
glm::vec3 _idealPosition;
|
||||
glm::vec3 _targetPosition;
|
||||
float _yaw;
|
||||
float _pitch;
|
||||
float _roll;
|
||||
float _up;
|
||||
float _distance;
|
||||
glm::vec3 _targetPosition;
|
||||
float _fieldOfView;
|
||||
float _aspectRatio;
|
||||
float _nearClip;
|
||||
float _farClip;
|
||||
float _yaw;
|
||||
float _pitch;
|
||||
float _roll;
|
||||
float _up;
|
||||
float _idealYaw;
|
||||
float _distance;
|
||||
float _tightness;
|
||||
Orientation _orientation;
|
||||
|
||||
// Lens attributes
|
||||
float _fieldOfView; // in degrees
|
||||
float _aspectRatio; // width/height
|
||||
float _nearClip; // in world units? - XXXBHG - we need to think about this!
|
||||
float _farClip; // in world units?
|
||||
Orientation _orientation;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -708,12 +708,12 @@ void display(void)
|
|||
//-----------------------------------------------
|
||||
// set the camera to looking at my own face
|
||||
//-----------------------------------------------
|
||||
myCamera.setTargetPosition ( myAvatar.getBodyPosition() );
|
||||
myCamera.setTargetPosition ( myAvatar.getBodyPosition() ); // XXXBHG - Shouldn't we use Head position here?
|
||||
myCamera.setYaw ( - myAvatar.getBodyYaw() );
|
||||
myCamera.setPitch ( 0.0 );
|
||||
myCamera.setRoll ( 0.0 );
|
||||
myCamera.setUp ( 0.53 );
|
||||
myCamera.setDistance ( 0.03 );
|
||||
myCamera.setUp ( 0.6 );
|
||||
myCamera.setDistance ( 0.3 );
|
||||
myCamera.setTightness ( 100.0f );
|
||||
myCamera.update ( 1.f/FPS );
|
||||
} else {
|
||||
|
@ -724,8 +724,8 @@ void display(void)
|
|||
myCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() );
|
||||
myCamera.setPitch ( 0.0 ); // temporarily, this must be 0.0 or else bad juju
|
||||
myCamera.setRoll ( 0.0 );
|
||||
myCamera.setUp ( 0.45 );
|
||||
myCamera.setDistance ( 0.5 );
|
||||
myCamera.setUp ( 0.45);
|
||||
myCamera.setDistance ( 1.0 );
|
||||
myCamera.setTightness ( 10.0f );
|
||||
myCamera.update ( 1.f/FPS );
|
||||
}
|
||||
|
@ -759,9 +759,11 @@ void display(void)
|
|||
// could be myCamera (if in normal mode)
|
||||
// or could be viewFrustumOffsetCamera if in offset mode
|
||||
//---------------------------------------------
|
||||
|
||||
// I changed the ordering here - roll is FIRST (JJV)
|
||||
glRotatef ( whichCamera.getRoll(), 0, 0, 1 );
|
||||
glRotatef ( whichCamera.getPitch(), 1, 0, 0 );
|
||||
glRotatef ( whichCamera.getYaw(), 0, 1, 0 );
|
||||
glRotatef ( whichCamera.getRoll(), 0, 0, 1 );
|
||||
glTranslatef( -whichCamera.getPosition().x, -whichCamera.getPosition().y, -whichCamera.getPosition().z );
|
||||
|
||||
|
||||
|
|
76
libraries/voxels/src/AABox.cpp
Executable file
76
libraries/voxels/src/AABox.cpp
Executable file
|
@ -0,0 +1,76 @@
|
|||
/* ------------------------------------------------------
|
||||
|
||||
Axis Aligned Boxes - Lighthouse3D
|
||||
|
||||
-----------------------------------------------------*/
|
||||
|
||||
#include "AABox.h"
|
||||
|
||||
|
||||
AABox::AABox(const glm::vec3& corner, float x, float y, float z) {
|
||||
setBox(corner,x,y,z);
|
||||
}
|
||||
|
||||
AABox::AABox(void) {
|
||||
corner.x = 0; corner.y = 0; corner.z = 0;
|
||||
x = 1.0f;
|
||||
y = 1.0f;
|
||||
z = 1.0f;
|
||||
}
|
||||
|
||||
|
||||
AABox::~AABox() {}
|
||||
|
||||
|
||||
|
||||
void AABox::setBox(const glm::vec3& corner, float x, float y, float z) {
|
||||
this->corner = corner;
|
||||
if (x < 0.0) {
|
||||
x = -x;
|
||||
this->corner.x -= x;
|
||||
}
|
||||
if (y < 0.0) {
|
||||
y = -y;
|
||||
this->corner.y -= y;
|
||||
}
|
||||
if (z < 0.0) {
|
||||
z = -z;
|
||||
this->corner.z -= z;
|
||||
}
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->z = z;
|
||||
}
|
||||
|
||||
|
||||
|
||||
glm::vec3 AABox::getVertexP(const glm::vec3 &normal) {
|
||||
glm::vec3 res = corner;
|
||||
if (normal.x > 0)
|
||||
res.x += x;
|
||||
|
||||
if (normal.y > 0)
|
||||
res.y += y;
|
||||
|
||||
if (normal.z > 0)
|
||||
res.z += z;
|
||||
|
||||
return(res);
|
||||
}
|
||||
|
||||
|
||||
|
||||
glm::vec3 AABox::getVertexN(const glm::vec3 &normal) {
|
||||
glm::vec3 res = corner;
|
||||
|
||||
if (normal.x < 0)
|
||||
res.x += x;
|
||||
|
||||
if (normal.y < 0)
|
||||
res.y += y;
|
||||
|
||||
if (normal.z < 0)
|
||||
res.z += z;
|
||||
|
||||
return(res);
|
||||
}
|
33
libraries/voxels/src/AABox.h
Executable file
33
libraries/voxels/src/AABox.h
Executable file
|
@ -0,0 +1,33 @@
|
|||
/* ------------------------------------------------------
|
||||
|
||||
Axis Aligned Boxes - Lighthouse3D
|
||||
|
||||
-----------------------------------------------------*/
|
||||
|
||||
|
||||
#ifndef _AABOX_
|
||||
#define _AABOX_
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
class AABox
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
glm::vec3 corner;
|
||||
float x,y,z;
|
||||
|
||||
AABox(const glm::vec3 &corner, float x, float y, float z);
|
||||
AABox(void);
|
||||
~AABox();
|
||||
|
||||
void setBox(const glm::vec3& corner, float x, float y, float z);
|
||||
|
||||
// for use in frustum computations
|
||||
glm::vec3 getVertexP(const glm::vec3& normal);
|
||||
glm::vec3 getVertexN(const glm::vec3& normal);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
83
libraries/voxels/src/Plane.cpp
Executable file
83
libraries/voxels/src/Plane.cpp
Executable file
|
@ -0,0 +1,83 @@
|
|||
// Plane.cpp
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Plane.h"
|
||||
#include <stdio.h>
|
||||
|
||||
// These are some useful utilities that vec3 is missing
|
||||
float vec3_length(const glm::vec3& v) {
|
||||
return((float)sqrt(v.x*v.x + v.y*v.y + v.z*v.z));
|
||||
}
|
||||
|
||||
void vec3_normalize(glm::vec3& v) {
|
||||
|
||||
float len;
|
||||
|
||||
len = vec3_length(v);
|
||||
if (len) {
|
||||
v.x /= len;;
|
||||
v.y /= len;
|
||||
v.z /= len;
|
||||
}
|
||||
}
|
||||
|
||||
float vec3_innerProduct(const glm::vec3& v1,const glm::vec3& v2) {
|
||||
|
||||
return (v1.x * v2.x + v1.y * v2.y + v1.z * v2.z);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Plane::Plane(const glm::vec3 &v1, const glm::vec3 &v2, const glm::vec3 &v3) {
|
||||
|
||||
set3Points(v1,v2,v3);
|
||||
}
|
||||
|
||||
|
||||
Plane::Plane() {}
|
||||
|
||||
Plane::~Plane() {}
|
||||
|
||||
|
||||
void Plane::set3Points(const glm::vec3 &v1, const glm::vec3 &v2, const glm::vec3 &v3) {
|
||||
|
||||
|
||||
glm::vec3 aux1, aux2;
|
||||
|
||||
aux1 = v1 - v2;
|
||||
aux2 = v3 - v2;
|
||||
|
||||
normal = aux2 * aux1;
|
||||
|
||||
vec3_normalize(normal);
|
||||
point = v2;
|
||||
d = -(vec3_innerProduct(normal,point));
|
||||
}
|
||||
|
||||
void Plane::setNormalAndPoint(const glm::vec3 &normal, const glm::vec3 &point) {
|
||||
|
||||
this->normal = normal;
|
||||
vec3_normalize(this->normal);
|
||||
d = -(vec3_innerProduct(this->normal,point));
|
||||
}
|
||||
|
||||
void Plane::setCoefficients(float a, float b, float c, float d) {
|
||||
|
||||
// set the normal vector
|
||||
normal = glm::vec3(a,b,c);
|
||||
//compute the lenght of the vector
|
||||
float l = normal.length();
|
||||
// normalize the vector
|
||||
normal = glm::vec3(a/l,b/l,c/l);
|
||||
// and divide d by th length as well
|
||||
this->d = d/l;
|
||||
}
|
||||
|
||||
float Plane::distance(const glm::vec3 &p) {
|
||||
return (d + vec3_innerProduct(normal,p));
|
||||
}
|
||||
|
||||
void Plane::print() {
|
||||
//printf("Plane(");normal.print();printf("# %f)",d);
|
||||
}
|
35
libraries/voxels/src/Plane.h
Executable file
35
libraries/voxels/src/Plane.h
Executable file
|
@ -0,0 +1,35 @@
|
|||
//////////////////////////////////////////////////////////////////////
|
||||
// Plane.h - inspired and modified from lighthouse3d.com
|
||||
//
|
||||
|
||||
|
||||
#ifndef _PLANE_
|
||||
#define _PLANE_
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
|
||||
class Plane
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
glm::vec3 normal,point;
|
||||
float d;
|
||||
|
||||
|
||||
Plane(const glm::vec3 &v1, const glm::vec3 &v2, const glm::vec3 &v3);
|
||||
Plane(void);
|
||||
~Plane();
|
||||
|
||||
void set3Points(const glm::vec3 &v1, const glm::vec3 &v2, const glm::vec3 &v3);
|
||||
void setNormalAndPoint(const glm::vec3 &normal, const glm::vec3 &point);
|
||||
void setCoefficients(float a, float b, float c, float d);
|
||||
float distance(const glm::vec3 &p);
|
||||
|
||||
void print();
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
|
@ -54,34 +54,43 @@ void ViewFrustum::calculate() {
|
|||
|
||||
float twoTimesTanHalfFOV = 2.0f * tan(fovInRadians/2.0f);
|
||||
|
||||
float slightlySmaller = 0.0f;
|
||||
float slightlyInsideWidth= 0.0f - slightlySmaller;
|
||||
float slightlyInsideNear = 0.0f + slightlySmaller;
|
||||
float slightlyInsideFar = 0.0f - slightlySmaller;
|
||||
|
||||
float nearClip = this->_nearClip + slightlyInsideNear;
|
||||
float farClip = this->_farClip + slightlyInsideFar;
|
||||
// Do we need this?
|
||||
//tang = (float)tan(ANG2RAD * angle * 0.5) ;
|
||||
|
||||
float nearClip = this->_nearClip;
|
||||
float farClip = this->_farClip;
|
||||
|
||||
this->_nearHeight = (twoTimesTanHalfFOV * nearClip);
|
||||
this->_nearWidth = this->_nearHeight * this->_aspectRatio;
|
||||
this->_farHeight = (twoTimesTanHalfFOV * farClip);
|
||||
this->_farWidth = this->_farHeight * this->_aspectRatio;
|
||||
|
||||
float farHalfHeight = (this->_farHeight * 0.5f) + slightlyInsideWidth;
|
||||
float farHalfWidth = (this->_farWidth * 0.5f) + slightlyInsideWidth;
|
||||
float farHalfHeight = (this->_farHeight * 0.5f);
|
||||
float farHalfWidth = (this->_farWidth * 0.5f);
|
||||
this->_farCenter = this->_position+front * farClip;
|
||||
this->_farTopLeft = this->_farCenter + (this->_up * farHalfHeight) - (this->_right * farHalfWidth);
|
||||
this->_farTopRight = this->_farCenter + (this->_up * farHalfHeight) + (this->_right * farHalfWidth);
|
||||
this->_farBottomLeft = this->_farCenter - (this->_up * farHalfHeight) - (this->_right * farHalfWidth);
|
||||
this->_farBottomRight = this->_farCenter - (this->_up * farHalfHeight) + (this->_right * farHalfWidth);
|
||||
|
||||
float nearHalfHeight = (this->_nearHeight * 0.5f) + slightlyInsideWidth;
|
||||
float nearHalfWidth = (this->_nearWidth * 0.5f) + slightlyInsideWidth;
|
||||
float nearHalfHeight = (this->_nearHeight * 0.5f);
|
||||
float nearHalfWidth = (this->_nearWidth * 0.5f);
|
||||
this->_nearCenter = this->_position+front * nearClip;
|
||||
this->_nearTopLeft = this->_nearCenter + (this->_up * nearHalfHeight) - (this->_right * nearHalfWidth);
|
||||
this->_nearTopRight = this->_nearCenter + (this->_up * nearHalfHeight) + (this->_right * nearHalfWidth);
|
||||
this->_nearBottomLeft = this->_nearCenter - (this->_up * nearHalfHeight) - (this->_right * nearHalfWidth);
|
||||
this->_nearBottomRight = this->_nearCenter - (this->_up * nearHalfHeight) + (this->_right * nearHalfWidth);
|
||||
|
||||
// compute the six planes
|
||||
// the function set3Points assumes that the points
|
||||
// are given in counter clockwise order
|
||||
this->_planes[TOPP].set3Points(this->_nearTopRight,this->_nearTopLeft,this->_farTopLeft);
|
||||
this->_planes[BOTTOMP].set3Points(this->_nearBottomLeft,this->_nearBottomRight,this->_farBottomRight);
|
||||
this->_planes[LEFTP].set3Points(this->_nearTopLeft,this->_nearBottomLeft,this->_farBottomLeft);
|
||||
this->_planes[RIGHTP].set3Points(this->_nearBottomRight,this->_nearTopRight,this->_farBottomRight);
|
||||
this->_planes[NEARP].set3Points(this->_nearTopLeft,this->_nearTopRight,this->_nearBottomRight);
|
||||
this->_planes[FARP].set3Points(this->_farTopRight,this->_farTopLeft,this->_farBottomLeft);
|
||||
|
||||
}
|
||||
|
||||
void ViewFrustum::dump() {
|
||||
|
@ -123,3 +132,37 @@ void ViewFrustum::dump() {
|
|||
}
|
||||
|
||||
|
||||
int ViewFrustum::pointInFrustum(glm::vec3 &p) {
|
||||
int result = INSIDE;
|
||||
for(int i=0; i < 6; i++) {
|
||||
if (this->_planes[i].distance(p) < 0)
|
||||
return OUTSIDE;
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
int ViewFrustum::sphereInFrustum(glm::vec3 ¢er, float radius) {
|
||||
int result = INSIDE;
|
||||
float distance;
|
||||
for(int i=0; i < 6; i++) {
|
||||
distance = this->_planes[i].distance(center);
|
||||
if (distance < -radius)
|
||||
return OUTSIDE;
|
||||
else if (distance < radius)
|
||||
result = INTERSECT;
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
int ViewFrustum::boxInFrustum(AABox &b) {
|
||||
int result = INSIDE;
|
||||
for(int i=0; i < 6; i++) {
|
||||
if (this->_planes[i].distance(b.getVertexP(this->_planes[i].normal)) < 0)
|
||||
return OUTSIDE;
|
||||
else if (this->_planes[i].distance(b.getVertexN(this->_planes[i].normal)) < 0)
|
||||
result = INTERSECT;
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
#define __hifi__ViewFrustum__
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include "Plane.h"
|
||||
#include "AABox.h"
|
||||
|
||||
class ViewFrustum {
|
||||
private:
|
||||
|
@ -43,6 +45,8 @@ private:
|
|||
glm::vec3 _nearTopRight;
|
||||
glm::vec3 _nearBottomLeft;
|
||||
glm::vec3 _nearBottomRight;
|
||||
enum { TOPP = 0, BOTTOMP, LEFTP, RIGHTP, NEARP, FARP };
|
||||
Plane _planes[6]; // How will this be used?
|
||||
|
||||
public:
|
||||
// setters for camera attributes
|
||||
|
@ -79,6 +83,13 @@ public:
|
|||
ViewFrustum();
|
||||
|
||||
void dump();
|
||||
|
||||
enum {OUTSIDE, INTERSECT, INSIDE};
|
||||
|
||||
int pointInFrustum(glm::vec3 &p);
|
||||
int sphereInFrustum(glm::vec3 ¢er, float radius);
|
||||
int boxInFrustum(AABox &b);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue