Mercurial > fife-parpg
comparison engine/core/view/renderers/gridrenderer.cpp @ 0:4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
author | mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 29 Jun 2008 18:44:17 +0000 |
parents | |
children | 90005975cdbb |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4a0efb7baf70 |
---|---|
1 /*************************************************************************** | |
2 * Copyright (C) 2005-2008 by the FIFE team * | |
3 * http://www.fifengine.de * | |
4 * This file is part of FIFE. * | |
5 * * | |
6 * FIFE is free software; you can redistribute it and/or modify * | |
7 * it under the terms of the GNU General Public License as published by * | |
8 * the Free Software Foundation; either version 2 of the License, or * | |
9 * (at your option) any later version. * | |
10 * * | |
11 * This program is distributed in the hope that it will be useful, * | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
14 * GNU General Public License for more details. * | |
15 * * | |
16 * You should have received a copy of the GNU General Public License * | |
17 * along with this program; if not, write to the * | |
18 * Free Software Foundation, Inc., * | |
19 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * | |
20 ***************************************************************************/ | |
21 | |
22 // Standard C++ library includes | |
23 | |
24 // 3rd party library includes | |
25 | |
26 // FIFE includes | |
27 // These includes are split up in two parts, separated by one empty line | |
28 // First block: files included from the FIFE root src directory | |
29 // Second block: files included from the same folder | |
30 #include "video/renderbackend.h" | |
31 #include "util/math/fife_math.h" | |
32 #include "util/log/logger.h" | |
33 #include "model/metamodel/grids/cellgrid.h" | |
34 #include "model/structures/instance.h" | |
35 #include "model/structures/layer.h" | |
36 #include "model/structures/location.h" | |
37 | |
38 #include "view/camera.h" | |
39 #include "gridrenderer.h" | |
40 | |
41 | |
42 namespace FIFE { | |
43 static Logger _log(LM_VIEWVIEW); | |
44 | |
45 GridRenderer::GridRenderer(RenderBackend* renderbackend, int position): | |
46 RendererBase(renderbackend, position) { | |
47 setEnabled(false); | |
48 } | |
49 | |
50 GridRenderer::GridRenderer(const GridRenderer& old): | |
51 RendererBase(old) { | |
52 setEnabled(false); | |
53 } | |
54 | |
55 RendererBase* GridRenderer::clone() { | |
56 return new GridRenderer(*this); | |
57 } | |
58 | |
59 GridRenderer::~GridRenderer() { | |
60 } | |
61 | |
62 void GridRenderer::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances) { | |
63 CellGrid* cg = layer->getCellGrid(); | |
64 if (!cg) { | |
65 FL_WARN(_log, "No cellgrid assigned to layer, cannot draw grid"); | |
66 return; | |
67 } | |
68 // | |
69 // | |
70 // //render elev_coord box | |
71 // //draw front quad | |
72 // // 1,1,1 | |
73 // //1,-1,1 | |
74 // //-1,-1,1 | |
75 // //-1,1,1 | |
76 Point a,b,c,d; | |
77 | |
78 | |
79 ScreenPoint copt1 =cam->toScreenCoordinates(ExactModelCoordinate(1,1,1) ); | |
80 ScreenPoint copt2 =cam->toScreenCoordinates(ExactModelCoordinate(1,-1,1) ); | |
81 Point coptt1(copt1.x,copt1.y); | |
82 Point coptt2(copt2.x,copt2.y); | |
83 m_renderbackend->drawLine(coptt1,coptt2 ,15, 15, 200); | |
84 a = coptt1; | |
85 | |
86 copt1 =cam->toScreenCoordinates(ExactModelCoordinate(1,-1,1) ); | |
87 copt2 =cam->toScreenCoordinates(ExactModelCoordinate(-1,-1,1) ); | |
88 coptt1 = Point(copt1.x,copt1.y); | |
89 coptt2 = Point(copt2.x,copt2.y); | |
90 m_renderbackend->drawLine(coptt1,coptt2 ,15, 15, 200); | |
91 b = coptt1; | |
92 | |
93 copt1 =cam->toScreenCoordinates(ExactModelCoordinate(-1,-1,1) ); | |
94 copt2 =cam->toScreenCoordinates(ExactModelCoordinate(-1,1,1) ); | |
95 coptt1 = Point(copt1.x,copt1.y); | |
96 coptt2 = Point(copt2.x,copt2.y); | |
97 m_renderbackend->drawLine(coptt1,coptt2 ,15, 15, 200); | |
98 c = coptt1; | |
99 | |
100 copt1 =cam->toScreenCoordinates(ExactModelCoordinate(-1,1,1) ); | |
101 copt2 =cam->toScreenCoordinates(ExactModelCoordinate(1,1,1) ); | |
102 coptt1 = Point(copt1.x,copt1.y); | |
103 coptt2 = Point(copt2.x,copt2.y); | |
104 m_renderbackend->drawLine(coptt1,coptt2 ,15, 15, 20); | |
105 d = coptt1; | |
106 | |
107 m_renderbackend->drawQuad(a,b,c,d,15, 15, 200); | |
108 // | |
109 // | |
110 // //draw back quad | |
111 copt1 =cam->toScreenCoordinates(ExactModelCoordinate(-1,-1,-1) ); | |
112 copt2 =cam->toScreenCoordinates(ExactModelCoordinate(-1,1,-1) ); | |
113 coptt1 = Point(copt1.x,copt1.y); | |
114 coptt2 = Point(copt2.x,copt2.y); | |
115 m_renderbackend->drawLine(coptt1,coptt2 ,200, 200, 200); | |
116 | |
117 copt1 =cam->toScreenCoordinates(ExactModelCoordinate(-1,1,-1) ); | |
118 copt2 =cam->toScreenCoordinates(ExactModelCoordinate(1,1,-1) ); | |
119 coptt1 = Point(copt1.x,copt1.y); | |
120 coptt2 = Point(copt2.x,copt2.y); | |
121 m_renderbackend->drawLine(coptt1,coptt2 ,200, 200, 200); | |
122 | |
123 copt1 =cam->toScreenCoordinates(ExactModelCoordinate(1,1,-1) ); | |
124 copt2 =cam->toScreenCoordinates(ExactModelCoordinate(1,-1,-1) ); | |
125 coptt1 = Point(copt1.x,copt1.y); | |
126 coptt2 = Point(copt2.x,copt2.y); | |
127 m_renderbackend->drawLine(coptt1,coptt2 ,200, 200, 200); | |
128 | |
129 copt1 =cam->toScreenCoordinates(ExactModelCoordinate(1,-1,-1) ); | |
130 copt2 =cam->toScreenCoordinates(ExactModelCoordinate(-1,-1,-1) ); | |
131 coptt1 = Point(copt1.x,copt1.y); | |
132 coptt2 = Point(copt2.x,copt2.y); | |
133 m_renderbackend->drawLine(coptt1,coptt2 ,200, 200, 200); | |
134 | |
135 | |
136 Rect cv = cam->getViewPort(); | |
137 std::vector<Instance*>::const_iterator instance_it = instances.begin(); | |
138 for (;instance_it != instances.end(); ++instance_it) { | |
139 Instance* instance = *instance_it; | |
140 std::vector<ExactModelCoordinate> vertices; | |
141 cg->getVertices(vertices, instance->getLocationRef().getLayerCoordinates()); | |
142 std::vector<ExactModelCoordinate>::const_iterator it = vertices.begin(); | |
143 ScreenPoint firstpt = cam->toScreenCoordinates(cg->toMapCoordinates(*it)); | |
144 Point pt1(firstpt.x, firstpt.y); | |
145 Point pt2; | |
146 ++it; | |
147 for (; it != vertices.end(); it++) { | |
148 ScreenPoint pts = cam->toScreenCoordinates(cg->toMapCoordinates(*it)); | |
149 pt2.x = pts.x; pt2.y = pts.y; | |
150 Point cpt1 = pt1; | |
151 Point cpt2 = pt2; | |
152 /* FIXME: limit grid drawing to current camera view port | |
153 code below does not do it, but may act as a starting point | |
154 | |
155 int cvx2 = cv.x+cv.w; | |
156 int cvy2 = cv.y+cv.h; | |
157 | |
158 if (((pt1.x < cv.x) && (pt2.x < cv.x)) || | |
159 ((pt1.x > cvx2) && (pt2.x > cvx2)) || | |
160 ((pt1.y < cv.y) && (pt2.y < cv.y)) || | |
161 ((pt1.y > cvy2) && (pt2.y > cvy2))) { | |
162 pt1 = pt2; | |
163 continue; | |
164 } | |
165 | |
166 if (cpt1.x < cv.x) cpt1.x = cv.x; | |
167 if (cpt2.x < cv.x) cpt2.x = cv.x; | |
168 if (cpt1.y < cv.y) cpt1.y = cv.y; | |
169 if (cpt2.y < cv.y) cpt2.y = cv.y; | |
170 if (cpt1.x > cvx2) cpt1.x = cvx2; | |
171 if (cpt2.x > cvx2) cpt2.x = cvx2; | |
172 if (cpt1.y > cvy2) cpt1.y = cvy2; | |
173 if (cpt2.y > cvy2) cpt2.y = cvy2; | |
174 */ | |
175 m_renderbackend->drawLine(cpt1, cpt2, 0, 255, 0); | |
176 pt1 = pt2; | |
177 } | |
178 m_renderbackend->drawLine(pt2, Point(firstpt.x, firstpt.y), 0, 255, 0); | |
179 } | |
180 } | |
181 } |