Mercurial > fife-parpg
comparison engine/core/view/renderers/quadtreerenderer.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 "quadtreerenderer.h" | |
40 #include "model/structures/instancetree.h" | |
41 #include "util/structures/quadtree.h" | |
42 | |
43 ///credit to phoku for his NodeDisplay example which the visitor code is adapted from ( he coded the quadtree after all ) | |
44 namespace FIFE { | |
45 static Logger _log(LM_VIEWVIEW); | |
46 | |
47 QuadTreeRenderer::QuadTreeRenderer(RenderBackend* renderbackend, int position): | |
48 RendererBase(renderbackend, position) { | |
49 setEnabled(false); | |
50 } | |
51 | |
52 QuadTreeRenderer::QuadTreeRenderer(const QuadTreeRenderer& old): | |
53 RendererBase(old) { | |
54 setEnabled(false); | |
55 } | |
56 | |
57 RendererBase* QuadTreeRenderer::clone() { | |
58 return new QuadTreeRenderer(*this); | |
59 } | |
60 | |
61 QuadTreeRenderer::~QuadTreeRenderer() { } | |
62 RenderVisitor::RenderVisitor(RenderBackend * rb, Layer * layer, Camera *camera) { | |
63 | |
64 m_renderbackend = rb; | |
65 m_layer = layer; | |
66 m_camera = camera; | |
67 } | |
68 | |
69 RenderVisitor::~RenderVisitor() {} | |
70 | |
71 template<typename T> bool RenderVisitor::visit(QuadNode<T,2>* node, int d) { | |
72 | |
73 if (d==0) | |
74 visited = 0; | |
75 | |
76 int x = node->x(); | |
77 int y = node->y(); | |
78 int size = node->size(); | |
79 | |
80 ++visited; | |
81 CellGrid *cg = m_layer->getCellGrid(); ///we have checked for null pointer in quadtreerenderer::render().. no need to check again | |
82 | |
83 | |
84 ExactModelCoordinate emc= cg->toMapCoordinates(ExactModelCoordinate( x,y) );//0.5 for each cell's half-width | |
85 ScreenPoint scrpt1 =m_camera->toScreenCoordinates( emc ); | |
86 emc= cg->toMapCoordinates(ExactModelCoordinate( x,y+size) );// this size usage is wrong.. me thinks | |
87 ScreenPoint scrpt2 =m_camera->toScreenCoordinates( emc ); | |
88 emc= cg->toMapCoordinates(ExactModelCoordinate( x+size,y) ); | |
89 ScreenPoint scrpt3 =m_camera->toScreenCoordinates( emc ); | |
90 emc= cg->toMapCoordinates(ExactModelCoordinate( x+size,y+size) ); | |
91 ScreenPoint scrpt4 =m_camera->toScreenCoordinates( emc ); | |
92 | |
93 m_renderbackend->drawLine( Point(scrpt1.x,scrpt1.y) , Point(scrpt2.x,scrpt2.y), 255, 255, 255); | |
94 m_renderbackend->drawLine(Point(scrpt1.x,scrpt1.y), Point(scrpt3.x,scrpt3.y), 255, 255, 255); | |
95 m_renderbackend->drawLine(Point(scrpt3.x,scrpt3.y), Point(scrpt4.x,scrpt4.y), 255, 255, 255); | |
96 m_renderbackend->drawLine(Point(scrpt2.x,scrpt2.y), Point(scrpt4.x,scrpt4.y), 255, 255, 255); | |
97 | |
98 return true; | |
99 } | |
100 | |
101 | |
102 void QuadTreeRenderer::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances) { | |
103 CellGrid* cg = layer->getCellGrid(); | |
104 if (!cg) { | |
105 FL_WARN(_log, "No cellgrid assigned to layer, cannot draw grid"); | |
106 return; | |
107 } | |
108 InstanceTree * itree = layer->getInstanceTree(); | |
109 RenderVisitor VIPguess(m_renderbackend, layer,cam); | |
110 itree->applyVisitor(VIPguess); | |
111 } | |
112 | |
113 } | |
114 |