From 22ed69f29f6c65e598b722f3936eb8a7c4abb00c Mon Sep 17 00:00:00 2001 From: Daveo Date: Thu, 1 Mar 2001 19:42:09 +0000 Subject: [PATCH] --- Utils/MapEdit/Elem.cpp | 381 +++++++++++++++++++++++++++++++++++++++++ Utils/MapEdit/Elem.h | 96 +++++++++++ 2 files changed, 477 insertions(+) create mode 100644 Utils/MapEdit/Elem.cpp create mode 100644 Utils/MapEdit/Elem.h diff --git a/Utils/MapEdit/Elem.cpp b/Utils/MapEdit/Elem.cpp new file mode 100644 index 000000000..c23a12d00 --- /dev/null +++ b/Utils/MapEdit/Elem.cpp @@ -0,0 +1,381 @@ +/*********************/ +/*** Tile Stuph ***/ +/*********************/ + +#include "stdafx.h" +#include +#include +#include +#include +#include + +#include "Core.h" +#include "TexCache.h" +//#include "TileSet.h" +#include "Tile.h" +#include "GinTex.h" +#include "utils.h" + + + +/*****************************************************************************/ +const float XFlipMtx[]= +{ +-1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1, +}; + +const float YFlipMtx[]= +{ + 1, 0, 0, 0, + 0,-1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1, +}; + +/*****************************************************************************/ +/* +CTile::CTile() +{ +} +*/ +/*****************************************************************************/ +CTile::CTile(int Blank,int _Width,int _Height) +{ + Width=_Width; + Height=_Height; + PCTexID=-1; + PCTexRGB=(u8*)malloc(Width*Height*3); + memset(PCTexRGB,0,Width*Height*3); + Tex2dID=-1; + Type=TileType2d; +} + +/*****************************************************************************/ +// 3d tile (From Gin File) +CTile::CTile(CCore *Core,const char *Filename,CScene &ThisScene,int Node) +{ +CNode &ThisNode=ThisScene.GetNode(Node); +CTexCache &TexCache=Core->GetTexCache(); +GFName Path=Filename; + + SetPath=Path.Drive(); + SetPath+=Path.Dir(); + SetPath.Append('\\'); + + Type=TileType3d; + TexXOfs=-1; + TexYOfs=-1; + Build3dTile(TexCache,ThisScene,Node); + Ofs.x=+0.5f; Ofs.y=0; Ofs.z=+4.0f; + Build3dDrawList(TexCache,DrawList[TileType3d]); + Create2dTexture(TexCache,Path.File(),Node); + Build2dDrawList(TexCache,DrawList[TileType2d]); +} + +/*****************************************************************************/ +// 2d tile (From Bmp File) +CTile::CTile(CCore *Core,const char *Filename,int TexID,int XOfs,int YOfs) +{ +CTexCache &TexCache=Core->GetTexCache(); +GFName Path=Filename; + + Type=TileType2d; + TexXOfs=XOfs; + TexYOfs=YOfs; + + Build2dTile(Core,Path.File(),TexID); + Ofs.Zero(); + Build3dDrawList(TexCache,DrawList[TileType3d]); + Create2dTexture(TexCache,Path.File(),TexID); + Build2dDrawList(TexCache,DrawList[TileType2d]); +} + +/*****************************************************************************/ +void CTile::Build2dTile(CCore *Core,const char *Filename,int TexID) +{ +const Vector3 P0(0.0f,0.0f,0.0f); +const Vector3 P1(1.0f,0.0f,0.0f); +const Vector3 P2(0.0f,1.0f,0.0f); +const Vector3 P3(1.0f,1.0f,0.0f); + +int ListSize=TriList.size(); + TriList.resize(ListSize+2); +sTriFace &Tri0=TriList[ListSize+0]; +sTriFace &Tri1=TriList[ListSize+1]; + +CTexCache &TexCache=Core->GetTexCache(); +sTex &ThisTex=TexCache.GetTex(TexID); + +float u0,u1,v0,v1; + + Tex2dID=TexID; + u0=(TexXOfs)*ThisTex.dW; + u1=u0+ThisTex.dW; + + v0=(((ThisTex.TexHeight/16)-(TexYOfs+1))*ThisTex.dH); + v1=v0+ThisTex.dH; + + Tri0.Mat=TexID; + + Tri0.vtx[0]=P0; + Tri0.vtx[1]=P1; + Tri0.vtx[2]=P2; + Tri0.uvs[0].u=u0; Tri0.uvs[0].v=v0; + Tri0.uvs[1].u=u1; Tri0.uvs[1].v=v0; + Tri0.uvs[2].u=u0; Tri0.uvs[2].v=v1; + + Tri1.Mat=TexID; + Tri1.vtx[0]=P1; + Tri1.vtx[1]=P2; + Tri1.vtx[2]=P3; + Tri1.uvs[0].u=u1; Tri1.uvs[0].v=v0; + Tri1.uvs[1].u=u0; Tri1.uvs[1].v=v1; + Tri1.uvs[2].u=u1; Tri1.uvs[2].v=v1; +} + +/*****************************************************************************/ +void CTile::Build3dTile(CTexCache &TexCache,CScene &ThisScene,int Node) +{ +CNode &ThisNode=ThisScene.GetNode(Node); +int ChildCount=ThisNode.GetChildCount(); +std::vector const &NodeTriList=ThisNode.GetTris(); +std::vectorconst &NodeVtxList=ThisNode.GetRelPts(); +std::vector const &NodeUVList=ThisNode.GetUVTris(); +std::vector const &NodeTriMat=ThisNode.GetTriMaterial(); +std::vector const &TexList= ThisScene.GetTexNames();//List(); +std::vector const &MatList= ThisScene.GetMaterials(); + +int TriCount=NodeTriList.size(); +int ListSize=TriList.size(); + + TriList.resize(ListSize+TriCount); + for (int T=0; T> PC_TILE_FLAG_COLLISION_SHIFT; + + if (ColFlags) + { + switch (ColFlags) + { + case PC_TILE_COLLISION_NORMAL: glColor4f(1,1,1,0.5); break; + case PC_TILE_COLLISION_DAMAGE: glColor4f(1,0,0,0.5); break; + case PC_TILE_COLLISION_SLIPPERY: glColor4f(0,1,0,0.5); break; + case PC_TILE_COLLISION_ELECTRIC: glColor4f(1,0,1,0.5); break; + case PC_TILE_COLLISION_STICKY: glColor4f(1,1,0,0.5); break; + case PC_TILE_COLLISION_WATER: glColor4f(0,0,1,0.5); break; + } + } + + glEnable(GL_TEXTURE_2D); + glCallList(DrawList[Render3d]); + glDisable(GL_TEXTURE_2D); + glPopMatrix(); +} + +/*****************************************************************************/ +void CTile::Purge() +{ + glDeleteLists(DrawList[TileType3d],1); + glDeleteLists(DrawList[TileType2d],1); + TriList.clear(); +} + +/*****************************************************************************/ +void CTile::RenderTile4Texture(sRGBData &RGBData) +{ + + glPushAttrib(GL_VIEWPORT_BIT); + glViewport(0,0,RGBData.Width,RGBData.Height); + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + + glLoadIdentity(); + glOrtho(-0.5f, +0.5f, -0.5f, +0.5f, -16.0f, +16.0f); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + glTranslatef(-0.5f,-0.5f,0); + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen + + glColor3f(1,1,1); + glEnable(GL_TEXTURE_2D); + glEnable(GL_DEPTH_TEST); + glCallList(DrawList[TileType3d]); + glDisable(GL_DEPTH_TEST); + glDisable(GL_TEXTURE_2D); + + glPopMatrix(); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glPopAttrib(); + + glReadPixels(0,0,RGBData.Width,RGBData.Height,GL_RGB, GL_UNSIGNED_BYTE,RGBData.RGB); +} + +/*****************************************************************************/ +// ID used to create unique textures within one set :o) +void CTile::Create2dTexture(CTexCache &TexCache,const char *Filename,int ID) +{ +sRGBData RGBData; + +// PC + glClearColor(1,0,1,1 ); + RGBData.Width=PCTexWidth; + RGBData.Height=PCTexHeight; + RGBData.RGB=PCTexRGB; + RenderTile4Texture(RGBData); + PCTexID=TexCache.ProcessTexture("",0,&RGBData); + ValidFlag=CheckHasData(RGBData); + glClearColor(0,0,0,1 ); + +#ifdef _DEBUG + if (0) + { +char Filename[256]; +char TexName[256]; +static asd=0; + sprintf(TexName,"_2dPc_%s_%03d",Filename,asd++); + sprintf(Filename,"/x/%s.Tga",TexName); + SaveTGA(Filename,PCTexWidth,PCTexHeight,PCTexRGB); + } + +#endif + +} + +/*****************************************************************************/ +bool CTile::CheckHasData(sRGBData &RGBData) +{ +u8 *Src=RGBData.RGB; +int Size=RGBData.Width*RGBData.Height; + + for (int i=0; i +#include +#include +#include +#include "TexCache.h" +#include "GinTex.h" + +struct sTriFace +{ + int Mat; + Vector3 vtx[3]; + int pts[3]; + sUV uvs[3]; +}; + + +/*****************************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ +class CCore; +class CElem +{ +public: + enum ElemType + { + ElemType2d=0, + ElemType3d, + }; + enum ElemEnums + { + PCTexWidth =16, + PCTexHeight =PCTexWidth, + }; + +// CElem(); + CElem(int Blank,int Width=PCTexWidth,int Height=PCTexHeight ); // Blank (2d) + CElem(CCore *Core,const char *Filename,int TexId,int XOfs,int YOfs); // 2d elem + CElem(CCore *Core,const char *Filename,CScene &ThisScene,int Node); // 3d elem + + void Purge(); + void Render(int Flags,bool Render3d); + + int GetPCTexW() {return(PCTexWidth);} + int GetPCTexH() {return(PCTexHeight);} + u8 *GetPCTexRGB() {return(PCTexRGB);} + + bool IsValid() {return(ValidFlag);} + + bool IsElem3d() {return(Type==ElemType3d);} + int GetTexXOfs() {return(TexXOfs);} + int GetTexYOfs() {return(TexYOfs);} + int GetTexID() {return(Tex2dID);} + + std::vector &GetTriList() {return(TriList);} + +protected: + void Build3dElem(CTexCache &TexCache,CScene &ThisScene,int Node); + void Build2dElem(CCore *Core,const char *Filename,int TexId); +// void FixUp(); + void Build3dDrawList(CTexCache &TexCache,GLint &List); + void Build2dDrawList(CTexCache &TexCache,GLint &List); + + void RenderElem4Texture(sRGBData &RGBData); + void Create2dTexture(CTexCache &TexCache,const char *Filename,int ID); + bool CheckHasData(sRGBData &RGBData); + + GString SetPath; + + std::vector TriList; + + + Vector3 Ofs; + int Width,Height; + + GLint DrawList[2]; + ElemType Type; + bool ValidFlag; + int TexXOfs,TexYOfs; + int Tex2dID; + +// char PCTexName[256]; + int PCTexID; + u8 *PCTexRGB; + +}; + +/*****************************************************************************/ +#endif \ No newline at end of file