📄 missionareaeditor.cc
字号:
Point3F terrOffset = -terrPos;
terrOffset.convolve(mScale);
//
mCenterPos.set(terrOffset.x + F32(offset.x), terrOffset.y + F32(offset.y));
}
//------------------------------------------------------------------------------
static void findObjectsCallback(SceneObject* obj, void * val)
{
Vector<SceneObject*> * list = (Vector<SceneObject*>*)val;
list->push_back(obj);
}
void MissionAreaEditor::onRender(Point2I offset, const RectI & updateRect)
{
RectI rect = updateRect;
setUpdate();
// draw an x
if(!bool(mMissionArea) || !bool(mTerrainBlock))
{
glBegin(GL_LINES);
glColor3f(0,0,0);
glVertex2f(rect.point.x, updateRect.point.y);
glVertex2f(rect.point.x + updateRect.extent.x, updateRect.point.y + updateRect.extent.y);
glVertex2f(rect.point.x, updateRect.point.y + updateRect.extent.y);
glVertex2f(rect.point.x + updateRect.extent.x, updateRect.point.y);
return;
}
//
setupScreenTransform(offset);
// draw the terrain
if(mSquareBitmap)
rect.extent.x > rect.extent.y ? rect.extent.x = rect.extent.y : rect.extent.y = rect.extent.x;
dglSetClipRect(rect);
dglClearBitmapModulation();
dglDrawBitmapStretch(mTextureHandle, rect);
// draw all the objects
Vector<SceneObject*> objects;
U32 mask = InteriorObjectType | PlayerObjectType | VehicleObjectType | StaticShapeObjectType | WaterObjectType | TriggerObjectType;
gServerContainer.findObjects(mask, findObjectsCallback, &objects);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBegin(GL_QUADS);
// project 'em
for(U32 i = 0; i < objects.size(); i++)
{
// get the color
if(objects[i]->getTypeMask() & WaterObjectType)
glColor4ub(mWaterObjectColor.red, mWaterObjectColor.green, mWaterObjectColor.blue, mWaterObjectColor.alpha);
else
glColor4ub(mDefaultObjectColor.red, mDefaultObjectColor.green, mDefaultObjectColor.blue, mDefaultObjectColor.alpha);
const Box3F & objBox = objects[i]->getObjBox();
const MatrixF & objTransform = objects[i]->getTransform();
const VectorF & objScale = objects[i]->getScale();
U32 numPlanes = 0;
PlaneF testPlanes[3];
U32 planeIndices[3];
U32 j;
for(j = 0; (j < 6) && (numPlanes < 3); j++)
{
PlaneF plane;
plane.x = BoxNormals[j].x;
plane.y = BoxNormals[j].y;
plane.z = BoxNormals[j].z;
if(j&1)
plane.d = (((const F32 *)objBox.min)[(j-1)>>1]);
else
plane.d = -(((const F32 *)objBox.max)[j>>1]);
//
mTransformPlane(objTransform, objScale, plane, &testPlanes[numPlanes]);
planeIndices[numPlanes] = j;
if(mDot(testPlanes[numPlanes], Point3F(0,0,1)) > 0.f)
numPlanes++;
}
// dump the polys
for(j = 0; j < numPlanes; j++)
{
for(U32 k = 0; k < 4; k++)
{
U32 vertIndex = BoxVerts[planeIndices[j]][k];
Point3F pnt;
pnt.set(BoxPnts[vertIndex].x ? objBox.max.x : objBox.min.x,
BoxPnts[vertIndex].y ? objBox.max.y : objBox.min.y,
BoxPnts[vertIndex].z ? objBox.max.z : objBox.min.z);
// scale it
pnt.convolve(objScale);
Point3F proj;
objTransform.mulP(pnt, &proj);
Point2F pos = worldToScreen(Point2F(proj.x, proj.y));
glVertex2f(pos.x, pos.y);
}
}
}
glEnd();
glDisable(GL_BLEND);
RectF area;
getScreenMissionArea(area);
// render the mission area box
glColor4ub(mMissionBoundsColor.red, mMissionBoundsColor.green, mMissionBoundsColor.blue, mMissionBoundsColor.alpha);
glBegin(GL_LINE_LOOP);
glVertex2f(area.point.x, area.point.y);
glVertex2f(area.point.x + area.extent.x, area.point.y);
glVertex2f(area.point.x + area.extent.x, area.point.y + area.extent.y);
glVertex2f(area.point.x, area.point.y + area.extent.y);
glEnd();
// render the handles
RectI iArea;
getScreenMissionArea(iArea);
if(mEnableEditing && !mEnableMirroring)
drawNuts(iArea);
// render the camera
if(mRenderCamera)
{
CameraQuery camera;
GameProcessCameraQuery(&camera);
// farplane too far, 90' looks wrong...
camera.fov = mDegToRad(60.f);
camera.farPlane = 500.f;
//
F32 rot = camera.fov / 2;
//
VectorF ray;
VectorF projRayA, projRayB;
ray.set(camera.farPlane * -mSin(rot), camera.farPlane * mCos(rot), 0);
camera.cameraMatrix.mulV(ray, &projRayA);
ray.set(camera.farPlane * -mSin(-rot), camera.farPlane * mCos(-rot), 0);
camera.cameraMatrix.mulV(ray, &projRayB);
Point3F camPos;
camera.cameraMatrix.getColumn(3, &camPos);
Point2F s = worldToScreen(Point2F(camPos.x, camPos.y));
Point2F e1 = worldToScreen(Point2F(camPos.x + projRayA.x, camPos.y + projRayA.y));
Point2F e2 = worldToScreen(Point2F(camPos.x + projRayB.x, camPos.y + projRayB.y));
glColor4ub(mCameraColor.red, mCameraColor.green, mCameraColor.blue, mCameraColor.alpha);
glBegin(GL_LINES);
glVertex2f(s.x, s.y);
glVertex2f(e1.x, e1.y);
glVertex2f(s.x, s.y);
glVertex2f(e2.x, e2.y);
glEnd();
}
// draw the mirroring info
if(mEnableMirroring)
{
// mirror index is cw octant of source
static Point2F octPoints[] =
{
Point2F(0.5, 0.0),
Point2F(1.0, 0.0),
Point2F(1.0, 0.5),
Point2F(1.0, 1.0),
Point2F(0.5, 1.0),
Point2F(0.0, 1.0),
Point2F(0.0, 0.5),
Point2F(0.0, 0.0)
};
// render the line
glColor4ub(mMirrorLineColor.red, mMirrorLineColor.green, mMirrorLineColor.blue, mMirrorLineColor.alpha);
glBegin(GL_LINES);
glVertex2f(rect.point.x + octPoints[(mMirrorIndex+6)%8].x * rect.extent.x,
rect.point.y + octPoints[(mMirrorIndex+6)%8].y * rect.extent.y);
glVertex2f(rect.point.x + octPoints[(mMirrorIndex+2)%8].x * rect.extent.x,
rect.point.y + octPoints[(mMirrorIndex+2)%8].y * rect.extent.y);
glEnd();
// render the arrow
static Point2F arrow[8] = // points up
{
Point2F(-0.375, 0),
Point2F(0, -0.375),
Point2F(0.375, 0),
Point2F(0.125, 0),
Point2F(0.125, 0.375),
Point2F(-0.125, 0.375),
Point2F(-0.125, 0),
Point2F(-0.375, 0)
};
static U32 arrow_tri[15] = // triangle verts
{
0, 1, 6,
6, 1, 3,
3, 1, 2,
6, 3, 5,
3, 4, 5
};
// rotate cw
F32 angle = -(M_PI * ((mMirrorIndex+6) % 8) / 4);
F32 sin = mCos(angle);
F32 cos = mSin(angle);
// rotate points..
Point2F pnts[8];
U32 i;
for(i = 0; i < 8; i++)
{
pnts[i].x = arrow[i].x * cos - arrow[i].y * sin;
pnts[i].y = arrow[i].x * sin + arrow[i].y * cos;
}
// draw it
glColor4ub(mMirrorArrowColor.red, mMirrorArrowColor.green, mMirrorArrowColor.blue, mMirrorArrowColor.alpha);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBegin(GL_TRIANGLES);
for(i = 0; i < 15; i++)
glVertex2f(rect.point.x + pnts[arrow_tri[i]].x * rect.extent.x + (rect.extent.x / 2),
rect.point.y + pnts[arrow_tri[i]].y * rect.extent.y + (rect.extent.y / 2));
glEnd();
// opaque
glColor4ub(mMirrorArrowColor.red, mMirrorArrowColor.green, mMirrorArrowColor.blue, 0xff);
glBegin(GL_LINE_STRIP);
for(i = 0; i < 8; i++)
glVertex2f(rect.point.x + pnts[i].x * rect.extent.x + (rect.extent.x / 2),
rect.point.y + pnts[i].y * rect.extent.y + (rect.extent.y / 2));
glEnd();
glDisable(GL_BLEND);
}
#ifdef TGE_RPG /// TGE_Map
if(bool(mProfile->mFont))
{
GameConnection * connection = GameConnection::getLocalClientConnection();
ShapeBase * obj = 0;
if(connection)
obj = connection->getControlObject();
if(obj)
{
Point3F pos = obj->getPosition();
char buffer[64];
dSprintf(buffer,64,"%2.0f,%2.0f",mFloor(pos.x),mFloor(pos.y) );
static ColorI clr(255,255,255,255);
dglDrawText(mProfile->mFont,offset,buffer,&clr);
}
}
#endif
renderChildControls(offset, updateRect);
}
//------------------------------------------------------------------------------
// sometimes you feel like a.....
bool MissionAreaEditor::inNut(const Point2I & pt, S32 x, S32 y)
{
S32 dx = pt.x - x;
S32 dy = pt.y - y;
return dx <= NUT_SIZE && dx >= -NUT_SIZE && dy <= NUT_SIZE && dy >= -NUT_SIZE;
}
S32 MissionAreaEditor::getSizingHitKnobs(const Point2I & pt, const RectI & box)
{
if(!mEnableEditing || mEnableMirroring)
return(nothing);
S32 lx = box.point.x, rx = box.point.x + box.extent.x - 1;
S32 cx = (lx + rx) >> 1;
S32 ty = box.point.y, by = box.point.y + box.extent.y - 1;
S32 cy = (ty + by) >> 1;
if (inNut(pt, lx, ty))
return sizingLeft | sizingTop;
if (inNut(pt, cx, ty))
return sizingTop;
if (inNut(pt, rx, ty))
return sizingRight | sizingTop;
if (inNut(pt, lx, by))
return sizingLeft | sizingBottom;
if (inNut(pt, cx, by))
return sizingBottom;
if (inNut(pt, rx, by))
return sizingRight | sizingBottom;
if (inNut(pt, lx, cy))
return sizingLeft;
if (inNut(pt, rx, cy))
return sizingRight;
if(pt.x >= box.point.x && pt.x < box.point.x + box.extent.x &&
pt.y >= box.point.y && pt.y < box.point.y + box.extent.y)
return(moving);
return nothing;
}
void MissionAreaEditor::drawNut(const Point2I & nut)
{
RectI r(nut.x - NUT_SIZE, nut.y - NUT_SIZE, 2 * NUT_SIZE + 1, 2 * NUT_SIZE + 1);
dglDrawRect(r, mHandleFrameColor);
r.point += Point2I(1, 1);
r.extent -= Point2I(1, 1);
dglDrawRectFill(r, mHandleFillColor);
}
void MissionAreaEditor::drawNuts(RectI & box)
{
S32 lx = box.point.x, rx = box.point.x + box.extent.x - 1;
S32 cx = (lx + rx) >> 1;
S32 ty = box.point.y, by = box.point.y + box.extent.y - 1;
S32 cy = (ty + by) >> 1;
drawNut(Point2I(lx, ty));
drawNut(Point2I(lx, cy));
drawNut(Point2I(lx, by));
drawNut(Point2I(rx, ty));
drawNut(Point2I(rx, cy));
drawNut(Point2I(rx, by));
drawNut(Point2I(cx, ty));
drawNut(Point2I(cx, by));
}
//------------------------------------------------------------------------------
void MissionAreaEditor::updateCursor(S32 hit)
{
if(hit)
{
if(hit == sizingTop || hit == sizingBottom)
setCursor(VertResizeCursor);
else if(hit == sizingLeft || hit == sizingRight)
setCursor(HorizResizeCursor);
else if(hit & sizingTop)
{
if(hit & sizingLeft)
setCursor(DiagLeftResizeCursor);
else
setCursor(DiagRightResizeCursor);
}
else if(hit & sizingBottom)
{
if(hit & sizingLeft)
setCursor(DiagRightResizeCursor);
else
setCursor(DiagLeftResizeCursor);
}
else if(hit == moving)
setCursor(HandCursor);
}
else
setCursor(DefaultCursor);
}
//------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -