From a3b274ba622c67cb597fa9b49b55ff416dc34236 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 8 May 2014 10:46:18 +0200 Subject: CGE2: Add new types: V2D and V3D. --- engines/cge2/general.h | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'engines/cge2/general.h') diff --git a/engines/cge2/general.h b/engines/cge2/general.h index 7d5c60f191..5564cd03ee 100644 --- a/engines/cge2/general.h +++ b/engines/cge2/general.h @@ -29,15 +29,77 @@ #define CGE2_GENERAL_H #include "common/file.h" +#include "common/rect.h" +#include "cge2/fileio.h" namespace CGE2 { +#define SCR_WID_ 320 + struct Dac { uint8 _r; uint8 _g; uint8 _b; }; +// From CGETYPE.H: +class V3D { +public: + double X, Y, Z; + V3D(void) { } + V3D(double x, double y, double z = 0) : X(x), Y(y), Z(z) { } + V3D(const V3D &p) : X(p.X), Y(p.Y), Z(p.Z) { } + V3D operator + (const V3D& p) const { return V3D(X + p.X, Y + p.Y, Z + p.Z); } + V3D operator - (const V3D& p) const { return V3D(X - p.X, Y - p.Y, Z - p.Z); } + V3D operator * (long n) const { return V3D(X * n, Y * n, Z * n); } + V3D operator / (long n) const { return V3D(X / n, Y / n, Z / n); } + bool operator == (V3D& p) const { return X == p.X && Y == p.Y && Z == p.Z; } + bool operator != (V3D& p) const { return X != p.X || Y != p.Y || Z != p.Z; } + V3D& operator += (const V3D& x) { return *this = *this + x; } + V3D& operator -= (const V3D& x) { return *this = *this - x; } +}; + +class V2D : public Common::Point { + double trunc(double d) { return (d > 0) ? floor(d) : ceil(d); } + double round(double number) { return number < 0.0 ? ceil(number - 0.5) : floor(number + 0.5); } +public: + V2D& operator = (const V3D& p3) { + double m = Eye.Z / (p3.Z - Eye.Z); + x = round((Eye.X + (Eye.X - p3.X) * m)); + y = round((Eye.Y + (Eye.Y - p3.Y) * m)); + return *this; + } + V2D(void) { } + V2D(const V3D& p3) { *this = p3; } + V2D(int x, int y) : Common::Point(x, y) { } + static V3D Eye; + static void SetEye(const V3D &e) { Eye = e; } + static void SetEye(const V2D& e2, int z = -SCR_WID_) { + Eye.X = e2.x; Eye.Y = e2.y; Eye.Z = z; + } + static void SetEye(const char *s) { + char *tempStr; + strcpy(tempStr, s); + Eye.X = atoi(EncryptedStream::token(tempStr)); + Eye.Y = atoi(EncryptedStream::token(tempStr)); + Eye.Z = atoi(EncryptedStream::token(tempStr)); + } + bool operator < (const V2D& p) const { return (x < p.x) && (y < p.y); } + bool operator <= (const V2D& p) const { return (x <= p.x) && (y <= p.y); } + bool operator >(const V2D& p) const { return (x > p.x) && (y > p.y); } + bool operator >= (const V2D& p) const { return (x >= p.x) && (y >= p.y); } + V2D operator + (const V2D& p) const { return V2D(x + p.x, y + p.y); } + V2D operator - (const V2D& p) const { return V2D(x - p.x, y - p.y); } + uint16 Area(void) { return x * y; } + bool Limited(const V2D& p) { + return (uint16(x) < uint16(p.x)) && (uint16(y) < uint16(p.y)); + } + V2D Scale(int z) { + double m = Eye.Z / (Eye.Z - z); + return V2D(trunc(m * x), trunc(m * y)); + } +}; + } // End of namespace CGE2 #endif // CGE2_GENERAL_H -- cgit v1.2.3