source: trunk/test/btphystest.cpp @ 2879

Last change on this file since 2879 was 2879, checked in by touky, 6 years ago

btPhysTest : Added a new test mode called "CAT_MODE". Try it out at your own risks.

  • Property svn:eol-style set to LF
File size: 20.7 KB
RevLine 
[2816]1//
2// BtPhysTest
3//
4// Copyright: (c) 2009-2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com>
5//            (c) 2012-2013 Sam Hocevar <sam@hocevar.net>
6//
7
8#if defined HAVE_CONFIG_H
9#   include "config.h"
10#endif
11
12#include "core.h"
13#include "loldebug.h"
14
15using namespace lol;
16
17#ifndef HAVE_PHYS_USE_BULLET
18#define HAVE_PHYS_USE_BULLET
19#endif /* HAVE_PHYS_USE_BULLET */
20
21#include "physics/lolphysics.h"
22#include "physics/easyphysics.h"
[2879]23
24#define CAT_MODE        0
25#define OBJ_SIZE        2.f
[2816]26#include "physicobject.h"
[2879]27
[2816]28#include "btphystest.h"
29
30using namespace lol::phys;
31
32#define CUBE_HALF_EXTENTS .5f
33#define EXTRA_HEIGHT 1.f
[2879]34#define BASE_TIME 2.f
35#define ZERO_TIME (BASE_TIME + rand(-BASE_TIME * .4f, BASE_TIME * .4f))
36#define ZERO_SPEED 3.5f
37#define JUMP_HEIGHT 30.f
38#define JUMP_STRAFE .5f
[2816]39
40int gNumObjects = 64;
41
[2879]42#if CAT_MODE
[2816]43#define USE_WALL        1
[2879]44#define USE_BODIES      1
45#else
46#define USE_WALL        1
[2816]47#define USE_PLATFORM    1
48#define USE_ROPE        0
[2838]49#define USE_BODIES      1
[2816]50#define USE_ROTATION    0
[2879]51#define USE_CHARACTER   0
52#define USE_STAIRS      0
53#endif
[2816]54
[2879]55LOLFX_RESOURCE_DECLARE(front_camera_sprite);
56
[2816]57BtPhysTest::BtPhysTest(bool editor)
58{
59    m_loop_value = .0f;
60
[2879]61    g_renderer->SetAlphaFunc(AlphaFunc::Greater, 0.0);
62
63#if CAT_MODE
64    /* cat datas setup */
65    m_cat_texture = Tiler::Register("data/CatsSheet.png", ivec2(0), ivec2(0,1));
66#endif //CAT_MODE
67
[2838]68    /* Register an input controller for the keyboard */
69    m_controller = new Controller(KEY_MAX, 0);
70    m_controller->GetKey(KEY_MOVE_FORWARD).Bind("Keyboard", "Up");
71    m_controller->GetKey(KEY_MOVE_BACK).Bind("Keyboard", "Down");
72    m_controller->GetKey(KEY_MOVE_LEFT).Bind("Keyboard", "Left");
73    m_controller->GetKey(KEY_MOVE_RIGHT).Bind("Keyboard", "Right");
74    m_controller->GetKey(KEY_MOVE_JUMP).Bind("Keyboard", "Space");
75    m_controller->GetKey(KEY_MOVE_UP).Bind("Keyboard", "PageUp");
76    m_controller->GetKey(KEY_MOVE_DOWN).Bind("Keyboard", "PageDown");
77    m_controller->GetKey(KEY_QUIT).Bind("Keyboard", "Escape");
78
[2816]79    /* Create a camera that matches the settings of XNA BtPhysTest */
80    m_camera = new Camera();
[2879]81#if CAT_MODE
82    m_camera->SetView(vec3(70.f, 50.f, 0.f),
83                      vec3(0.f, 0.f, 0.f),
84                      vec3(0, 1, 0));
85    m_camera->SetProjection(mat4::perspective(60.f, 1280.f, 960.f, .1f, 1000.f));
86#else
[2816]87    m_camera->SetView(vec3(50.f, 50.f, 0.f),
88                      vec3(0.f, 0.f, 0.f),
89                      vec3(0, 1, 0));
90    m_camera->SetProjection(mat4::perspective(45.f, 1280.f, 960.f, .1f, 1000.f));
[2879]91#endif
[2816]92    g_scene->PushCamera(m_camera);
93
94    m_ready = false;
95
96    m_simulation = new Simulation();
97    m_simulation->SetWorldLimit(vec3(-1000.0f, -1000.0f, -1000.0f), vec3(1000.0f, 1000.0f, 1000.0f));
98    m_simulation->Init();
99    vec3 NewGravity = vec3(.0f, -10.0f, .0f);
100    m_simulation->SetGravity(NewGravity);
101    m_simulation->SetContinuousDetection(true);
102    m_simulation->SetTimestep(1.f / 120.f);
103    Ticker::Ref(m_simulation);
104
105    /* Add a white directional light */
106    m_light1 = new Light();
107    m_light1->SetPosition(vec4(0.2f, 0.2f, 0.f, 0.f));
108    m_light1->SetColor(vec4(0.5f, 0.5f, 0.5f, 1.f));
109    Ticker::Ref(m_light1);
110
111    /* Add an orangeish point light */
112    m_light2 = new Light();
113    m_light2->SetPosition(vec4(-15.f, 15.f, 15.f, 1.f));
114    m_light2->SetColor(vec4(0.4f, 0.3f, 0.2f, 1.f));
115    Ticker::Ref(m_light2);
116
117    float offset = 29.5f;
118    vec3 pos_offset = vec3(.0f, 30.f, .0f);
[2879]119#if USE_STAIRS
[2816]120    {
121        vec3 new_offset = vec3(1.0f, .125f, .0f);
122        quat NewRotation = quat::fromeuler_xyz(0.f, 0.f, 0.f);
123        vec3 NewPosition = pos_offset + vec3(5.0f, -29.f, 15.0f);
124        {
125            NewRotation = quat::fromeuler_xyz(0.f, 0.f, 30.f);
126            NewPosition += vec3(4.0f, .0f, -4.0f);
127
128            PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 3);
129            Ticker::Ref(NewPhyobj);
130            m_stairs_list << NewPhyobj;
131        }
132        {
133            NewRotation = quat::fromeuler_xyz(0.f, 0.f, 40.f);
134            NewPosition += vec3(4.0f, .0f, -4.0f);
135
136            PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 3);
137            Ticker::Ref(NewPhyobj);
138            m_stairs_list << NewPhyobj;
139        }
140        NewPosition = pos_offset + vec3(5.0f, -29.5f, 15.0f);
141        NewRotation = quat::fromeuler_xyz(0.f, 0.f, 0.f);
142        for (int i=0; i < 15; i++)
143        {
144            NewPosition += new_offset;
145
146            PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 3);
147            Ticker::Ref(NewPhyobj);
148            m_stairs_list << NewPhyobj;
149        }
150    }
[2879]151#endif //USE_STAIRS
[2816]152
[2879]153#if USE_WALL
[2816]154    {
155        for (int i=0; i < 6; i++)
156        {
157            vec3 NewPosition = vec3(.0f);
158            quat NewRotation = quat(1.f);
159
160            PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation);
161
162            int idx = i/2;
163            NewPosition = pos_offset;
164            NewPosition[idx] += offset;
165            offset *= -1.f;
166
167            if (idx != 1)
168            {
169                vec3 NewAxis = vec3(.0f);
170                NewAxis[2 - idx] = 1;
171                NewRotation = quat::rotate(90.f, NewAxis);
172            }
173
174            NewPhyobj->SetTransform(NewPosition, NewRotation);
175            Ticker::Ref(NewPhyobj);
176            m_ground_list << NewPhyobj;
177        }
178    }
[2879]179#endif //USE_WALL
[2816]180
181    PhysicsObject* BasePhyobj = NULL;
[2879]182#if USE_PLATFORM
[2816]183    {
184        quat NewRotation = quat::fromeuler_xyz(0.f, 0.f, 0.f);
185        vec3 NewPosition = pos_offset + vec3(5.0f, -25.0f, -15.0f);
186
187        PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1);
188
189        m_platform_list << NewPhyobj;
190        Ticker::Ref(NewPhyobj);
191
192        NewPosition = pos_offset + vec3(-15.0f, -25.0f, 5.0f);
193
194        NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1);
195        BasePhyobj = NewPhyobj;
196
197        m_platform_list << NewPhyobj;
198        Ticker::Ref(NewPhyobj);
199
200        NewRotation = quat::fromeuler_xyz(0.f, 0.f, 90.f);
201        NewPosition = pos_offset + vec3(-20.0f, -25.0f, 5.0f);
202
203        NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1);
204
205        NewPhyobj->GetPhysic()->AttachTo(BasePhyobj->GetPhysic(), true, true);
206        m_platform_list << NewPhyobj;
207        Ticker::Ref(NewPhyobj);
208
209        //NewPosition += vec3(-0.0f, .0f, .0f);
210        //NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1);
211
212        //NewPhyobj->GetPhysic()->AttachTo(BasePhyobj->GetPhysic(), true, false);
213        //m_platform_list << NewPhyobj;
214        //Ticker::Ref(NewPhyobj);
215
216        //NewPosition += vec3(-2.0f, .0f, .0f);
217        //NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1);
218
219        //NewPhyobj->GetPhysic()->AttachTo(BasePhyobj->GetPhysic(), false, false);
220        //m_platform_list << NewPhyobj;
221        //Ticker::Ref(NewPhyobj);
222    }
[2879]223#endif //USE_PLATFORM
[2816]224
[2879]225#if USE_CHARACTER
[2816]226    {
227        quat NewRotation = quat::fromeuler_xyz(0.f, 0.f, 0.f);
228        vec3 NewPosition = pos_offset + vec3(-5.0f, -10.0f, 15.0f);
229
230        PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 2);
231
232        m_character_list << NewPhyobj;
233        Ticker::Ref(NewPhyobj);
234
235        //NewPhyobj->GetCharacter()->AttachTo(BasePhyobj->GetPhysic(), true, true);
236    }
[2879]237#endif //USE_CHARACTER
[2816]238
[2879]239#if USE_BODIES
[2816]240    {
241        for (int x=0; x < 6; x++)
242        {
[2879]243            for (int y=0; y < 2; y++)
[2816]244            {
245                for (int z=0; z < 5; z++)
246                {
247                    PhysicsObject* new_physobj = new PhysicsObject(m_simulation, 1000.f,
248                        vec3(-20.f, 15.f, -20.f) +
249                        vec3(8.f * (float)x, 8.f * (float)y, 8.f * (float)z));
[2879]250                    m_physobj_list.Push(new_physobj, ZERO_TIME);
[2816]251                    Ticker::Ref(new_physobj);
252                }
253            }
254        }
255    }
[2879]256#endif //USE_BODIES
[2816]257
[2879]258#if USE_ROPE
[2816]259    {
260        Array<PhysicsObject*> RopeElements;
261        for (int i = 0; i < 14; i++)
262        {
263            PhysicsObject* new_physobj = new PhysicsObject(m_simulation, 1000.f,
264                vec3(0.f, 15.f, -20.f) +
265                vec3(0.f, 0.f, 2.f * (float)i), 1);
266            RopeElements << new_physobj;
[2879]267            m_physobj_list.Push(new_physobj, ZERO_TIME);
[2816]268            Ticker::Ref(new_physobj);
269            if (RopeElements.Count() > 1)
270            {
271                EasyConstraint* new_constraint = new EasyConstraint();
272
273                vec3 A2B = .5f * (RopeElements[i]->GetPhysic()->GetTransform().v3.xyz -
274                            RopeElements[i - 1]->GetPhysic()->GetTransform().v3.xyz);
275                new_constraint->SetPhysObjA(RopeElements[i - 1]->GetPhysic(), lol::mat4::translate(A2B));
276                new_constraint->SetPhysObjB(RopeElements[i]->GetPhysic(), lol::mat4::translate(-A2B));
277                new_constraint->InitConstraintToPoint2Point();
278                new_constraint->DisableCollisionBetweenObjs(true);
279                new_constraint->AddToSimulation(m_simulation);
280                m_constraint_list << new_constraint;
281            }
282        }
283    }
[2879]284#endif //USE_ROPE
[2816]285}
286
287void BtPhysTest::TickGame(float seconds)
288{
289    WorldEntity::TickGame(seconds);
290
[2838]291    if (m_controller->GetKey(KEY_QUIT).IsReleased())
[2816]292        Ticker::Shutdown();
293
294    m_loop_value += seconds;
295    if (m_loop_value > F_PI * 2.0f)
296        m_loop_value -= F_PI * 2.0f;
297
298    vec3 GroundBarycenter = vec3(.0f);
299    vec3 PhysObjBarycenter = vec3(.0f);
300    float factor = .0f;
[2879]301#if CAT_MODE
302#if USE_BODIES
303    vec3 cam_center(0.f);
304    float cam_factor = .0f;
305    vec2 screen_min_max[2] = { vec2(FLT_MAX), vec2(-FLT_MAX) };
306    vec3 cam_min_max[2] = { vec3(FLT_MAX), vec3(-FLT_MAX) };
307    mat4 world_cam = g_scene->GetCamera()->GetView();
308    mat4 cam_screen = g_scene->GetCamera()->GetProjection();
[2816]309
[2879]310    for (int i = 0; i < m_physobj_list.Count(); i++)
[2816]311    {
[2879]312        PhysicsObject* PhysObj = m_physobj_list[i].m1;
313        float &Timer = m_physobj_list[i].m2;
314
315        vec3 obj_loc = PhysObj->GetPhysic()->GetTransform().v3.xyz;
316
317        cam_center += obj_loc;
318        cam_factor += 1.f;
319
320        mat4 LocalPos = mat4::translate(obj_loc);
321        vec3 vpos;
322
323        LocalPos = world_cam * LocalPos;
324        vpos = LocalPos.v3.xyz;
325        cam_min_max[0] = min(vpos.xyz, cam_min_max[0]);
326        cam_min_max[1] = max(vpos.xyz, cam_min_max[1]);
327
328        LocalPos = cam_screen * LocalPos;
329        vpos = (LocalPos.v3 / LocalPos.v3.w).xyz;
330        screen_min_max[0] = min(vpos.xy, screen_min_max[0]);
331        screen_min_max[1] = max(vpos.xy, screen_min_max[1]);
332
333        //if (length(PhysObj->GetPhysic()->GetLinearVelocity()) < ZERO_SPEED)
334        if (lol::abs(PhysObj->GetPhysic()->GetLinearVelocity().y) < ZERO_SPEED)
335            Timer -= seconds;
336
337        if (Timer < .0f)
338        {
339            PhysObj->GetPhysic()->AddImpulse(JUMP_HEIGHT *
340                                             vec3(JUMP_STRAFE, 1.f, JUMP_STRAFE) *
341                                             vec3(rand(-1.f, 1.f), 1.0f, rand(-1.f, 1.f)) *
342                                             PhysObj->GetPhysic()->GetMass());
343            Timer = ZERO_TIME;
344        }
345    }
346
347    vec3 min_max_diff = (cam_min_max[1] - cam_min_max[0]);
348    float screen_size = max(max(lol::abs(min_max_diff.x), lol::abs(min_max_diff.y)),
349                        max(    lol::abs(min_max_diff.x), lol::abs(min_max_diff.y)));
350    float fov_ratio = max(max(lol::abs(screen_min_max[0].x), lol::abs(screen_min_max[0].y)),
351                          max(lol::abs(screen_min_max[1].x), lol::abs(screen_min_max[1].y)));
352
353    //m_camera->SetProjection(mat4::perspective(30.f * fov_ratio * 1.1f, 1280.f, 960.f, .1f, 1000.f));
354    m_camera->SetView((mat4::rotate(10.f * seconds, vec3(.0f, 1.f, .0f)) * vec4(m_camera->GetPosition(), 1.0f)).xyz,
355                      //vec3(70.f, 30.f, 0.f),
356                      cam_center / cam_factor, vec3(0, 1, 0));
357#endif //USE_BODIES
358#endif //CAT_MODE
359
360#if USE_WALL
361    {
[2816]362        for (int i = 0; i < m_ground_list.Count(); i++)
363        {
364            PhysicsObject* PhysObj = m_ground_list[i];
365            mat4 GroundMat = PhysObj->GetTransform();
366
367            GroundBarycenter += GroundMat.v3.xyz;
368            factor += 1.f;
369        }
370
371        GroundBarycenter /= factor;
372
373        for (int i = 0; i < m_ground_list.Count(); i++)
374        {
375            PhysicsObject* PhysObj = m_ground_list[i];
376
377            mat4 GroundMat = PhysObj->GetTransform();
378            vec3 CenterToGround = GroundMat.v3.xyz - GroundBarycenter;
379            vec3 CenterToCam = m_camera->GetPosition() - GroundBarycenter;
380
381            if (dot(normalize(CenterToCam - CenterToGround),
382                    normalize(CenterToGround)) > 0.f)
383                PhysObj->SetRender(false);
384            else
385                PhysObj->SetRender(true);
386        }
387    }
[2879]388#endif //USE_WALL
[2816]389
[2879]390#if USE_ROTATION
[2816]391    {
392        for (int i = 0; i < m_ground_list.Count(); i++)
393        {
394            PhysicsObject* PhysObj = m_ground_list[i];
395
396            mat4 GroundMat = PhysObj->GetTransform();
397            mat4 CenterMx = mat4::translate(GroundBarycenter);
398            GroundMat = inverse(CenterMx) * GroundMat;
399            GroundMat = CenterMx *
400                        mat4(quat::fromeuler_xyz(vec3(.0f, 20.f, 20.0f) * seconds))
401                        * GroundMat;
402            PhysObj->SetTransform(GroundMat.v3.xyz, quat(GroundMat));
403        }
404    }
[2879]405#endif //USE_ROTATION
[2816]406
[2879]407#if USE_PLATFORM
[2816]408    {
409        for (int i = 0; i < m_platform_list.Count(); i++)
410        {
411            PhysicsObject* PhysObj = m_platform_list[i];
412
413            mat4 GroundMat = PhysObj->GetTransform();
414            if (i == 0)
415            {
416                GroundMat = GroundMat * mat4(quat::fromeuler_xyz(vec3(20.f, .0f, .0f) * seconds));
417                PhysObj->SetTransform(GroundMat.v3.xyz, quat(GroundMat));
418            }
419            else if (i == 1)
420            {
421                GroundMat =
422                    mat4::translate(vec3(-15.0f, 5.0f, lol::cos(m_loop_value) * 8.f)) *
423                    mat4(quat::fromeuler_xyz(vec3(.0f, lol::cos(m_loop_value) * 20.f, .0f)));
424                PhysObj->SetTransform(GroundMat.v3.xyz, quat(GroundMat));
425            }
426        }
427    }
[2879]428#endif //USE_PLATFORM
[2816]429
[2879]430#if USE_CHARACTER
[2816]431    {
432        for (int i = 0; i < m_character_list.Count(); i++)
433        {
434            PhysicsObject* PhysObj = m_character_list[i];
435            EasyCharacterController* Character = (EasyCharacterController*)PhysObj->GetCharacter();
436            mat4 CtlrMx = Character->GetTransform();
437
[2838]438            vec3 movement(0.f);
439            movement.z = (m_controller->GetKey(KEY_MOVE_RIGHT).IsDown() ? 1.f : 0.f)
440                       - (m_controller->GetKey(KEY_MOVE_LEFT).IsDown() ? 1.f : 0.f);
441            movement.x = (m_controller->GetKey(KEY_MOVE_FORWARD).IsDown() ? 1.f : 0.f)
442                       - (m_controller->GetKey(KEY_MOVE_BACK).IsDown() ? 1.f : 0.f);
443            movement.y = (m_controller->GetKey(KEY_MOVE_UP).IsDown() ? 1.f : 0.f)
444                       - (m_controller->GetKey(KEY_MOVE_DOWN).IsDown() ? 1.f : 0.f);
445            vec3 CharMove = movement * seconds * vec3(4.f, 10.f, 4.f);
[2816]446
[2838]447            if (m_controller->GetKey(KEY_MOVE_JUMP).IsReleased())
[2816]448                Character->Jump();
449            Character->SetMovementForFrame(CharMove);
450
451            RayCastResult HitResult;
452            if (m_simulation->RayHits(HitResult, ERT_Closest, Character->GetTransform().v3.xyz, (Character->GetTransform().v3.xyz + vec3(.0f, -1.f, .0f)), Character))
453                Character->AttachTo(HitResult.m_collider_list[0], true, true);
454            else
455                Character->AttachTo(NULL);
456        }
457    }
[2879]458#endif //USE_CHARACTER
[2816]459
[2879]460#if USE_CHARACTER
[2816]461    {
462        PhysObjBarycenter = vec3(.0f);
463        factor = .0f;
464
465        for (int i = 0; i < m_character_list.Count(); i++)
466        {
467            PhysicsObject* PhysObj = m_character_list[i];
468            mat4 GroundMat = PhysObj->GetTransform();
469
470            PhysObjBarycenter += GroundMat.v3.xyz;
471            factor += 1.f;
472        }
473
474        PhysObjBarycenter /= factor;
475
476#if 0
477        m_camera->SetTarget(m_camera->GetTarget() + (seconds / (seconds + 0.18f)) * (PhysObjBarycenter - m_camera->GetTarget()));
478        vec3 CamPosCenter = m_camera->GetTarget() + vec3(.0f, 5.0f, .0f);
479        m_camera->SetPosition(CamPosCenter + normalize(m_camera->GetPosition() - CamPosCenter) * 20.0f);
480#endif
481    }
[2879]482#else
[2816]483    {
484        PhysObjBarycenter = vec3(.0f);
485        for (int i = 0; i < m_physobj_list.Count(); i++)
486        {
[2879]487            PhysicsObject* PhysObj = m_physobj_list[i].m1;
[2816]488            mat4 GroundMat = PhysObj->GetTransform();
489
490            PhysObjBarycenter += GroundMat.v3.xyz;
491            factor += 1.f;
492        }
493
494        PhysObjBarycenter /= factor;
495
496#if 0
497        m_camera->SetTarget(PhysObjBarycenter);
498        m_camera->SetPosition(GroundBarycenter + normalize(GroundBarycenter - PhysObjBarycenter) * 60.0f);
499#endif
500    }
[2879]501#endif //USE_CHARACTER
[2816]502}
503
504void BtPhysTest::TickDraw(float seconds)
505{
506    WorldEntity::TickDraw(seconds);
507
508    if (!m_ready)
509    {
[2879]510#if CAT_MODE
511        /* cat datas setup */
512        m_cat_shader = Shader::Create(LOLFX_RESOURCE_NAME(front_camera_sprite));
513#if USE_BODIES
514        for (int i = 0; i < m_physobj_list.Count(); i++)
515        {
516            PhysicsObject* PhysObj = m_physobj_list[i].m1;
517            m_cat_sdata = new CatShaderData(((1 << VertexUsage::Position) |
518                                                (1 << VertexUsage::Color) |
519                                                (1 << VertexUsage::TexCoord) |
520                                                (1 << VertexUsage::TexCoordExt)),
521                                                m_cat_shader);
522            m_cat_sdata->m_shader_texture = m_cat_texture->GetTexture();
523            PhysObj->SetCustomShaderData(m_cat_sdata);
524        }
525#endif //USE_BODIES
526
527
528#endif //CAT_MODE
529
[2816]530        /* FIXME: this object never cleans up */
531        m_ready = true;
532    }
533
534    //Video::SetClearColor(vec4(0.0f, 0.0f, 0.12f, 1.0f));
535
536}
537
538BtPhysTest::~BtPhysTest()
539{
540    g_scene->PopCamera(m_camera);
541    Ticker::Unref(m_light1);
542    Ticker::Unref(m_light2);
543
[2879]544#if CAT_MODE
545    /* cat datas setup */
546    delete(m_cat_sdata);
547    Shader::Destroy(m_cat_shader);
548    Tiler::Deregister(m_cat_texture);
549#endif //CAT_MODE
550
[2816]551    while (m_constraint_list.Count())
552    {
553        EasyConstraint* CurPop = m_constraint_list.Last();
554        m_constraint_list.Pop();
555        CurPop->RemoveFromSimulation(m_simulation);
556        delete CurPop;
557    }
558    while (m_ground_list.Count())
559    {
560        PhysicsObject* CurPop = m_ground_list.Last();
561        m_ground_list.Pop();
562        CurPop->GetPhysic()->RemoveFromSimulation(m_simulation);
563        Ticker::Unref(CurPop);
564    }
565    while (m_stairs_list.Count())
566    {
567        PhysicsObject* CurPop = m_stairs_list.Last();
568        m_stairs_list.Pop();
569        CurPop->GetPhysic()->RemoveFromSimulation(m_simulation);
570        Ticker::Unref(CurPop);
571    }
572    while (m_character_list.Count())
573    {
574        PhysicsObject* CurPop = m_character_list.Last();
575        m_character_list.Pop();
576        CurPop->GetCharacter()->RemoveFromSimulation(m_simulation);
577        Ticker::Unref(CurPop);
578    }
579    while (m_platform_list.Count())
580    {
581        PhysicsObject* CurPop = m_platform_list.Last();
582        m_platform_list.Pop();
583        CurPop->GetPhysic()->RemoveFromSimulation(m_simulation);
584        Ticker::Unref(CurPop);
585    }
586    while (m_physobj_list.Count())
587    {
[2879]588        PhysicsObject* CurPop = m_physobj_list.Last().m1;
[2816]589        m_physobj_list.Pop();
590        CurPop->GetPhysic()->RemoveFromSimulation(m_simulation);
591        Ticker::Unref(CurPop);
592    }
593    Ticker::Unref(m_simulation);
594
595}
596
[2879]597//-----------------------------------------------------------------------------
598// CShaderData
599//-----------------------------------------------------------------------------
600CatShaderData::CatShaderData(uint32_t vert_decl_flags, Shader* shader)
601    : GpuShaderData(vert_decl_flags, shader, DebugRenderMode::Default)
602{
603    SetupDefaultData();
604}
605
606//-----------------------------------------------------------------------------
607void CatShaderData::SetupDefaultData()
608{
609    AddUniform("in_model_view");
610    AddUniform("in_normal_mat");
611    AddUniform("in_proj");
612    AddUniform("in_texture");
613}
614
615//-----------------------------------------------------------------------------
616void CatShaderData::SetupShaderDatas(mat4 const &model)
617{
618    mat4 proj = g_scene->GetCamera()->GetProjection();
619    mat4 view = g_scene->GetCamera()->GetView();
620
621    mat4 modelview = view * model;
622    mat3 normalmat = transpose(inverse(mat3(view)));
623
624    m_shader->SetUniform(*GetUniform("in_model_view"), modelview);
625    m_shader->SetUniform(*GetUniform("in_normal_mat"), normalmat);
626    m_shader->SetUniform(*GetUniform("in_proj"), proj);
627}
628
[2816]629int main(int argc, char **argv)
630{
631    System::Init(argc, argv);
632
[2879]633    Application app("BtPhysTest", ivec2(1280, 960), 60.0f);
[2816]634
635    new BtPhysTest(argc > 1);
636    app.ShowPointer(false);
637
638    app.Run();
639
640    return EXIT_SUCCESS;
641}
642
Note: See TracBrowser for help on using the repository browser.