diff --git a/extensions/physics-nodes/CCPhysicsDebugNode.cpp b/extensions/physics-nodes/CCPhysicsDebugNode.cpp index 1f535a6414..fc171f0356 100644 --- a/extensions/physics-nodes/CCPhysicsDebugNode.cpp +++ b/extensions/physics-nodes/CCPhysicsDebugNode.cpp @@ -1,6 +1,7 @@ /* Copyright (c) 2012 Scott Lembcke and Howling Moon Software * Copyright (c) 2012 cocos2d-x.org * Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + * Copyright (c) 2021 @aismann; Peter Eismann, Germany; dreifrankensoft * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -49,6 +50,25 @@ Vec2 physicsDebugNodeOffset; as the private API may change with little or no warning. */ +static const cpVect spring_verts[] = { + {0.00f, 0.0f}, + {0.20f, 0.0f}, + {0.25f, 3.0f}, + {0.30f, -6.0f}, + {0.35f, 6.0f}, + {0.40f, -6.0f}, + {0.45f, 6.0f}, + {0.50f, -6.0f}, + {0.55f, 6.0f}, + {0.60f, -6.0f}, + {0.65f, 6.0f}, + {0.70f, -3.0f}, + {0.75f, 6.0f}, + {0.80f, 0.0f}, + {1.00f, 0.0f}, +}; +static const int spring_count = sizeof(spring_verts) / sizeof(cpVect); + static Color4F ColorForBody(cpBody *body) { if (CP_BODY_TYPE_STATIC == cpBodyGetType(body) || cpBodyIsSleeping(body)) @@ -154,11 +174,35 @@ static void DrawConstraint(cpConstraint *constraint, DrawNode *renderer) } else if(cpConstraintIsDampedSpring(constraint)) { - // TODO: uninplemented + cpDampedSpring* spring = (cpDampedSpring*) constraint; + + cpVect a = cpTransformPoint(body_a->transform, spring->anchorA); + cpVect b = cpTransformPoint(body_b->transform, spring->anchorB); + + renderer->drawDot(cpVert2Point(a), 3.0, CONSTRAINT_COLOR); + renderer->drawDot(cpVert2Point(b), 3.0, CONSTRAINT_COLOR); + + cpVect delta = cpvsub(b, a); + cpFloat cos = delta.x; + cpFloat sin = delta.y; + cpFloat s = 1.0f / cpvlength(delta); + + cpVect r1 = cpv(cos, -sin * s); + cpVect r2 = cpv(sin, cos * s); + + cpVect* verts = (cpVect*) alloca(spring_count * sizeof(cpVect)); + for (int i = 0; i < spring_count; i++) { + cpVect v = spring_verts[i]; + verts[i] = cpv(cpvdot(v, r1) + a.x, cpvdot(v, r2) + a.y); + } + + for (int i = 0; i < spring_count - 1; i++) { + renderer->drawSegment(cpVert2Point(verts[i]), cpVert2Point(verts[i+1]), 1.0, CONSTRAINT_COLOR); + } } else { - // printf("Cannot draw constraint\n"); + CCLOG("Cannot draw constraint"); } } diff --git a/extensions/physics-nodes/CCPhysicsDebugNode.h b/extensions/physics-nodes/CCPhysicsDebugNode.h index b369967735..8a0e42295c 100644 --- a/extensions/physics-nodes/CCPhysicsDebugNode.h +++ b/extensions/physics-nodes/CCPhysicsDebugNode.h @@ -1,6 +1,7 @@ /* Copyright (c) 2012 Scott Lembcke and Howling Moon Software * Copyright (c) 2012 cocos2d-x.org * Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + * Copyright (c) 2021 @aismann; Peter Eismann, Germany; dreifrankensoft * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/extensions/physics-nodes/CCPhysicsSprite.cpp b/extensions/physics-nodes/CCPhysicsSprite.cpp index 468afee7a2..4459f8c158 100644 --- a/extensions/physics-nodes/CCPhysicsSprite.cpp +++ b/extensions/physics-nodes/CCPhysicsSprite.cpp @@ -1,6 +1,7 @@ /* Copyright (c) 2012 Scott Lembcke and Howling Moon Software * Copyright (c) 2012 cocos2d-x.org * Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + * Copyright (c) 2021 @aismann; Peter Eismann, Germany; dreifrankensoft * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/extensions/physics-nodes/CCPhysicsSprite.h b/extensions/physics-nodes/CCPhysicsSprite.h index c094e1404b..df2ad5ca3a 100644 --- a/extensions/physics-nodes/CCPhysicsSprite.h +++ b/extensions/physics-nodes/CCPhysicsSprite.h @@ -1,6 +1,7 @@ /* Copyright (c) 2012 Scott Lembcke and Howling Moon Software * Copyright (c) 2012 cocos2d-x.org * Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + * Copyright (c) 2021 @aismann; Peter Eismann, Germany; dreifrankensoft * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/extensions/physics-nodes/CCPhysicsSpriteBox2D.cpp b/extensions/physics-nodes/CCPhysicsSpriteBox2D.cpp index 93055d729c..53d6cad4c5 100644 --- a/extensions/physics-nodes/CCPhysicsSpriteBox2D.cpp +++ b/extensions/physics-nodes/CCPhysicsSpriteBox2D.cpp @@ -1,7 +1,8 @@ /* Copyright (c) 2012 Scott Lembcke and Howling Moon Software * Copyright (c) 2012 cocos2d-x.org * Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - * + * Copyright (c) 2021 @aismann; Peter Eismann, Germany; dreifrankensoft + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights diff --git a/extensions/physics-nodes/CCPhysicsSpriteBox2D.h b/extensions/physics-nodes/CCPhysicsSpriteBox2D.h index 18a8f95afe..b102f1be6d 100644 --- a/extensions/physics-nodes/CCPhysicsSpriteBox2D.h +++ b/extensions/physics-nodes/CCPhysicsSpriteBox2D.h @@ -1,6 +1,7 @@ /* Copyright (c) 2012 Scott Lembcke and Howling Moon Software * Copyright (c) 2012 cocos2d-x.org * Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + * Copyright (c) 2021 @aismann; Peter Eismann, Germany; dreifrankensoft * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/extensions/physics-nodes/CCPhysicsSpriteChipmunk2D.cpp b/extensions/physics-nodes/CCPhysicsSpriteChipmunk2D.cpp index 4fa04e1477..bea5cc63e0 100644 --- a/extensions/physics-nodes/CCPhysicsSpriteChipmunk2D.cpp +++ b/extensions/physics-nodes/CCPhysicsSpriteChipmunk2D.cpp @@ -1,6 +1,7 @@ /* Copyright (c) 2012 Scott Lembcke and Howling Moon Software * Copyright (c) 2012 cocos2d-x.org * Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + * Copyright (c) 2021 @aismann; Peter Eismann, Germany; dreifrankensoft * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/extensions/physics-nodes/CCPhysicsSpriteChipmunk2D.h b/extensions/physics-nodes/CCPhysicsSpriteChipmunk2D.h index 21f069b79d..951b1309a4 100644 --- a/extensions/physics-nodes/CCPhysicsSpriteChipmunk2D.h +++ b/extensions/physics-nodes/CCPhysicsSpriteChipmunk2D.h @@ -1,6 +1,7 @@ /* Copyright (c) 2012 Scott Lembcke and Howling Moon Software * Copyright (c) 2012 cocos2d-x.org * Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + * Copyright (c) 2021 @aismann; Peter Eismann, Germany; dreifrankensoft * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/tests/cpp-tests/Classes/ChipmunkTestBed/ChipmunkTestBed.cpp b/tests/cpp-tests/Classes/ChipmunkTestBed/ChipmunkTestBed.cpp index 2a172c0ebf..7293af701a 100644 --- a/tests/cpp-tests/Classes/ChipmunkTestBed/ChipmunkTestBed.cpp +++ b/tests/cpp-tests/Classes/ChipmunkTestBed/ChipmunkTestBed.cpp @@ -1,7 +1,5 @@ /**************************************************************************** - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - http://www.cocos2d-x.org + * Copyright (c) 2021 @aismann; Peter Eismann, Germany; dreifrankensoft Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -52,12 +50,14 @@ cpBool ChipmunkDemoRightClick; cpBool ChipmunkDemoRightDown; cpBool ChipmunkDemoLeftDown = cpFalse; + cpBody* mouse_body = cpBodyNewKinematic(); cpConstraint* mouse_joint = NULL; char const* ChipmunkDemoMessageString = NULL; float ChipmunkDebugDrawPointLineScale = 1.0f; +static size_t VertexCount, IndexCount; #define GRABBABLE_MASK_BIT (1 << 31) cpShapeFilter GRAB_FILTER = {CP_NO_GROUP, GRABBABLE_MASK_BIT, GRABBABLE_MASK_BIT}; @@ -70,10 +70,50 @@ void ChipmunkDemoDefaultDrawImpl(cpSpace* space){}; void ChipmunkDebugDrawDot(cpFloat size, cpVect pos, cpSpaceDebugColor fillColor){}; void ChipmunkDebugDrawSegment(cpVect a, cpVect b, cpSpaceDebugColor color){}; -void ChipmunkDebugDrawFatSegment( - cpVect a, cpVect b, cpFloat radius, cpSpaceDebugColor outlineColor, cpSpaceDebugColor fillColor){}; +void ChipmunkDebugDrawFatSegment(cpVect a, cpVect b, cpFloat radius, cpSpaceDebugColor outlineColor, cpSpaceDebugColor fillColor){}; void ChipmunkDebugDrawBB(cpBB bb, cpSpaceDebugColor outlineColor){}; -void ChipmunkDemoPrintString(char const* fmt, ...){}; +static Vertex* push_vertexes(size_t vcount, const Index* index_src, size_t icount){}; +//// cpAssertHard(VertexCount + vcount <= VERTEX_MAX && IndexCount + icount <= INDEX_MAX, "Geometry buffer full."); +// +// Vertex* vertex_dst = Vertexes + VertexCount; +// size_t base = VertexCount; +// VertexCount += vcount; +// +// Index* index_dst = Indexes + IndexCount; +// for (size_t i = 0; i < icount; i++) +// index_dst[i] = index_src[i] + (Index) base; +// IndexCount += icount; +// +// return vertex_dst; +//} + +static char PrintStringBuffer[1024 * 8]; +static char* PrintStringCursor; +cocos2d::Label* label; + +void ChipmunkDemoPrintString(char const* fmt, ...) { + if (PrintStringCursor == NULL) { + return; + } + + ChipmunkDemoMessageString = PrintStringBuffer; + if (ChipmunkDemoMessageString) { + label->setString(ChipmunkDemoMessageString); + ChipmunkDemoMessageString = ""; + } + + va_list args; + va_start(args, fmt); + int remaining = sizeof(PrintStringBuffer) - (PrintStringCursor - PrintStringBuffer); + int would_write = vsnprintf(PrintStringCursor, remaining, fmt, args); + if (would_write > 0 && would_write < remaining) { + PrintStringCursor += would_write; + } else { + // encoding error or overflow, prevent further use until reinitialized + PrintStringCursor = NULL; + } + va_end(args); +} cpSpaceDebugColor RGBAColor(float r, float g, float b, float a) { cpSpaceDebugColor color = {r, g, b, a}; @@ -138,91 +178,61 @@ static Rect getRect(Node* node) { } ChipmunkTestBed::ChipmunkTestBed() { + // halx99: since adxe init scene default camera at 'initWithXXX' function, only change design sze at scene construct is ok + // see also: https://github.com/adxeproject/adxe/commit/581a7921554c09746616759d5a5ca6ce9d3eaa22 auto director = Director::getInstance(); auto glview = director->getOpenGLView(); Size designSize(960 * 0.8, 640 * 0.8); glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::NO_BORDER); - //// Resize (expand) window - // static Size resourceSize(1280, 720); - // auto director = Director::getInstance(); - // GLViewImpl* view = (GLViewImpl*) Director::getInstance()->getOpenGLView(); - // view->setWindowed(resourceSize.width, resourceSize.height); - // orgSize = view->getDesignResolutionSize(); - // view->setDesignResolutionSize(480, 320, ResolutionPolicy::NO_BORDER); - - // auto director = Director::getInstance(); - // auto glview = director->getOpenGLView(); - // Size designSize(960, 640); - // glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::NO_BORDER); - // creating a keyboard event listener auto listener = EventListenerKeyboard::create(); listener->onKeyPressed = [](EventKeyboard::KeyCode keyCode, Event* event) { - char buf[100] = {0}; - sprintf(buf, "Key %d was pressed!", (int) keyCode); - switch ((int) keyCode) { - case 28: + case 28: // Up ChipmunkDemoKeyboard.y++; break; - case 29: + case 29: // Down ChipmunkDemoKeyboard.y--; break; - case 27: + case 27: // Right ChipmunkDemoKeyboard.x++; break; - case 26: + case 26: // Left ChipmunkDemoKeyboard.x--; break; } - - CCLOG("%s", buf); }; - - listener->onKeyReleased = [](EventKeyboard::KeyCode keyCode, Event* event) { - char buf[100] = {0}; - sprintf(buf, "Key %d was released!", (int) keyCode); - - auto label = static_cast(event->getCurrentTarget()); - CCLOG("%s", buf); - }; - - // - // - // Line 65 : cpVect ChipmunkDemoKeyboard; - // Line 444 : case SAPP_KEYCODE_UP : ChipmunkDemoKeyboard.y += (event->type == SAPP_EVENTTYPE_KEY_DOWN ? 1.0 : - // -1.0); break; Line 445 : case SAPP_KEYCODE_DOWN : ChipmunkDemoKeyboard.y += (event->type == - // SAPP_EVENTTYPE_KEY_DOWN ? -1.0 : 1.0); break; Line 446 : case SAPP_KEYCODE_LEFT : ChipmunkDemoKeyboard.x += - // (event->type == SAPP_EVENTTYPE_KEY_DOWN ? -1.0 : 1.0); break; Line 447 : case SAPP_KEYCODE_RIGHT : - // ChipmunkDemoKeyboard.x += (event->type == SAPP_EVENTTYPE_KEY_DOWN ? 1.0 : -1.0); break; - - _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); - + // creating a mouse event listener _mouseListener = EventListenerMouse::create(); _mouseListener->onMouseMove = CC_CALLBACK_1(ChipmunkTestBed::onMouseMove, this); _mouseListener->onMouseUp = CC_CALLBACK_1(ChipmunkTestBed::onMouseUp, this); _mouseListener->onMouseDown = CC_CALLBACK_1(ChipmunkTestBed::onMouseDown, this); - _mouseListener->onMouseScroll = CC_CALLBACK_1(ChipmunkTestBed::onMouseScroll, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(_mouseListener, this); // ChipmunkDemoMessageString - label = Label::createWithTTF("", "fonts/Marker Felt.ttf", 10.0f); - label->setPosition(VisibleRect::center().x, VisibleRect::top().y - 8); + label = Label::createWithTTF("", "fonts/Marker Felt.ttf", 16.0f); + label->setAnchorPoint(Vec2(0, 1)); + label->setPosition(10, VisibleRect::top().y - 100); label->setColor(Color3B::GREEN); this->addChild(label, -1); scheduleUpdate(); } + ChipmunkTestBed::~ChipmunkTestBed() { ChipmunkDemoFreeSpaceChildren(_space); auto director = Director::getInstance(); auto glview = director->getOpenGLView(); + // halx99: since we restore design resolution at BasetTest, this is not necessary. + // Size designSize(480, 320); + // glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::NO_BORDER); + _eventDispatcher->removeEventListener(_mouseListener); } @@ -242,6 +252,8 @@ void ChipmunkTestBed::update(float delta) { #else cpHastySpaceStep(_space, delta); #endif + + } void ChipmunkTestBed::createResetButton() { @@ -257,11 +269,6 @@ void ChipmunkTestBed::reset(Ref* sender) { } void ChipmunkTestBed::onEnter() { - /*auto director = Director::getInstance(); - auto glview = director->getOpenGLView(); - Size designSize(960 * 0.8, 640 * 0.8); - glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::NO_BORDER);*/ - TestCase::onEnter(); physicsDebugNodeOffset = VisibleRect::center(); ChipmunkDemoMessageString = ""; @@ -292,13 +299,11 @@ void ChipmunkTestBed::onMouseDown(Event* event) { cpSpaceAddConstraint(_space, mouse_joint); } } else if ((int) e->getMouseButton() == 1) { - if (mouse_joint) { cpSpaceRemoveConstraint(_space, mouse_joint); cpConstraintFree(mouse_joint); mouse_joint = NULL; } - ChipmunkDemoLeftDown = cpFalse; ChipmunkDemoRightDown = cpTrue; ChipmunkDemoRightClick = cpTrue; @@ -329,13 +334,6 @@ void ChipmunkTestBed::onMouseMove(Event* event) { cpBodySetPosition(mouse_body, ChipmunkDemoMouse); } -void ChipmunkTestBed::onMouseScroll(Event* event) { - EventMouse* e = (EventMouse*) event; - CCLOG("Mouse Scroll detected, X: %i ", e->getScrollX()); - CCLOG("Mouse Scroll detected, Y: %i ", e->getScrollY()); -} - - //------------------------------------------------------------------ // // LogoSmashDemo @@ -643,7 +641,6 @@ void SpringiesDemo::update(float delta) { //------------------------------------------------------------------ void ShatterDemo::onEnter() { ChipmunkTestBed::onEnter(); - initPhysics(); } @@ -804,7 +801,6 @@ void PlatformerPlayerDemo::update(float delta) { PlatformerPlayer.updateFunc(_space, PlatformerPlayer.timestep); } - //------------------------------------------------------------------ // // QueryDemo @@ -826,6 +822,8 @@ void QueryDemo::initPhysics() { } void QueryDemo::update(float delta) { + PrintStringBuffer[0] = 0; + PrintStringCursor = PrintStringBuffer; Query.updateFunc(_space, Query.timestep); } @@ -850,6 +848,8 @@ void ContactGraphDemo::initPhysics() { } void ContactGraphDemo::update(float delta) { + // PrintStringBuffer[0] = 0; + PrintStringCursor = PrintStringBuffer; ContactGraph.updateFunc(_space, ContactGraph.timestep); } diff --git a/tests/cpp-tests/Classes/ChipmunkTestBed/ChipmunkTestBed.h b/tests/cpp-tests/Classes/ChipmunkTestBed/ChipmunkTestBed.h index ceb92802d8..03ee91794d 100644 --- a/tests/cpp-tests/Classes/ChipmunkTestBed/ChipmunkTestBed.h +++ b/tests/cpp-tests/Classes/ChipmunkTestBed/ChipmunkTestBed.h @@ -1,8 +1,6 @@ /**************************************************************************** - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - http://www.cocos2d-x.org - + * Copyright (c) 2021 @aismann; Peter Eismann, Germany; dreifrankensoft + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights @@ -88,16 +86,12 @@ public: void onMouseDown(cocos2d::Event* event); void onMouseUp(cocos2d::Event* event); void onMouseMove(cocos2d::Event* event); - void onMouseScroll(cocos2d::Event* event); cpSpace* _space; // strong ref - cocos2d::Size orgSize; - private: cocos2d::extension::PhysicsDebugNode* _debugLayer; // weak ref cocos2d::EventListenerMouse* _mouseListener; - cocos2d::Label* label; cocos2d::Node* _trackNode; }; @@ -291,12 +285,6 @@ public: virtual void update(float dt) override; }; - - - - - - class QueryDemo : public ChipmunkTestBed { public: CREATE_FUNC(QueryDemo); @@ -318,7 +306,6 @@ public: virtual void update(float dt) override; }; - class BuoyancyDemo : public ChipmunkTestBed { public: CREATE_FUNC(BuoyancyDemo); @@ -329,7 +316,6 @@ public: virtual void update(float dt) override; }; - class SliceDemo : public ChipmunkTestBed { public: CREATE_FUNC(SliceDemo); @@ -340,7 +326,6 @@ public: virtual void update(float dt) override; }; - class UnicycleDemo : public ChipmunkTestBed { public: CREATE_FUNC(UnicycleDemo); @@ -351,10 +336,6 @@ public: virtual void update(float dt) override; }; - - - - class ExampleDemo : public ChipmunkTestBed { public: CREATE_FUNC(ExampleDemo); @@ -364,12 +345,6 @@ public: void initPhysics() override; virtual void update(float dt) override; }; - - - - - - DEFINE_TEST_SUITE(ChipmunkTestBedTests); #endif /* __CHIPMUNKTESTBED_H__ */ diff --git a/tests/cpp-tests/Classes/ChipmunkTestBed/demo/ChipmunkDemo.h b/tests/cpp-tests/Classes/ChipmunkTestBed/demo/ChipmunkDemo.h index 2aaba6136c..54fddf36da 100644 --- a/tests/cpp-tests/Classes/ChipmunkTestBed/demo/ChipmunkDemo.h +++ b/tests/cpp-tests/Classes/ChipmunkTestBed/demo/ChipmunkDemo.h @@ -51,7 +51,26 @@ frand_unit_circle(){ return (cpvlengthsq(v) < 1.0f ? v : frand_unit_circle()); } +typedef struct { + float x, y; +} float2; +typedef struct { + uint8_t r, g, b, a; +} RGBA8; +typedef struct { + float2 pos; + float2 uv; + float r; + RGBA8 fill, outline; +} Vertex; +typedef uint16_t Index; +// Meh, just max out 16 bit index size. +#define VERTEX_MAX (64 * 1024) +#define INDEX_MAX (4 * VERTEX_MAX) + +static Vertex Vertexes[VERTEX_MAX]; +static Index Indexes[INDEX_MAX]; extern int ChipmunkDemoTicks; @@ -60,11 +79,10 @@ extern cpVect ChipmunkDemoKeyboard; extern cpVect ChipmunkDemoMouse; extern cpBool ChipmunkDemoRightClick; extern cpBool ChipmunkDemoRightDown; - extern float ChipmunkDebugDrawPointLineScale; extern char const *ChipmunkDemoMessageString; -void ChipmunkDemoPrintString(char const *fmt, ...); +extern void ChipmunkDemoPrintString(char const* fmt, ...); extern cpShapeFilter GRAB_FILTER; extern cpShapeFilter NOT_GRABBABLE_FILTER; diff --git a/tests/cpp-tests/Classes/ChipmunkTestBed/demo/ContactPoints.c_ b/tests/cpp-tests/Classes/ChipmunkTestBed/demo/ContactPoints.c_ deleted file mode 100644 index 4408d079bd..0000000000 --- a/tests/cpp-tests/Classes/ChipmunkTestBed/demo/ContactPoints.c_ +++ /dev/null @@ -1,143 +0,0 @@ -/* Copyright (c) 2007 Scott Lembcke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include -#include -#include -#include - -#include "chipmunk/chipmunk_private.h" -#include "ChipmunkDemo.h" - -static cpBool NeverCollide(cpArbiter *arb, cpSpace *space, void *data){return cpFalse;} - -static void -update(cpSpace *space) -{ - int steps = 1; - cpFloat dt = 1.0f/60.0f/(cpFloat)steps; - - for(int i=0; i -#include -#include -#include - -#include "chipmunk_private.h" -#include "chipmunk_unsafe.h" -#include "ChipmunkDemo.h" - -static cpShape *shape1, *shape2; - -static void -update(cpSpace *space, cpFloat dt) -{ - cpSpaceStep(space, dt); -} - -static void -draw(cpSpace *space) -{ - ChipmunkDemoDefaultDrawImpl(space); - struct cpContact arr[CP_MAX_CONTACTS_PER_ARBITER]; -// cpCollideShapes(shape1, shape2, (cpCollisionID[]){0}, arr); - cpCollisionInfo info = cpCollideShapes(shape2, shape1, 0x00000000, arr); -} - -static cpSpace * -init(void) -{ - cpSpace *space = cpSpaceNew(); - cpSpaceSetIterations(space, 5); - space->damping = 0.1; - - cpFloat mass = 1.0f; - - { - cpFloat size = 100.0; - - cpBody *body = cpSpaceAddBody(space, cpBodyNew(mass, cpMomentForBox(mass, size, size))); - cpBodySetPosition(body, cpv(100.0, 50.0f)); - - shape1 = cpSpaceAddShape(space, cpBoxShapeNew(body, size, size, 0.0)); - shape1->group = 1; - }{ - cpFloat size = 100.0; - - cpBody *body = cpSpaceAddBody(space, cpBodyNew(mass, cpMomentForBox(mass, size, size))); - cpBodySetPosition(body, cpv(120.0, -40.0f)); - cpBodySetAngle(body, 1e-2); - - shape2 = cpSpaceAddShape(space, cpBoxShapeNew(body, size, size, 0.0)); - shape2->group = 1; - } - -// { -// cpFloat size = 100.0; -// const int NUM_VERTS = 5; -// -// cpVect verts[NUM_VERTS]; -// for(int i=0; igroup = 1; -// } -// { -// cpFloat size = 100.0; -// const int NUM_VERTS = 4; -// -// cpVect verts[NUM_VERTS]; -// for(int i=0; igroup = 1; -// } -// -// { -// cpFloat size = 150.0; -// cpFloat radius = 25.0; -// -// cpVect a = cpv( size/2.0, 0.0); -// cpVect b = cpv(-size/2.0, 0.0); -// cpBody *body = cpSpaceAddBody(space, cpBodyNew(mass, cpMomentForSegment(mass, a, b))); -// cpBodySetPosition(body, cpv(0, 25)); -// -// shape1 = cpSpaceAddShape(space, cpSegmentShapeNew(body, a, b, radius)); -// shape1->group = 1; -// } -// { -// cpFloat radius = 50.0; -// -// cpBody *body = cpSpaceAddBody(space, cpBodyNew(mass, cpMomentForCircle(mass, 0.0f, radius, cpvzero))); -// cpBodySetPosition(body, cpv(0, -25)); -// -// shape2 = cpSpaceAddShape(space, cpCircleShapeNew(body, radius, cpvzero)); -// shape2->group = 1; -// } - - return space; -} - -static void -destroy(cpSpace *space) -{ - ChipmunkDemoFreeSpaceChildren(space); - cpSpaceFree(space); -} - -ChipmunkDemo GJK = { - "GJK", - 1.0f/60.0f, - init, - update, - draw, - destroy, -}; diff --git a/tests/cpp-tests/Classes/ChipmunkTestBed/demo/Player.c b/tests/cpp-tests/Classes/ChipmunkTestBed/demo/Player.c index 21ae206c20..2ad66acb5b 100644 --- a/tests/cpp-tests/Classes/ChipmunkTestBed/demo/Player.c +++ b/tests/cpp-tests/Classes/ChipmunkTestBed/demo/Player.c @@ -140,7 +140,7 @@ init(void) body->velocity_func = playerUpdateVelocity; playerBody = body; - shape = cpSpaceAddShape(space, cpBoxShapeNew2(body, cpBBNew(-15.0, -27.5, 15.0, 27.5), 10.0)); + shape = cpSpaceAddShape(space, cpBoxShapeNew2(body, cpBBNew(-15.0, -27.5, 15.0, 27.5), 1.0)); // shape = cpSpaceAddShape(space, cpSegmentShapeNew(playerBody, cpvzero, cpv(0, radius), radius)); shape->e = 0.0f; shape->u = 0.0f; shape->type = 1; diff --git a/tests/cpp-tests/Classes/ChipmunkTestBed/demo/Plink.c b/tests/cpp-tests/Classes/ChipmunkTestBed/demo/Plink.c index 344de87cec..ecf7ca2129 100644 --- a/tests/cpp-tests/Classes/ChipmunkTestBed/demo/Plink.c +++ b/tests/cpp-tests/Classes/ChipmunkTestBed/demo/Plink.c @@ -30,7 +30,7 @@ static void eachBody(cpBody *body, void *unused) { cpVect pos = cpBodyGetPosition(body); - if(pos.y < -260 || cpfabs(pos.x) > 340){ + if(pos.y < -260){ cpFloat x = rand()/(cpFloat)RAND_MAX*640 - 320; cpBodySetPosition(body, cpv(x, 260)); } @@ -80,10 +80,10 @@ init(void) }; // Create the static triangles. - for(int i=0; i<9; i++){ + for(int i=0; i<10; i++){ for(int j=0; j<6; j++){ cpFloat stagger = (j%2)*40; - cpVect offset = cpv(i*80 - 320 + stagger, j*70 - 240); + cpVect offset = cpv(i*80 - 360 + stagger, j*70 - 200); shape = cpSpaceAddShape(space, cpPolyShapeNew(staticBody, 3, tris, cpTransformTranslate(offset), 0.0)); cpShapeSetElasticity(shape, 1.0f); cpShapeSetFriction(shape, 1.0f); diff --git a/tests/cpp-tests/Classes/ChipmunkTestBed/demo/Query.c b/tests/cpp-tests/Classes/ChipmunkTestBed/demo/Query.c index 34e96316b7..9b49a4746a 100644 --- a/tests/cpp-tests/Classes/ChipmunkTestBed/demo/Query.c +++ b/tests/cpp-tests/Classes/ChipmunkTestBed/demo/Query.c @@ -38,7 +38,7 @@ update(cpSpace *space, double dt) cpFloat radius = 10.0; ChipmunkDebugDrawSegment(start, end, RGBAColor(0,1,0,1)); - ChipmunkDemoPrintString("Query: Dist(%f) Point(%5.2f, %5.2f), ", cpvdist(start, end), end.x, end.y); + ChipmunkDemoPrintString("Query: Dist(%f) Point(%5.2f, %5.2f),\n", cpvdist(start, end), end.x, end.y); cpSegmentQueryInfo segInfo = {0}; if(cpSpaceSegmentQueryFirst(space, start, end, radius, CP_SHAPE_FILTER_ALL, &segInfo)){ @@ -55,9 +55,9 @@ update(cpSpace *space, double dt) ChipmunkDebugDrawDot(3, point, RGBAColor(1,0,0,1)); - ChipmunkDemoPrintString("Segment Query: Dist(%f) Normal(%5.2f, %5.2f)", segInfo.alpha*cpvdist(start, end), n.x, n.y); + ChipmunkDemoPrintString("Segment Query: Dist(%f) Normal(%5.2f, %5.2f)\n", segInfo.alpha*cpvdist(start, end), n.x, n.y); } else { - ChipmunkDemoPrintString("Segment Query (None)"); + ChipmunkDemoPrintString("Segment Query (None)\n"); } // Draw a fat green line over the unoccluded part of the query diff --git a/tests/cpp-tests/Classes/ChipmunkTestBed/demo/Smooth.c_ b/tests/cpp-tests/Classes/ChipmunkTestBed/demo/Smooth.c_ deleted file mode 100644 index 118df2f410..0000000000 --- a/tests/cpp-tests/Classes/ChipmunkTestBed/demo/Smooth.c_ +++ /dev/null @@ -1,141 +0,0 @@ -/* Copyright (c) 2007 Scott Lembcke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include -#include -#include -#include - -#include "chipmunk/chipmunk_private.h" -#include "ChipmunkDemo.h" - -static cpBool DrawContacts(cpArbiter *arb, cpSpace *space, void *data){ - cpContactPointSet set = cpArbiterGetContactPointSet(arb); - - for(int i=0; i b ? a : b) -#define MIN(a, b) (a < b ? a : b) - -static cpSpace * -init(void) -{ - cpSpace *space = cpSpaceNew(); - cpSpaceSetIterations(space, 5); - cpSpaceSetDamping(space, 0.1f); - - cpSpaceSetDefaultCollisionHandler(space, NULL, DrawContacts, NULL, NULL, NULL); - - { - cpFloat mass = 1.0f; - cpFloat length = 100.0f; - cpVect a = cpv(-length/2.0f, 0.0f), b = cpv(length/2.0f, 0.0f); - - cpBody *body = cpSpaceAddBody(space, cpBodyNew(mass, cpMomentForSegment(mass, a, b))); - cpBodySetPos(body, cpv(-160.0f, 80.0f)); - - cpSpaceAddShape(space, cpSegmentShapeNew(body, a, b, 30.0f)); - } - - { - cpFloat mass = 1.0f; - const int NUM_VERTS = 5; - - cpVect verts[NUM_VERTS]; - for(int i=0; i