This commit is contained in:
parent
425713a3aa
commit
c1309c1c96
44 changed files with 2193 additions and 1452 deletions
|
@ -7,6 +7,12 @@
|
|||
#include <Vector3.h>
|
||||
#include <gl\gl.h>
|
||||
#include <gl\glu.h>
|
||||
#include "GLEnabledView.h"
|
||||
|
||||
#include "MapEdit.h"
|
||||
#include "MapEditDoc.h"
|
||||
#include "MapEditView.h"
|
||||
#include "MainFrm.h"
|
||||
|
||||
#include "Core.h"
|
||||
#include "Layer.h"
|
||||
|
@ -23,6 +29,7 @@ sLayerInfoTable CLayer::InfoTable[]=
|
|||
{LAYER_TYPE_TILE, LAYER_SUBTYPE_MID, "Mid", true, 2.0f, false, true, true, LAYER_SUBVIEW_TILEBANK,},
|
||||
{LAYER_TYPE_TILE, LAYER_SUBTYPE_ACTION, "Action", false, 1.0f, true, true, true, LAYER_SUBVIEW_TILEBANK,},
|
||||
{LAYER_TYPE_COLLISION, LAYER_SUBTYPE_NONE, "Collision", true, 1.0f, false, true, true, LAYER_SUBVIEW_TILEBANK,},
|
||||
{LAYER_TYPE_ITEM, LAYER_SUBTYPE_NONE, "Item", true, 1.0f, false, true, true, LAYER_SUBVIEW_TILEBANK,},
|
||||
};
|
||||
|
||||
int CLayer::InfoTableSize=sizeof(InfoTable)/sizeof(sLayerInfoTable);
|
||||
|
@ -63,3 +70,142 @@ int CLayer::GetLayerIdx(int Type,int SubType)
|
|||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CLayer::RenderGrid(CCore *Core,Vector3 &CamPos,bool Active)
|
||||
{
|
||||
Vector3 ThisCam=Core->OffsetCam(CamPos,GetScaleFactor());
|
||||
int MapWidth=GetWidth();
|
||||
int MapHeight=GetHeight();
|
||||
float ZoomW=Core->GetZoomW();
|
||||
float ZoomH=Core->GetZoomH();
|
||||
float ScrOfsX=(ZoomW/2);
|
||||
float ScrOfsY=(ZoomH/2);
|
||||
Vector3 &Scale=Core->GetScaleVector();
|
||||
float Col;
|
||||
const float OverVal=0.1f;
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glScalef(Scale.x,Scale.y,Scale.z);
|
||||
glTranslatef(-ThisCam.x,ThisCam.y,0);
|
||||
glTranslatef(-ScrOfsX,ScrOfsY,0); // Bring to top left corner
|
||||
|
||||
if (Active) Col=1; else Col=0.5f;
|
||||
|
||||
glBegin(GL_LINES);
|
||||
|
||||
glColor3f(Col,Col,Col);
|
||||
|
||||
for (int YLoop=0; YLoop<MapHeight+1; YLoop++)
|
||||
{
|
||||
glVertex3f( 0-OverVal, -YLoop+1, 0);
|
||||
glVertex3f( MapWidth+OverVal, -YLoop+1, 0);
|
||||
}
|
||||
|
||||
for (int XLoop=0; XLoop<MapWidth+1; XLoop++)
|
||||
{
|
||||
glVertex3f( XLoop, 0+1+OverVal, 0);
|
||||
glVertex3f( XLoop, -MapHeight+1-OverVal, 0);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void CLayer::FindCursorPos(CCore *Core,Vector3 &CamPos,CPoint &MousePos)
|
||||
{
|
||||
Vector3 ThisCam=Core->OffsetCam(CamPos,GetScaleFactor());
|
||||
int MapWidth=GetWidth();
|
||||
int MapHeight=GetHeight();
|
||||
float ZoomW=Core->GetZoomW();
|
||||
float ZoomH=Core->GetZoomH();
|
||||
float ScrOfsX=(ZoomW/2);
|
||||
float ScrOfsY=(ZoomH/2);
|
||||
Vector3 &Scale=Core->GetScaleVector();
|
||||
|
||||
GLint Viewport[4];
|
||||
GLuint SelectBuffer[SELECT_BUFFER_SIZE];
|
||||
int TileID=0;
|
||||
CPoint &CursorPos=Core->GetCursorPos();
|
||||
|
||||
int StartX=(int)ThisCam.x;
|
||||
int StartY=(int)ThisCam.y;
|
||||
float ShiftX=ThisCam.x - (int)ThisCam.x;
|
||||
float ShiftY=ThisCam.y - (int)ThisCam.y;
|
||||
|
||||
if (StartX<0) StartX=0;
|
||||
if (StartY<0) StartY=0;
|
||||
|
||||
int DrawW=ZoomW+8;
|
||||
int DrawH=ZoomH+8;
|
||||
|
||||
if (StartX+DrawW>MapWidth) DrawW=MapWidth-StartX;
|
||||
if (StartY+DrawH>MapHeight) DrawH=MapHeight-StartY;
|
||||
|
||||
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->GetView()->SetupPersMatrix();
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glScalef(Scale.x,Scale.y,Scale.z);
|
||||
// glTranslatef(-ThisCam.x,ThisCam.y,0);
|
||||
glTranslatef(-ShiftX,ShiftY,0);
|
||||
glTranslatef(-ScrOfsX,ScrOfsY,0); // Bring to top left corner
|
||||
|
||||
bool WrapMap=GetSubType()==LAYER_SUBTYPE_BACK;
|
||||
if (WrapMap)
|
||||
{
|
||||
DrawW=MapWidth;
|
||||
DrawH=MapHeight;
|
||||
}
|
||||
|
||||
for (int YLoop=0; YLoop<DrawH; YLoop++)
|
||||
{
|
||||
for (int XLoop=0; XLoop<DrawW; XLoop++)
|
||||
{
|
||||
int XPos=StartX+XLoop;
|
||||
int YPos=StartY+YLoop;
|
||||
if (WrapMap)
|
||||
{
|
||||
XPos%=MapWidth;
|
||||
YPos%=MapHeight;
|
||||
}
|
||||
|
||||
TileID=(XPos)+(((YPos)*MapWidth));
|
||||
glLoadName (TileID);
|
||||
glBegin (GL_QUADS);
|
||||
BuildGLQuad(XLoop,XLoop+1,-YLoop,-YLoop+1,0);
|
||||
glEnd();
|
||||
TileID++;
|
||||
}
|
||||
}
|
||||
|
||||
TileID= glRenderMode (GL_RENDER);
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
CursorPos.x=CursorPos.y=-1;
|
||||
|
||||
// Process hits
|
||||
|
||||
GLuint *HitPtr=SelectBuffer;
|
||||
|
||||
if (TileID) // Just take 1st
|
||||
{
|
||||
int HitID=HitPtr[3];
|
||||
CursorPos=IDToPoint(HitID,MapWidth);
|
||||
}
|
||||
glMatrixMode(GL_MODELVIEW); // <-- Prevent arse GL assert
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue