00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "video/renderbackend.h"
00031 #include "util/math/fife_math.h"
00032 #include "util/log/logger.h"
00033 #include "model/metamodel/grids/cellgrid.h"
00034 #include "model/structures/instance.h"
00035 #include "model/structures/layer.h"
00036 #include "model/structures/location.h"
00037
00038 #include "view/camera.h"
00039 #include "gridrenderer.h"
00040
00041
00042 namespace FIFE {
00043 static Logger _log(LM_VIEWVIEW);
00044
00045 GridRenderer::GridRenderer(RenderBackend* renderbackend, int position):
00046 RendererBase(renderbackend, position) {
00047 setEnabled(false);
00048 }
00049
00050 GridRenderer::GridRenderer(const GridRenderer& old):
00051 RendererBase(old) {
00052 setEnabled(false);
00053 }
00054
00055 RendererBase* GridRenderer::clone() {
00056 return new GridRenderer(*this);
00057 }
00058
00059 GridRenderer::~GridRenderer() {
00060 }
00061
00062 void GridRenderer::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances) {
00063 CellGrid* cg = layer->getCellGrid();
00064 if (!cg) {
00065 FL_WARN(_log, "No cellgrid assigned to layer, cannot draw grid");
00066 return;
00067 }
00068
00069
00070
00071
00072
00073
00074
00075
00076 Point a,b,c,d;
00077
00078
00079 ScreenPoint copt1 =cam->toScreenCoordinates(ExactModelCoordinate(1,1,1) );
00080 ScreenPoint copt2 =cam->toScreenCoordinates(ExactModelCoordinate(1,-1,1) );
00081 Point coptt1(copt1.x,copt1.y);
00082 Point coptt2(copt2.x,copt2.y);
00083 m_renderbackend->drawLine(coptt1,coptt2 ,15, 15, 200);
00084 a = coptt1;
00085
00086 copt1 =cam->toScreenCoordinates(ExactModelCoordinate(1,-1,1) );
00087 copt2 =cam->toScreenCoordinates(ExactModelCoordinate(-1,-1,1) );
00088 coptt1 = Point(copt1.x,copt1.y);
00089 coptt2 = Point(copt2.x,copt2.y);
00090 m_renderbackend->drawLine(coptt1,coptt2 ,15, 15, 200);
00091 b = coptt1;
00092
00093 copt1 =cam->toScreenCoordinates(ExactModelCoordinate(-1,-1,1) );
00094 copt2 =cam->toScreenCoordinates(ExactModelCoordinate(-1,1,1) );
00095 coptt1 = Point(copt1.x,copt1.y);
00096 coptt2 = Point(copt2.x,copt2.y);
00097 m_renderbackend->drawLine(coptt1,coptt2 ,15, 15, 200);
00098 c = coptt1;
00099
00100 copt1 =cam->toScreenCoordinates(ExactModelCoordinate(-1,1,1) );
00101 copt2 =cam->toScreenCoordinates(ExactModelCoordinate(1,1,1) );
00102 coptt1 = Point(copt1.x,copt1.y);
00103 coptt2 = Point(copt2.x,copt2.y);
00104 m_renderbackend->drawLine(coptt1,coptt2 ,15, 15, 20);
00105 d = coptt1;
00106
00107 m_renderbackend->drawQuad(a,b,c,d,15, 15, 200);
00108
00109
00110
00111 copt1 =cam->toScreenCoordinates(ExactModelCoordinate(-1,-1,-1) );
00112 copt2 =cam->toScreenCoordinates(ExactModelCoordinate(-1,1,-1) );
00113 coptt1 = Point(copt1.x,copt1.y);
00114 coptt2 = Point(copt2.x,copt2.y);
00115 m_renderbackend->drawLine(coptt1,coptt2 ,200, 200, 200);
00116
00117 copt1 =cam->toScreenCoordinates(ExactModelCoordinate(-1,1,-1) );
00118 copt2 =cam->toScreenCoordinates(ExactModelCoordinate(1,1,-1) );
00119 coptt1 = Point(copt1.x,copt1.y);
00120 coptt2 = Point(copt2.x,copt2.y);
00121 m_renderbackend->drawLine(coptt1,coptt2 ,200, 200, 200);
00122
00123 copt1 =cam->toScreenCoordinates(ExactModelCoordinate(1,1,-1) );
00124 copt2 =cam->toScreenCoordinates(ExactModelCoordinate(1,-1,-1) );
00125 coptt1 = Point(copt1.x,copt1.y);
00126 coptt2 = Point(copt2.x,copt2.y);
00127 m_renderbackend->drawLine(coptt1,coptt2 ,200, 200, 200);
00128
00129 copt1 =cam->toScreenCoordinates(ExactModelCoordinate(1,-1,-1) );
00130 copt2 =cam->toScreenCoordinates(ExactModelCoordinate(-1,-1,-1) );
00131 coptt1 = Point(copt1.x,copt1.y);
00132 coptt2 = Point(copt2.x,copt2.y);
00133 m_renderbackend->drawLine(coptt1,coptt2 ,200, 200, 200);
00134
00135
00136 Rect cv = cam->getViewPort();
00137 std::vector<Instance*>::const_iterator instance_it = instances.begin();
00138 for (;instance_it != instances.end(); ++instance_it) {
00139 Instance* instance = *instance_it;
00140 std::vector<ExactModelCoordinate> vertices;
00141 cg->getVertices(vertices, instance->getLocationRef().getLayerCoordinates());
00142 std::vector<ExactModelCoordinate>::const_iterator it = vertices.begin();
00143 ScreenPoint firstpt = cam->toScreenCoordinates(cg->toMapCoordinates(*it));
00144 Point pt1(firstpt.x, firstpt.y);
00145 Point pt2;
00146 ++it;
00147 for (; it != vertices.end(); it++) {
00148 ScreenPoint pts = cam->toScreenCoordinates(cg->toMapCoordinates(*it));
00149 pt2.x = pts.x; pt2.y = pts.y;
00150 Point cpt1 = pt1;
00151 Point cpt2 = pt2;
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175 m_renderbackend->drawLine(cpt1, cpt2, 0, 255, 0);
00176 pt1 = pt2;
00177 }
00178 m_renderbackend->drawLine(pt2, Point(firstpt.x, firstpt.y), 0, 255, 0);
00179 }
00180 }
00181 }