3DSHAPES.H
资源名称:tc3d.zip [点击查看]
上传用户:abcdshs
上传日期:2007-01-07
资源大小:1858k
文件大小:5k
源码类别:
游戏
开发平台:
Visual C++
- // (C) Copyright 1996 by Anthony J. Carin. All Rights Reserved.
- #ifndef _3DSHAPES_H
- #define _3DSHAPES_H
- #include <math.h>
- #include <windows.h>
- #include "launch.h"
- #include "tcdirect.h"
- #include "color.h"
- class coordinate
- {
- public:
- coordinate() { m_x = m_y = m_z = 0.0f; }
- coordinate(float x, float y, float z) { setto(x,y,z); }
- coordinate(coordinate& o) { setto(o.x(),o.y(),o.z()); }
- virtual coordinate& operator =(coordinate& o) { setto(o.x(),o.y(),o.z()); return *this; }
- virtual void setto(coordinate& o) { setto(o.x(),o.y(),o.z()); }
- void setto(float x, float y, float z);
- void stepto(coordinate& o, float step, char stop = TRUE);
- float x() { return m_x; }
- float y() { return m_y; }
- float z() { return m_z; }
- void setx(float x) { m_x = x; }
- void sety(float y) { m_y = y; }
- void setz(float z) { m_z = z; }
- void operator +=(coordinate& c);
- void operator -=(coordinate& c);
- direction& xdirectionto(coordinate& b);
- direction& ydirectionto(coordinate& b);
- direction& zdirectionto(coordinate& b);
- float distanceto(coordinate& b);
- friend coordinate& operator+(coordinate& a, coordinate& b);
- friend coordinate& operator-(coordinate& a, coordinate& b);
- friend char operator!=(coordinate& a, coordinate& b);
- friend char operator==(coordinate& a, coordinate& b);
- protected:
- float m_x;
- float m_y;
- float m_z;
- };
- inline direction& coordinate::xdirectionto(coordinate& b)
- {
- static direction r;
- r = getdirection(m_y,m_z,b.m_y,b.m_z);
- return r;
- }
- inline direction& coordinate::ydirectionto(coordinate& b)
- {
- static direction r;
- r = getdirection(m_x,m_z,b.m_x,b.m_z);
- return r;
- }
- inline direction& coordinate::zdirectionto(coordinate& b)
- {
- static direction r;
- r = getdirection(m_x,m_y,b.m_x,b.m_y);
- return r;
- }
- inline float coordinate::distanceto(coordinate& b)
- {
- double x = m_x - b.m_x;
- double z = m_z - b.m_z;
- return (float) sqrt(x*x+z*z);
- }
- inline void coordinate::setto(float nx, float ny, float nz)
- {
- m_x = nx;
- m_y = ny;
- m_z = nz;
- }
- inline char operator!=(coordinate& a, coordinate& b)
- {
- return (char)!operator==(a,b);
- }
- class view : public coordinate
- {
- public:
- view() : coordinate() { m_xdirection = m_ydirection = m_zdirection = (short) 0; }
- view(coordinate& c) : coordinate(c) { m_xdirection = m_ydirection = m_zdirection = (short) 0; }
- view(view& c);
- void setxdir(direction dir) { m_xdirection = dir; }
- void setydir(direction dir) { m_ydirection = dir; }
- void setzdir(direction dir) { m_zdirection = dir; }
- direction& xdirection() { return m_xdirection; }
- direction& ydirection() { return m_ydirection; }
- direction& zdirection() { return m_zdirection; }
- //view& operator =(view& v);
- private:
- direction m_xdirection;
- direction m_ydirection;
- direction m_zdirection;
- };
- class point : public coordinate
- {
- public:
- point() : coordinate() {}
- point(coordinate& c) : coordinate(c) {}
- point(float x, float y, float z) : coordinate(x,y,z) {}
- point& operator =(point& o) { setto(o.x(),o.y(),o.z()); return *this; }
- void xrotate(direction& d);
- void yrotate(direction& d);
- void zrotate(direction& d);
- };
- class polygon
- {
- public:
- polygon() { m_linenum = 0; }
- polygon(polygon& p);
- polygon(coordinate& a, coordinate& b, coordinate& c);
- polygon(coordinate& a, coordinate& b, coordinate& c, coordinate& d);
- void setto(coordinate& a, coordinate& b, coordinate& c);
- void setcolor(int c) { m_color = c; }
- COLORREF color() { return m_color; }
- coordinate& getcenter();
- point& a() { return m_a; }
- point& b() { return m_b; }
- point& c() { return m_c; }
- point& d() { return m_d; }
- virtual void setto(coordinate& a, coordinate& b, coordinate& c, coordinate& d);
- virtual void operator =(polygon &p);
- protected:
- point m_a;
- point m_b;
- point m_c;
- point m_d;
- char m_linenum;
- tccolor m_color;
- private:
- };
- inline polygon::polygon(coordinate& a, coordinate& b, coordinate& c, coordinate& d)
- {
- setto(a,b,c,d);
- }
- inline polygon::polygon(coordinate& a, coordinate& b, coordinate& c)
- {
- setto(a,b,c);
- }
- inline void polygon::operator =(polygon& p)
- {
- m_linenum = p.m_linenum;
- m_a = p.m_a;
- m_b = p.m_b;
- m_c = p.m_c;
- m_d = p.m_d;
- m_color = p.m_color;
- }
- #endif