This commit is contained in:
parent
46791b36f4
commit
84eb6ded52
15 changed files with 243 additions and 108 deletions
|
@ -8,10 +8,10 @@
|
|||
#include <gl\gl.h>
|
||||
#include <gl\glu.h>
|
||||
#include <gl\glut.h>
|
||||
//#include "GLEnabledView.h"
|
||||
#include "GLEnabledView.h"
|
||||
|
||||
//#include "MapEditDoc.h"
|
||||
//#include "MapEditView.h"
|
||||
#include "MapEditDoc.h"
|
||||
#include "MapEditView.h"
|
||||
|
||||
#include "Core.h"
|
||||
#include "Layer.h"
|
||||
|
@ -43,9 +43,6 @@ int Height=Map.GetHeight();
|
|||
/*****************************************************************************/
|
||||
void CLayer::Render(Vec &MapPos,BOOL Is3d)
|
||||
{
|
||||
if (Is3d && CanRender3d())
|
||||
Render3d(MapPos);
|
||||
else
|
||||
Render2d(MapPos);
|
||||
}
|
||||
|
||||
|
@ -62,7 +59,6 @@ int Height=Map.GetHeight();
|
|||
glTranslatef(MapPos.x/XYDiv,MapPos.y/XYDiv,MapPos.z);
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
SetTestColor();
|
||||
BuildGLQuad(-1,Width+1,-1,0,0); // Bottom
|
||||
BuildGLQuad(-1,Width+1,Height+1,Height,0); // Top
|
||||
BuildGLQuad(-1,0,Height,0,0); // Left
|
||||
|
@ -73,37 +69,133 @@ int Height=Map.GetHeight();
|
|||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
float asd=0;
|
||||
void CLayer::Render3d(Vec &MapPos)
|
||||
{
|
||||
float XYDiv=GetLayerZPosDiv();
|
||||
float X,Y;
|
||||
int XX=0;
|
||||
int YY=0;
|
||||
int MapW=Map.GetWidth();
|
||||
int MapH=Map.GetHeight();
|
||||
float StartX=MapPos.x/XYDiv;
|
||||
float StartY=MapPos.y/XYDiv;
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
Y=MapPos.y;
|
||||
|
||||
for (YY=0; YY<3; YY++)
|
||||
for (int YLoop=0; YLoop<MapH; YLoop++)
|
||||
{
|
||||
X=MapPos.x;
|
||||
for (XX=0; XX<3; XX++)
|
||||
for (int XLoop=0; XLoop<MapW; XLoop++)
|
||||
{
|
||||
glLoadIdentity();
|
||||
glTranslatef(X/XYDiv,Y/XYDiv,MapPos.z);
|
||||
// glRotatef(asd,0,1,0);
|
||||
// asd+=0.5;
|
||||
// glCallList(Core->GetTile(0,2));
|
||||
glCallList(Core->GetTile(0,XX+(YY*3)));
|
||||
|
||||
X+=1.0f;
|
||||
sMapElem &ThisTile=Map.GetTile(XLoop,YLoop);
|
||||
|
||||
glLoadIdentity(); // Slow way, but good to go for the mo
|
||||
glTranslatef(StartX+XLoop,StartY-YLoop,MapPos.z);
|
||||
glCallList(Core->GetTile(ThisTile.Bank,ThisTile.Tile));
|
||||
}
|
||||
Y+=1.0f;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CLayer::RenderGrid(Vec &MapPos)
|
||||
{
|
||||
float XYDiv=GetLayerZPosDiv();
|
||||
int MapW=Map.GetWidth();
|
||||
int MapH=Map.GetHeight();
|
||||
float StartX=MapPos.x/XYDiv;
|
||||
float StartY=MapPos.y/XYDiv;
|
||||
float OverVal=0.5;
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glTranslatef(StartX,StartY,MapPos.z);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
glBegin(GL_LINES);
|
||||
glNormal3f( 1,1,1);
|
||||
glColor3ub(255,255,255);
|
||||
|
||||
for (int YLoop=0; YLoop<MapH+1; YLoop++)
|
||||
{
|
||||
glVertex3f( 0-OverVal, -YLoop+1, 0);
|
||||
glVertex3f( MapW+OverVal, -YLoop+1, 0);
|
||||
}
|
||||
|
||||
for (int XLoop=0; XLoop<MapW+1; XLoop++)
|
||||
{
|
||||
glVertex3f( XLoop, 0+1+OverVal, 0);
|
||||
glVertex3f( XLoop, -MapH+1-OverVal, 0);
|
||||
}
|
||||
glEnd();
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CLayer::FindCursorPos(Vec &MapPos,CPoint &MousePos)
|
||||
{
|
||||
GLint Viewport[4];
|
||||
GLuint SelectBuffer[SELECT_BUFFER_SIZE];
|
||||
int HitCount;
|
||||
int TileID=0;
|
||||
CPoint &CursorPos=Core->GetCursorPos();
|
||||
|
||||
float XYDiv=GetLayerZPosDiv();
|
||||
int MapW=Map.GetWidth();
|
||||
int MapH=Map.GetHeight();
|
||||
float StartX=MapPos.x/XYDiv;
|
||||
float StartY=MapPos.y/XYDiv;
|
||||
|
||||
glGetIntegerv(GL_VIEWPORT, Viewport);
|
||||
glSelectBuffer (SELECT_BUFFER_SIZE, SelectBuffer );
|
||||
glRenderMode (GL_SELECT);
|
||||
|
||||
glInitNames();
|
||||
glPushName(-1);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
gluPickMatrix( MousePos.x ,(Viewport[3]-MousePos.y),5.0,5.0,Viewport);
|
||||
Core->GetParentWindow()->SetupPersMatrix();
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glTranslatef(StartX,StartY,MapPos.z);
|
||||
|
||||
|
||||
for (int YLoop=0; YLoop<MapH; YLoop++)
|
||||
{
|
||||
for (int XLoop=0; XLoop<MapW; XLoop++)
|
||||
{
|
||||
glLoadName (TileID);
|
||||
glBegin (GL_QUADS);
|
||||
BuildGLQuad(XLoop,XLoop+1,-YLoop,-YLoop+1,0);
|
||||
glEnd();
|
||||
TileID++;
|
||||
}
|
||||
}
|
||||
|
||||
HitCount= glRenderMode (GL_RENDER);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
CursorPos.x=CursorPos.y=-1;
|
||||
// TRACE1("Hits %i\n",HitCount);
|
||||
|
||||
// Process hits
|
||||
|
||||
GLuint *Ptr=SelectBuffer,*BestHit=0;
|
||||
|
||||
for (int H=0;H<HitCount;H++)
|
||||
{
|
||||
BestHit=Ptr; // Fakeness for the mo
|
||||
}
|
||||
|
||||
if (BestHit)
|
||||
{
|
||||
int HitID=BestHit[3];
|
||||
CursorPos.x=HitID%MapH;
|
||||
CursorPos.y=HitID/MapW;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue