Files
pvvmud/common/include/geometry.H
2025-03-05 08:37:43 +01:00

255 lines
7.1 KiB
C++

/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef _GEOMETRY_H
#define _GEOMETRY_H
#include "object.H"
#include "objectarray.H"
#include <stdio.h>
#include "cache.H"
#include "texture.H"
#include "material.H"
#include "intarray.H"
#include "doublearray.H"
#include "beam.H"
#include "vector.H"
#include "plane.H"
#include "vertex.H"
#include "bbox.H"
#ifdef HAVE_GL_GL_H
#include <GL/gl.h>
#define POLYGON_TRIANGLES GL_TRIANGLES
#define POLYGON_TRIANGLE_STRIP GL_TRIANGLE_STRIP
#define POLYGON_TRIANGLE_FAN GL_TRIANGLE_FAN
#define POLYGON_QUADS GL_QUADS
#define POLYGON_QUAD_STRIP GL_QUAD_STRIP
#define POLYGON_POLYGON GL_POLYGON
typedef GLdouble TexCoordCoord_t;
typedef GLdouble NormalVector_t;
#else /* HAVE_GL_GL_H */
#define POLYGON_TRIANGLES 0x0004
#define POLYGON_TRIANGLE_STRIP 0x0005
#define POLYGON_TRIANGLE_FAN 0x0006
#define POLYGON_QUADS 0x0007
#define POLYGON_QUAD_STRIP 0x0008
#define POLYGON_POLYGON 0x0009
typedef double TexCoordCoord_t;
typedef double NormalVector_t;
#endif /* HAVE_GL_GL_H */
class CGeometry;
class CTexCoord : public CObject{
TexCoordCoord_t m_coord[2];
public:
CTexCoord(double u, double v);
TexCoordCoord_t * getCoord();
void setCoord(double u, double v);
double getU();
double getV();
};
class CNormal : public CObject{
NormalVector_t m_vector[3];
public:
CNormal(double x, double y, double z);
NormalVector_t * getVector();
void setVector(double x, double y, double z);
double getX();
double getY();
double getZ();
};
class CVertexList : public CObjectArray {
public:
CVertexList(int size);
virtual ~CVertexList();
int add( double x, double y, double z );
void set( int index, double x, double y, double z );
void get( int index, double * x, double * y, double * z );
VertexCoord_t * get( int index );
CVertex * getVertex( int index );
int getSize();
};
class CNormalList : public CObjectArray {
public:
CNormalList(int size);
virtual ~CNormalList();
int add(double x, double y, double z);
void set( int index, double x, double y, double z );
void get(int index, double * x, double * y, double * z );
NormalVector_t * get( int index );
CNormal * getNormal( int index );
};
class CTexCoordList : public CObjectArray {
public:
CTexCoordList(int size);
virtual ~CTexCoordList();
int add( double u, double v);
void set( int index, double u, double v );
void get( int index, double * u, double * v );
TexCoordCoord_t * get( int index );
CTexCoord * getTexCoord( int index );
};
class CPolygon;
class CPolygonList : public CObjectArray {
CGeometry * m_geometry;
public:
CPolygonList(CGeometry * geometry,int size);
virtual ~CPolygonList();
int add( CPolygon * polygon );
void set( int index, CPolygon * polygon );
CPolygon * get(int index );
};
class CPolygon : public CObject{
int m_materialId;
int m_type; /* POLYGON_QUADS , POLYGON_POLYGON , etc */
CIntArray * m_vertexIndexList;
CIntArray * m_normalIndexList;
CIntArray * m_texCoordIndexList;
CGeometry * m_geometry;
public:
CPolygon(int type, int materialId, int numVertices,
int numNormals, int numTexCoords);
virtual ~CPolygon();
void setGeometry(CGeometry * geometry);
void get( int * type,
int * materialId, int * numVertices,
int * numNormals, int * numTexCoords );
int getType();
void setMaterial( int materialId );
int getMaterial();
int addVertexIndex( int vertexIndex );
void setVertexIndex( int index, int vertexIndex );
int getVertexIndex( int index );
CVertex * getVertex( int index );
int addNormalIndex( int normalIndex );
void setNormalIndex( int index, int normalIndex );
int getNormalIndex( int index );
CNormal * getNormal( int index );
int addTexCoordIndex( int texCoordIndex );
void setTexCoordIndex( int index, int texCoordIndex );
int getTexCoordIndex( int index );
CTexCoord * getTexCoord( int index );
CIntArray * getVertexIList();
int getNumVertices();
CIntArray * getNormalIList();
CIntArray * getTexCoordIList();
void distances(CDoubleArray & distArray, const CBeam & beam);
CDoubleArray* distances(const CBeam & beam);
};
class CGeometry : public CObject{
protected:
int id,subid;
CGeometry * next;
CVertexList * vertexList;
CNormalList * normalList;
CTexCoordList * texCoordList;
CPolygonList * polygonList;
public:
CGeometry(int objectGeometryId);
CGeometry(int objectGeometryId, int numVertices,
int numNormals, int numTexCoords, int numPolygons);
virtual ~CGeometry();
virtual CGeometry * newGeometry(int geometryId);
void setSize(int numVertices, int numNormals,
int numTexCoords, int numPolygons);
int getId();
void setId(int id);
void setSubId( int subid );
int getSubId();
int getNumSubobjects();
void setNext( CGeometry * next );
CGeometry * getNext();
int addVertex( double x, double y, double z );
void getVertex( int index, double * x,
double * y, double * z );
CVertex * getVertex( int index );
void setVertex( int index, double x,
double y, double z );
int addNormal( double x, double y, double z );
void setNormal( int index, double x, double y, double z );
void getNormal( int index, double * x,
double * y, double * z );
CNormal * getNormal( int index );
int addTexCoord( double u, double v );
void setTexCoord( int index, double u, double v );
void getTexCoord( int index, double * u,
double * v );
CTexCoord * getTexCoord( int index );
virtual int draw( CMaterialCache * matCache, CTextureCache * texCache );
int addPolygon( CPolygon * polygon );
void setPolygon( int index, CPolygon * polygon );
CPolygon * getPolygon(int index );
int getNumVertices();
int getNumNormals();
int getNumTexCoords();
int getNumPolygons();
int scale( double scale );
// int ReadBOG(int objId, FILE * bog);
void distances(CDoubleArray & distArray, const CBeam & beam, double min, double max);
CDoubleArray * distances(const CBeam & beam, double min, double max);
CBBox calculateBBox();
void load(char * name);
void save(char * name);
void readBOG(FILE * bog);
int writeBOG(FILE * bog);
private:
int readBOGCore(FILE * bog, int numV, int numN, int numTC, int numP);
};
class CGeometryCache : public CCache {
public:
CGeometryCache();
virtual ~CGeometryCache();
CGeometry * add( CGeometry * objGeo );
CGeometry * get( int id );
};
#endif /* _GEOMETRY_H */