~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/box2d/Testbed/Tests/ShapeEditing.h

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
* Copyright (c) 2008-2009 Erin Catto http://www.box2d.org
 
3
*
 
4
* This software is provided 'as-is', without any express or implied
 
5
* warranty.  In no event will the authors be held liable for any damages
 
6
* arising from the use of this software.
 
7
* Permission is granted to anyone to use this software for any purpose,
 
8
* including commercial applications, and to alter it and redistribute it
 
9
* freely, subject to the following restrictions:
 
10
* 1. The origin of this software must not be misrepresented; you must not
 
11
* claim that you wrote the original software. If you use this software
 
12
* in a product, an acknowledgment in the product documentation would be
 
13
* appreciated but is not required.
 
14
* 2. Altered source versions must be plainly marked as such, and must not be
 
15
* misrepresented as being the original software.
 
16
* 3. This notice may not be removed or altered from any source distribution.
 
17
*/
 
18
 
 
19
#ifndef SHAPE_EDITING_H
 
20
#define SHAPE_EDITING_H
 
21
 
 
22
class ShapeEditing : public Test
 
23
{
 
24
public:
 
25
 
 
26
        ShapeEditing()
 
27
        {
 
28
                {
 
29
                        b2BodyDef bd;
 
30
                        b2Body* ground = m_world->CreateBody(&bd);
 
31
 
 
32
                        b2EdgeShape shape;
 
33
                        shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));
 
34
                        ground->CreateFixture(&shape, 0.0f);
 
35
                }
 
36
 
 
37
                b2BodyDef bd;
 
38
                bd.type = b2_dynamicBody;
 
39
                bd.position.Set(0.0f, 10.0f);
 
40
                m_body = m_world->CreateBody(&bd);
 
41
 
 
42
                b2PolygonShape shape;
 
43
                shape.SetAsBox(4.0f, 4.0f, b2Vec2(0.0f, 0.0f), 0.0f);
 
44
                m_fixture1 = m_body->CreateFixture(&shape, 10.0f);
 
45
 
 
46
                m_fixture2 = NULL;
 
47
 
 
48
                m_sensor = false;
 
49
        }
 
50
 
 
51
        void Keyboard(unsigned char key)
 
52
        {
 
53
                switch (key)
 
54
                {
 
55
                case 'c':
 
56
                        if (m_fixture2 == NULL)
 
57
                        {
 
58
                                b2CircleShape shape;
 
59
                                shape.m_radius = 3.0f;
 
60
                                shape.m_p.Set(0.5f, -4.0f);
 
61
                                m_fixture2 = m_body->CreateFixture(&shape, 10.0f);
 
62
                                m_body->SetAwake(true);
 
63
                        }
 
64
                        break;
 
65
 
 
66
                case 'd':
 
67
                        if (m_fixture2 != NULL)
 
68
                        {
 
69
                                m_body->DestroyFixture(m_fixture2);
 
70
                                m_fixture2 = NULL;
 
71
                                m_body->SetAwake(true);
 
72
                        }
 
73
                        break;
 
74
 
 
75
                case 's':
 
76
                        if (m_fixture2 != NULL)
 
77
                        {
 
78
                                m_sensor = !m_sensor;
 
79
                                m_fixture2->SetSensor(m_sensor);
 
80
                        }
 
81
                        break;
 
82
                }
 
83
        }
 
84
 
 
85
        void Step(Settings* settings)
 
86
        {
 
87
                Test::Step(settings);
 
88
                m_debugDraw.DrawString(5, m_textLine, "Press: (c) create a shape, (d) destroy a shape.");
 
89
                m_textLine += 15;
 
90
                m_debugDraw.DrawString(5, m_textLine, "sensor = %d", m_sensor);
 
91
                m_textLine += 15;
 
92
        }
 
93
 
 
94
        static Test* Create()
 
95
        {
 
96
                return new ShapeEditing;
 
97
        }
 
98
 
 
99
        b2Body* m_body;
 
100
        b2Fixture* m_fixture1;
 
101
        b2Fixture* m_fixture2;
 
102
        bool m_sensor;
 
103
};
 
104
 
 
105
#endif