mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-10 03:40:25 +00:00
more cleanup
This commit is contained in:
parent
45ce2249c6
commit
2600dc2efc
90
matrix3.cpp
90
matrix3.cpp
@ -18,74 +18,74 @@
|
||||
#include <math.h>
|
||||
#include "matrix3.h"
|
||||
|
||||
void Matrix3::setAsIdentity( void ) {
|
||||
void Matrix3::setAsIdentity() {
|
||||
right_.set(1.f, 0.f, 0.f);
|
||||
up_.set(0.f, 1.f, 0.f);
|
||||
at_.set(0.f, 0.f, 0.f);
|
||||
}
|
||||
|
||||
void Matrix3::buildFromPitchYawRoll( float pitch, float yaw, float roll ) {
|
||||
void Matrix3::buildFromPitchYawRoll(float pitch, float yaw, float roll) {
|
||||
Matrix3 temp1, temp2;
|
||||
|
||||
temp1.constructAroundPitch( pitch );
|
||||
constructAroundRoll( roll );
|
||||
temp1.constructAroundPitch(pitch);
|
||||
constructAroundRoll(roll);
|
||||
|
||||
(*this) *= temp1;
|
||||
|
||||
temp2.constructAroundYaw( yaw );
|
||||
temp2.constructAroundYaw(yaw);
|
||||
|
||||
(*this) *= temp2;
|
||||
}
|
||||
|
||||
#define MYPI 3.141592654
|
||||
#define DEGTORAD(a) (a*MYPI/180.0)
|
||||
#define RADTODEG(a) (a*180.0/MYPI)
|
||||
#define MYPI 3.14159265358979323846
|
||||
#define DEGTORAD(a) (a * MYPI / 180.0)
|
||||
#define RADTODEG(a) (a * 180.0 / MYPI)
|
||||
|
||||
float RadianToDegree( float rad ) {
|
||||
float RadianToDegree(float rad) {
|
||||
return RADTODEG(rad);
|
||||
}
|
||||
|
||||
float DegreeToRadian( float degrees ) {
|
||||
float DegreeToRadian(float degrees) {
|
||||
return DEGTORAD(degrees);
|
||||
}
|
||||
|
||||
// right
|
||||
void Matrix3::constructAroundPitch( float pitch ) {
|
||||
void Matrix3::constructAroundPitch(float pitch) {
|
||||
float cosa;
|
||||
float sina;
|
||||
|
||||
cosa = (float)cos( DegreeToRadian(pitch) );
|
||||
sina = (float)sin( DegreeToRadian(pitch) );
|
||||
cosa = (float)cos(DegreeToRadian(pitch));
|
||||
sina = (float)sin(DegreeToRadian(pitch));
|
||||
|
||||
right_.set( 1.f, 0.f, 0.f );
|
||||
up_.set( 0.f, cosa, -sina );
|
||||
at_.set( 0.f, sina, cosa );
|
||||
right_.set(1.f, 0.f, 0.f);
|
||||
up_.set(0.f, cosa, -sina);
|
||||
at_.set(0.f, sina, cosa);
|
||||
}
|
||||
|
||||
// up
|
||||
void Matrix3::constructAroundYaw( float yaw ) {
|
||||
void Matrix3::constructAroundYaw(float yaw) {
|
||||
float cosa;
|
||||
float sina;
|
||||
|
||||
cosa = (float)cos( DegreeToRadian(yaw) );
|
||||
sina = (float)sin( DegreeToRadian(yaw) );
|
||||
cosa = (float)cos(DegreeToRadian(yaw));
|
||||
sina = (float)sin(DegreeToRadian(yaw));
|
||||
|
||||
right_.set( cosa, 0.f, sina );
|
||||
up_.set( 0.f, 1.f, 0.f );
|
||||
at_.set( -sina, 0.f, cosa );
|
||||
right_.set(cosa, 0.f, sina);
|
||||
up_.set(0.f, 1.f, 0.f);
|
||||
at_.set(-sina, 0.f, cosa);
|
||||
}
|
||||
|
||||
// at
|
||||
void Matrix3::constructAroundRoll( float roll ) {
|
||||
void Matrix3::constructAroundRoll(float roll) {
|
||||
float cosa;
|
||||
float sina;
|
||||
|
||||
cosa = (float)cos( DegreeToRadian(roll) );
|
||||
sina = (float)sin( DegreeToRadian(roll) );
|
||||
cosa = (float)cos(DegreeToRadian(roll));
|
||||
sina = (float)sin(DegreeToRadian(roll));
|
||||
|
||||
right_.set( cosa, -sina, 0.f );
|
||||
up_.set( sina, cosa, 0.f );
|
||||
at_.set( 0.f, 0.f, 1.f );
|
||||
right_.set(cosa, -sina, 0.f);
|
||||
up_.set(sina, cosa, 0.f);
|
||||
at_.set(0.f, 0.f, 1.f);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -95,7 +95,7 @@ void Matrix3::constructAroundRoll( float roll ) {
|
||||
*/
|
||||
|
||||
// WARNING: Still buggy in some occasions.
|
||||
void Matrix3::getPitchYawRoll( float* pPitch, float* pYaw, float* pRoll ) {
|
||||
void Matrix3::getPitchYawRoll(float* pPitch, float* pYaw, float* pRoll) {
|
||||
float D;
|
||||
float C;
|
||||
float ftrx;
|
||||
@ -104,13 +104,13 @@ void Matrix3::getPitchYawRoll( float* pPitch, float* pYaw, float* pRoll ) {
|
||||
float angle_y;
|
||||
float angle_z;
|
||||
|
||||
angle_y = D = asin( right_.z() ); /* Calculate Y-axis angle */
|
||||
C = cos( angle_y );
|
||||
angle_y = RadianToDegree( angle_y );
|
||||
angle_y = D = asin(right_.z()); /* Calculate Y-axis angle */
|
||||
C = cos(angle_y);
|
||||
angle_y = RadianToDegree(angle_y);
|
||||
|
||||
if ( fabs( C ) > 0.005 ) { /* Gimball lock? */
|
||||
if (fabs( C ) > 0.005) { /* Gimball lock? */
|
||||
ftrx = at_.z() / C; /* No, so get X-axis angle */
|
||||
ftry = -up_.z() / C;
|
||||
ftry = -up_.z() / C;
|
||||
|
||||
angle_x = RadianToDegree(atan2( ftry, ftrx ));
|
||||
|
||||
@ -121,10 +121,10 @@ void Matrix3::getPitchYawRoll( float* pPitch, float* pYaw, float* pRoll ) {
|
||||
} else { /* Gimball lock has occurred */
|
||||
angle_x = 0; /* Set X-axis angle to zqero */
|
||||
|
||||
ftrx = up_.y(); /* And calculate Z-axis angle */
|
||||
ftry = up_.x();
|
||||
ftrx = up_.y(); /* And calculate Z-axis angle */
|
||||
ftry = up_.x();
|
||||
|
||||
angle_z = RadianToDegree(atan2( ftry, ftrx ));
|
||||
angle_z = RadianToDegree(atan2(ftry, ftrx));
|
||||
}
|
||||
|
||||
/* return only positive angles in [0,360] */
|
||||
@ -145,7 +145,7 @@ void Matrix3::getPitchYawRoll( float* pPitch, float* pYaw, float* pRoll ) {
|
||||
float Matrix3::getPitch() {
|
||||
float pitch;
|
||||
|
||||
getPitchYawRoll( &pitch, 0, 0);
|
||||
getPitchYawRoll(&pitch, 0, 0);
|
||||
|
||||
return pitch;
|
||||
}
|
||||
@ -153,7 +153,7 @@ float Matrix3::getPitch() {
|
||||
float Matrix3::getYaw() {
|
||||
float yaw;
|
||||
|
||||
getPitchYawRoll( 0, &yaw, 0);
|
||||
getPitchYawRoll(0, &yaw, 0);
|
||||
|
||||
return yaw;
|
||||
}
|
||||
@ -161,20 +161,20 @@ float Matrix3::getYaw() {
|
||||
float Matrix3::getRoll() {
|
||||
float roll;
|
||||
|
||||
getPitchYawRoll( 0, 0, &roll);
|
||||
getPitchYawRoll(0, 0, &roll);
|
||||
|
||||
return roll;
|
||||
}
|
||||
|
||||
void Matrix3::transform( Vector3d* v ) {
|
||||
void Matrix3::transform(Vector3d* v) {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
|
||||
x = v->dotProduct( right_.x(), up_.x(), at_.x() );
|
||||
y = v->dotProduct( right_.x(), up_.x(), at_.x() );
|
||||
z = v->dotProduct( right_.x(), up_.x(), at_.x() );
|
||||
x = v->dotProduct(right_.x(), up_.x(), at_.x());
|
||||
y = v->dotProduct(right_.x(), up_.x(), at_.x());
|
||||
z = v->dotProduct(right_.x(), up_.x(), at_.x());
|
||||
|
||||
v->set( x, y, z );
|
||||
v->set(x, y, z);
|
||||
}
|
||||
|
||||
|
@ -18,16 +18,16 @@
|
||||
#include "matrix4.h"
|
||||
|
||||
Matrix4::Matrix4( void ) {
|
||||
pos_.set( 0.f, 0.f, 0.f );
|
||||
pos_.set(0.f, 0.f, 0.f);
|
||||
rot_.setAsIdentity();
|
||||
}
|
||||
|
||||
void Matrix4::translate( float x, float y, float z ) {
|
||||
void Matrix4::translate(float x, float y, float z) {
|
||||
Vector3d v;
|
||||
|
||||
v.set( x, y, z );
|
||||
v.set(x, y, z);
|
||||
|
||||
rot_.transform( &v );
|
||||
rot_.transform(&v);
|
||||
|
||||
pos_ += v;
|
||||
}
|
||||
|
@ -22,12 +22,12 @@
|
||||
#include "matrix3.h"
|
||||
|
||||
// matrix 4 is a rotation matrix + position
|
||||
class Matrix4{
|
||||
class Matrix4 {
|
||||
public:
|
||||
Matrix3 rot_;
|
||||
Vector3d pos_;
|
||||
|
||||
Matrix4( void );
|
||||
Matrix4();
|
||||
|
||||
Matrix4& operator =(const Matrix4& s) {
|
||||
pos_ = s.pos_;
|
||||
@ -40,7 +40,7 @@ public:
|
||||
Vector3d v;
|
||||
|
||||
v = s.pos_;
|
||||
rot_.transform( &v );
|
||||
rot_.transform(&v);
|
||||
|
||||
pos_+=v;
|
||||
|
||||
@ -49,7 +49,7 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
void translate( float x, float y, float z );
|
||||
void translate(float x, float y, float z);
|
||||
|
||||
private:
|
||||
};
|
||||
|
20
screen.cpp
20
screen.cpp
@ -43,7 +43,7 @@ float getZbufferBlockDepth(char *zbuffer, int x, int y) {
|
||||
writePtr = (char *)buffer;
|
||||
|
||||
for(i = 0; i < 16; i++) {
|
||||
readPtr = zbuffer + (y*16+i) * 640 + (x * 16);
|
||||
readPtr = zbuffer + (y * 16 + i) * 640 + (x * 16);
|
||||
for(j = 0; j < 16; j++) {
|
||||
*(writePtr++) = *(readPtr++);
|
||||
*(writePtr++) = *(readPtr++);
|
||||
@ -126,11 +126,11 @@ void screenBlocksAddRectangle( int top, int right, int left, int bottom, float d
|
||||
firstTop = top /16;
|
||||
|
||||
width = (right - left) / 16;
|
||||
if((right-left)%16)
|
||||
if((right-left) % 16)
|
||||
width++;
|
||||
|
||||
height = (bottom - top) / 16;
|
||||
if((bottom - top)%16)
|
||||
if((bottom - top) % 16)
|
||||
height++;
|
||||
|
||||
// temp hack
|
||||
@ -165,14 +165,14 @@ void screenBlocksDrawDebug() {
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
for(i = 0; i< 40; i++) {
|
||||
for(i = 0; i < 40; i++) {
|
||||
for(j = 0;j < 30; j++) {
|
||||
if(screenBlockData[i][j].isDirty) {
|
||||
glBegin(GL_QUADS);
|
||||
glVertex2i(i*16,j*16);
|
||||
glVertex2i((i+1)*16,j*16);
|
||||
glVertex2i((i+1)*16,(j+1)*16);
|
||||
glVertex2i(i*16,(j+1)*16);
|
||||
glVertex2i(i * 16, j * 16);
|
||||
glVertex2i((i + 1) * 16, j * 16);
|
||||
glVertex2i((i + 1) * 16, (j + 1) * 16);
|
||||
glVertex2i(i * 16,(j + 1)*16);
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
@ -208,8 +208,8 @@ void screenBlocksBlitDirtyBlocks() {
|
||||
width++;
|
||||
}
|
||||
for (int y = 0; y < 16; y++) {
|
||||
glRasterPos2i(start*16, j*16 + y + 1);
|
||||
glDrawPixels(16*width, 1, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, dataTemp+((j*16 +y) * 640)+(start*16));
|
||||
glRasterPos2i(start * 16, j * 16 + y + 1);
|
||||
glDrawPixels(16 * width, 1, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, dataTemp+((j*16 +y) * 640)+(start*16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user