-
Notifications
You must be signed in to change notification settings - Fork 0
/
DebugDraw.cpp
88 lines (78 loc) · 3 KB
/
DebugDraw.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* Survival
*
* Copyright (C) 2009-2011 Vishesh Handa <me@vhanda.in>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "DebugDraw.h"
#include <iostream>
#include "World.h"
#include "Camera.h"
DebugDraw::DebugDraw()
{
//ctor
//std::cout << "Constructor - DebugDraw" << std::endl;
//uint32 flags = b2DebugDraw::e_shapeBit;
//SetFlags(flags);
}
DebugDraw::~DebugDraw()
{
//std::cout << "Destructor - DebugDraw" << std::endl;
}
void DebugDraw::DrawPolygon (const b2Vec2 *vertices, int32 vertexCount, const b2Color &color)
{
SDL_Surface * screen = SDL_GetVideoSurface();
SDL_Rect r = Camera::getInstance()->getRect();
for(int i=0; i < vertexCount; i++)
{
int k = (i == vertexCount-1) ? 0 : i+1;
lineRGBA( screen, vertices[i].x*World::ratio -r.x,
vertices[i].y*World::ratio -r.y,
vertices[k].x*World::ratio -r.x,
vertices[k].y*World::ratio -r.y,
0, 255, 0, 255 );
}
//std::cout << "Drew Polygon" << std::endl;
}
void DebugDraw::DrawSolidPolygon (const b2Vec2 *vertices, int32 vertexCount, const b2Color &color)
{
DrawPolygon( vertices, vertexCount, color);
//std::cout << "Drew Solid Polygon" << std::endl;
}
void DebugDraw::DrawSegment(const b2Vec2 &p1, const b2Vec2 &p2, const b2Color &color)
{
//std::cout << "Drawing Segment" << std::endl;
lineRGBA( SDL_GetVideoSurface(), p1.x*World::ratio, p1.y*World::ratio,
p2.x*World::ratio, p2.y*World::ratio,
0, 0, 255, 255);
}
void DebugDraw::DrawCircle (const b2Vec2 ¢er, float32 radius, const b2Color &color)
{
SDL_Rect r = Camera::getInstance()->getRect();
circleRGBA( SDL_GetVideoSurface(), center.x*World::ratio -r.x, center.y*World::ratio -r.y,
radius*World::ratio, 0, 0, 0, 255);
//std::cout << "Drawing Solid Circle" << std::endl;*/
}
void DebugDraw::DrawSolidCircle (const b2Vec2 ¢er, float32 radius, const b2Vec2 &axis,const b2Color &color)
{
SDL_Rect r = Camera::getInstance()->getRect();
circleRGBA( SDL_GetVideoSurface(), center.x*World::ratio -r.x, center.y*World::ratio -r.y,
radius*World::ratio, 0, 0, 0, 255);
}
void DebugDraw::DrawXForm (const b2XForm &xf)
{
//std::cout << "Drawing XForm" << std::endl;
}