00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "Teddy/Models/Model.h"
00026 using namespace Teddy::Maths;
00027
00028
00029 namespace Teddy {
00030 namespace Models {
00031
00032
00039 Matrix Model::getWorldToLocalMatrix() const {
00040 Matrix m = attitude;
00041 float x = (float) -position.v[0];
00042 float y = (float) -position.v[1];
00043 float z = (float) -position.v[2];
00044
00045 m.translate( x, y, z );
00046 return m;
00047 }
00048
00049
00056 Matrix Model::getLocalToWorldMatrix() const {
00057 Matrix r = attitude;
00058 Matrix t;
00059 r.transpose();
00060 t.translateMatrix( position );
00061 return t * r;
00062 }
00063
00064
00070 Matrix Model::getViewMatrix() const {
00071
00072
00073
00074
00075 Matrix m = attitude;
00076 return m;
00077 }
00078
00079
00084 Matrix Model::getModelMatrix( Model *camera ) const {
00085 Matrix m;
00086 m.modelMatrix( attitude, position-camera->position );
00087 return m;
00088 }
00089
00090
00097 Matrix Model::getScaledModelMatrix( Model *camera ) const {
00098
00099
00100
00101
00102
00103
00104 const double MAX_DISTANCE = 256.0;
00105 const double MAX_DISCERNABLE = (512.0f*512.0f);
00106 const double HALF_MAX = (MAX_DISTANCE*0.5);
00107 Matrix mat = getModelMatrix( camera );
00108 Vector vec = position - camera->position;
00109 double distance = vec.magnitude();
00110
00111 if( distance > HALF_MAX ){
00112 vec /= distance;
00113 double factor = MAX_DISTANCE;
00114
00115 if( distance < MAX_DISCERNABLE ){
00116 factor = (HALF_MAX + HALF_MAX * (1 - exp((HALF_MAX - distance) / MAX_DISCERNABLE)));
00117 }
00118 vec *= factor;
00119 mat.m[3][0] = (float)vec.v[0];
00120 mat.m[3][1] = (float)vec.v[1];
00121 mat.m[3][2] = (float)vec.v[2];
00122 factor /= distance;
00123 mat.scale( (float)factor, (float)factor, (float)factor );
00124 }
00125 return mat;
00126 }
00127
00128
00129 };
00130 };
00131