2021-06-16 19:34:09 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-06-17 14:22:52 +08:00
|
|
|
|
2021-06-16 19:34:09 +08:00
|
|
|
http://www.cocos2d-x.org
|
2021-06-17 14:22:52 +08:00
|
|
|
|
2021-06-16 19:34:09 +08:00
|
|
|
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:
|
2021-06-17 14:22:52 +08:00
|
|
|
|
2021-06-16 19:34:09 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-06-17 14:22:52 +08:00
|
|
|
|
2021-06-16 19:34:09 +08:00
|
|
|
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 <stdbool.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
2021-06-23 14:25:44 +08:00
|
|
|
#include "chipmunk/chipmunk_private.h"
|
2021-06-16 19:34:09 +08:00
|
|
|
#include "chipmunk/chipmunk.h"
|
|
|
|
|
|
|
|
#include "ChipmunkTestBed.h"
|
|
|
|
|
|
|
|
|
|
|
|
USING_NS_CC;
|
|
|
|
USING_NS_CC_EXT;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
kTagParentNode = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
Z_PHYSICS_DEBUG = 100,
|
|
|
|
};
|
|
|
|
|
2021-06-23 14:25:44 +08:00
|
|
|
cpVect ChipmunkDemoMouse;
|
|
|
|
cpVect ChipmunkDemoKeyboard;
|
|
|
|
cpBool ChipmunkDemoRightClick;
|
|
|
|
cpBool ChipmunkDemoRightDown;
|
|
|
|
cpBool ChipmunkDemoLeftDown = cpFalse;
|
2021-06-16 19:34:09 +08:00
|
|
|
|
2021-06-23 14:25:44 +08:00
|
|
|
cpBody* mouse_body = cpBodyNewKinematic();
|
|
|
|
cpConstraint* mouse_joint = NULL;
|
|
|
|
|
|
|
|
char const* ChipmunkDemoMessageString = NULL;
|
|
|
|
|
|
|
|
float ChipmunkDebugDrawPointLineScale = 1.0f;
|
2021-06-17 14:22:52 +08:00
|
|
|
|
|
|
|
#define GRABBABLE_MASK_BIT (1 << 31)
|
|
|
|
cpShapeFilter GRAB_FILTER = {CP_NO_GROUP, GRABBABLE_MASK_BIT, GRABBABLE_MASK_BIT};
|
|
|
|
cpShapeFilter NOT_GRABBABLE_FILTER = {CP_NO_GROUP, ~GRABBABLE_MASK_BIT, ~GRABBABLE_MASK_BIT};
|
|
|
|
|
2021-06-23 14:25:44 +08:00
|
|
|
// cpVect view_translate = {0, 0};
|
|
|
|
// cpFloat view_scale = 1.0;
|
|
|
|
|
|
|
|
void ChipmunkDemoDefaultDrawImpl(cpSpace* space){};
|
|
|
|
|
|
|
|
void ChipmunkDebugDrawDot(cpFloat size, cpVect pos, cpSpaceDebugColor fillColor){};
|
|
|
|
cpSpaceDebugColor RGBAColor(float r, float g, float b, float a) {
|
|
|
|
cpSpaceDebugColor color = {r, g, b, a};
|
|
|
|
return color;
|
|
|
|
};
|
|
|
|
|
2021-06-16 19:34:09 +08:00
|
|
|
|
|
|
|
static void ShapeFreeWrap(cpSpace* space, cpShape* shape, void* unused) {
|
|
|
|
cpSpaceRemoveShape(space, shape);
|
|
|
|
cpShapeFree(shape);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PostShapeFree(cpShape* shape, cpSpace* space) {
|
|
|
|
cpSpaceAddPostStepCallback(space, (cpPostStepFunc) ShapeFreeWrap, shape, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ConstraintFreeWrap(cpSpace* space, cpConstraint* constraint, void* unused) {
|
|
|
|
cpSpaceRemoveConstraint(space, constraint);
|
|
|
|
cpConstraintFree(constraint);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PostConstraintFree(cpConstraint* constraint, cpSpace* space) {
|
|
|
|
cpSpaceAddPostStepCallback(space, (cpPostStepFunc) ConstraintFreeWrap, constraint, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void BodyFreeWrap(cpSpace* space, cpBody* body, void* unused) {
|
|
|
|
cpSpaceRemoveBody(space, body);
|
|
|
|
cpBodyFree(body);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PostBodyFree(cpBody* body, cpSpace* space) {
|
|
|
|
cpSpaceAddPostStepCallback(space, (cpPostStepFunc) BodyFreeWrap, body, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Safe and future proof way to remove and free all objects that have been added to the space.
|
|
|
|
void ChipmunkDemoFreeSpaceChildren(cpSpace* space) {
|
|
|
|
// Must remove these BEFORE freeing the body or you will access dangling pointers.
|
|
|
|
cpSpaceEachShape(space, (cpSpaceShapeIteratorFunc) PostShapeFree, space);
|
|
|
|
cpSpaceEachConstraint(space, (cpSpaceConstraintIteratorFunc) PostConstraintFree, space);
|
2021-06-24 00:04:29 +08:00
|
|
|
|
2021-06-16 19:34:09 +08:00
|
|
|
cpSpaceEachBody(space, (cpSpaceBodyIteratorFunc) PostBodyFree, space);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-23 14:25:44 +08:00
|
|
|
void updateMouseBody(void) {
|
|
|
|
cpVect new_point = cpvlerp(mouse_body->p, ChipmunkDemoMouse, 0.25f);
|
|
|
|
mouse_body->v = cpvmult(cpvsub(new_point, mouse_body->p), 60.0f);
|
|
|
|
mouse_body->p = new_point;
|
2021-06-16 19:34:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-23 14:25:44 +08:00
|
|
|
ChipmunkTestBed::ChipmunkTestBed() {
|
|
|
|
|
|
|
|
//// 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);
|
2021-06-16 19:34:09 +08:00
|
|
|
|
2021-06-23 14:25:44 +08:00
|
|
|
_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);
|
2021-06-16 19:34:09 +08:00
|
|
|
|
|
|
|
scheduleUpdate();
|
|
|
|
}
|
|
|
|
|
2021-06-23 14:25:44 +08:00
|
|
|
ChipmunkTestBed::~ChipmunkTestBed() {
|
2021-06-16 19:34:09 +08:00
|
|
|
ChipmunkDemoFreeSpaceChildren(_space);
|
2021-06-23 14:25:44 +08:00
|
|
|
|
2021-06-24 00:04:29 +08:00
|
|
|
// static Size resourceSize(960, 640);
|
|
|
|
// GLViewImpl* view = (GLViewImpl*) Director::getInstance()->getOpenGLView();
|
|
|
|
// view->setWindowed(resourceSize.width, resourceSize.height);
|
|
|
|
|
|
|
|
|
|
|
|
// auto director = Director::getInstance();
|
|
|
|
// auto glview = director->getOpenGLView();
|
|
|
|
// view->setDesignResolutionSize(orgSize.width, orgSize.height, ResolutionPolicy::NO_BORDER);
|
2021-06-23 14:25:44 +08:00
|
|
|
|
|
|
|
_eventDispatcher->removeEventListener(_mouseListener);
|
2021-06-16 19:34:09 +08:00
|
|
|
}
|
|
|
|
|
2021-06-23 14:25:44 +08:00
|
|
|
void ChipmunkTestBed::initPhysics() {
|
2021-06-16 19:34:09 +08:00
|
|
|
// Physics debug layer
|
|
|
|
_debugLayer = PhysicsDebugNode::create(_space);
|
|
|
|
this->addChild(_debugLayer, Z_PHYSICS_DEBUG);
|
|
|
|
}
|
|
|
|
|
2021-06-23 14:25:44 +08:00
|
|
|
void ChipmunkTestBed::update(float delta) {
|
2021-06-16 19:34:09 +08:00
|
|
|
#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
|
2021-06-23 14:25:44 +08:00
|
|
|
cpSpaceStep(_space, delta);
|
2021-06-16 19:34:09 +08:00
|
|
|
#else
|
2021-06-23 14:25:44 +08:00
|
|
|
cpHastySpaceStep(_space, delta);
|
2021-06-16 19:34:09 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-06-17 14:22:52 +08:00
|
|
|
void ChipmunkTestBed::createResetButton() {
|
2021-06-16 19:34:09 +08:00
|
|
|
auto reset = MenuItemImage::create("Images/r1.png", "Images/r2.png", CC_CALLBACK_1(ChipmunkTestBed::reset, this));
|
2021-06-23 14:25:44 +08:00
|
|
|
auto menu = Menu::create(reset, nullptr);
|
2021-06-16 19:34:09 +08:00
|
|
|
menu->setPosition(VisibleRect::center().x, VisibleRect::bottom().y + 30);
|
|
|
|
this->addChild(menu, -1);
|
|
|
|
}
|
|
|
|
|
2021-06-17 14:22:52 +08:00
|
|
|
void ChipmunkTestBed::reset(Ref* sender) {
|
2021-06-16 19:34:09 +08:00
|
|
|
ChipmunkDemoFreeSpaceChildren(_space);
|
|
|
|
getTestSuite()->restartCurrTest();
|
|
|
|
}
|
|
|
|
|
2021-06-17 14:22:52 +08:00
|
|
|
void ChipmunkTestBed::onEnter() {
|
|
|
|
TestCase::onEnter();
|
2021-06-24 00:04:29 +08:00
|
|
|
physicsDebugNodeOffset = VisibleRect::center();
|
2021-06-17 14:22:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-23 14:25:44 +08:00
|
|
|
void ChipmunkTestBed::onMouseDown(Event* event) {
|
|
|
|
EventMouse* e = (EventMouse*) event;
|
|
|
|
if ((int) e->getMouseButton() == 0) {
|
2021-06-24 00:04:29 +08:00
|
|
|
ChipmunkDemoLeftDown = cpTrue;
|
|
|
|
ChipmunkDemoRightDown = cpFalse;
|
2021-06-23 14:25:44 +08:00
|
|
|
|
|
|
|
// give the mouse click a little radius to make it easier to click small shapes.
|
|
|
|
cpFloat radius = 5.0;
|
|
|
|
|
|
|
|
cpPointQueryInfo info = {0};
|
|
|
|
cpShape* shape = cpSpacePointQueryNearest(_space, ChipmunkDemoMouse, radius, GRAB_FILTER, &info);
|
|
|
|
|
|
|
|
if (shape && cpBodyGetMass(cpShapeGetBody(shape)) < INFINITY) {
|
|
|
|
// Use the closest point on the surface if the click is outside of the shape.
|
|
|
|
cpVect nearest = (info.distance > 0.0f ? info.point : ChipmunkDemoMouse);
|
|
|
|
|
|
|
|
cpBody* body = cpShapeGetBody(shape);
|
|
|
|
mouse_joint = cpPivotJointNew2(mouse_body, body, cpvzero, cpBodyWorldToLocal(body, nearest));
|
|
|
|
mouse_joint->maxForce = 50000.0f;
|
|
|
|
mouse_joint->errorBias = cpfpow(1.0f - 0.15f, 60.0f);
|
|
|
|
cpSpaceAddConstraint(_space, mouse_joint);
|
|
|
|
}
|
|
|
|
} else if ((int) e->getMouseButton() == 1) {
|
|
|
|
|
|
|
|
if (mouse_joint) {
|
|
|
|
cpSpaceRemoveConstraint(_space, mouse_joint);
|
|
|
|
cpConstraintFree(mouse_joint);
|
|
|
|
mouse_joint = NULL;
|
|
|
|
}
|
|
|
|
|
2021-06-24 00:04:29 +08:00
|
|
|
ChipmunkDemoLeftDown = cpFalse;
|
|
|
|
ChipmunkDemoRightDown = cpTrue;
|
2021-06-23 14:25:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChipmunkTestBed::onMouseUp(Event* event) {
|
|
|
|
EventMouse* e = (EventMouse*) event;
|
|
|
|
|
|
|
|
ChipmunkDemoLeftDown = cpFalse;
|
|
|
|
|
|
|
|
if (mouse_joint) {
|
|
|
|
cpSpaceRemoveConstraint(_space, mouse_joint);
|
|
|
|
cpConstraintFree(mouse_joint);
|
|
|
|
mouse_joint = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChipmunkTestBed::onMouseMove(Event* event) {
|
|
|
|
EventMouse* e = (EventMouse*) event;
|
|
|
|
|
|
|
|
ChipmunkDemoMouse.x = e->getCursorX() - physicsDebugNodeOffset.x;
|
|
|
|
ChipmunkDemoMouse.y = e->getCursorY() - physicsDebugNodeOffset.y;
|
|
|
|
|
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-17 14:22:52 +08:00
|
|
|
//------------------------------------------------------------------
|
2021-06-16 19:34:09 +08:00
|
|
|
//
|
2021-06-18 15:47:48 +08:00
|
|
|
// LogoSmashDemo
|
2021-06-16 19:34:09 +08:00
|
|
|
//
|
2021-06-17 14:22:52 +08:00
|
|
|
//------------------------------------------------------------------
|
2021-06-18 15:47:48 +08:00
|
|
|
void LogoSmashDemo::onEnter() {
|
2021-06-17 14:22:52 +08:00
|
|
|
ChipmunkTestBed::onEnter();
|
|
|
|
initPhysics();
|
2021-06-18 15:47:48 +08:00
|
|
|
}
|
2021-06-17 14:22:52 +08:00
|
|
|
|
2021-06-18 15:47:48 +08:00
|
|
|
std::string LogoSmashDemo::title() const {
|
|
|
|
return LogoSmash.name;
|
|
|
|
}
|
2021-06-17 14:22:52 +08:00
|
|
|
|
2021-06-18 15:47:48 +08:00
|
|
|
void LogoSmashDemo::initPhysics() {
|
|
|
|
_space = LogoSmash.initFunc();
|
|
|
|
ChipmunkTestBed::initPhysics();
|
2021-06-17 14:22:52 +08:00
|
|
|
}
|
|
|
|
|
2021-06-18 15:47:48 +08:00
|
|
|
void LogoSmashDemo::update(float delta) {
|
2021-06-23 14:25:44 +08:00
|
|
|
updateMouseBody();
|
2021-06-18 15:47:48 +08:00
|
|
|
LogoSmash.updateFunc(_space, LogoSmash.timestep);
|
2021-06-17 14:22:52 +08:00
|
|
|
}
|
|
|
|
|
2021-06-18 15:47:48 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// PlinkDemo
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void PlinkDemo::onEnter() {
|
|
|
|
ChipmunkTestBed::onEnter();
|
2021-06-17 14:22:52 +08:00
|
|
|
|
2021-06-18 15:47:48 +08:00
|
|
|
initPhysics();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string PlinkDemo::title() const {
|
|
|
|
return Plink.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlinkDemo::initPhysics() {
|
|
|
|
_space = Plink.initFunc();
|
2021-06-17 14:22:52 +08:00
|
|
|
ChipmunkTestBed::initPhysics();
|
2021-06-18 15:47:48 +08:00
|
|
|
}
|
2021-06-17 14:22:52 +08:00
|
|
|
|
2021-06-18 15:47:48 +08:00
|
|
|
void PlinkDemo::update(float delta) {
|
2021-06-23 14:25:44 +08:00
|
|
|
updateMouseBody();
|
2021-06-18 15:47:48 +08:00
|
|
|
Plink.updateFunc(_space, Plink.timestep);
|
2021-06-17 14:22:52 +08:00
|
|
|
}
|
|
|
|
|
2021-06-18 15:47:48 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TumbleDemo
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void TumbleDemo::onEnter() {
|
|
|
|
ChipmunkTestBed::onEnter();
|
|
|
|
initPhysics();
|
2021-06-17 14:22:52 +08:00
|
|
|
}
|
|
|
|
|
2021-06-18 15:47:48 +08:00
|
|
|
std::string TumbleDemo::title() const {
|
|
|
|
return Tumble.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TumbleDemo::initPhysics() {
|
|
|
|
_space = Tumble.initFunc();
|
|
|
|
ChipmunkTestBed::initPhysics();
|
|
|
|
}
|
2021-06-17 14:22:52 +08:00
|
|
|
|
2021-06-18 15:47:48 +08:00
|
|
|
void TumbleDemo::update(float delta) {
|
2021-06-23 14:25:44 +08:00
|
|
|
updateMouseBody();
|
2021-06-18 15:47:48 +08:00
|
|
|
Tumble.updateFunc(_space, Tumble.timestep);
|
|
|
|
}
|
2021-06-17 14:22:52 +08:00
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
2021-06-16 19:34:09 +08:00
|
|
|
//
|
2021-06-18 15:47:48 +08:00
|
|
|
// PyramidStackDemo
|
2021-06-16 19:34:09 +08:00
|
|
|
//
|
2021-06-17 14:22:52 +08:00
|
|
|
//------------------------------------------------------------------
|
2021-06-18 15:47:48 +08:00
|
|
|
void PyramidStackDemo::onEnter() {
|
2021-06-17 14:22:52 +08:00
|
|
|
ChipmunkTestBed::onEnter();
|
|
|
|
initPhysics();
|
2021-06-18 15:47:48 +08:00
|
|
|
}
|
2021-06-17 14:22:52 +08:00
|
|
|
|
2021-06-18 15:47:48 +08:00
|
|
|
std::string PyramidStackDemo::title() const {
|
|
|
|
return PyramidStack.name;
|
|
|
|
}
|
2021-06-17 14:22:52 +08:00
|
|
|
|
2021-06-18 15:47:48 +08:00
|
|
|
void PyramidStackDemo::initPhysics() {
|
|
|
|
_space = PyramidStack.initFunc();
|
|
|
|
ChipmunkTestBed::initPhysics();
|
2021-06-17 14:22:52 +08:00
|
|
|
}
|
|
|
|
|
2021-06-18 15:47:48 +08:00
|
|
|
void PyramidStackDemo::update(float delta) {
|
2021-06-23 14:25:44 +08:00
|
|
|
updateMouseBody();
|
2021-06-18 15:47:48 +08:00
|
|
|
PyramidStack.updateFunc(_space, PyramidStack.timestep);
|
2021-06-17 14:22:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-18 15:47:48 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// PyramidToppleDemo
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void PyramidToppleDemo::onEnter() {
|
|
|
|
ChipmunkTestBed::onEnter();
|
|
|
|
initPhysics();
|
|
|
|
}
|
2021-06-17 14:22:52 +08:00
|
|
|
|
2021-06-18 15:47:48 +08:00
|
|
|
std::string PyramidToppleDemo::title() const {
|
|
|
|
return PyramidTopple.name;
|
2021-06-17 14:22:52 +08:00
|
|
|
}
|
|
|
|
|
2021-06-18 15:47:48 +08:00
|
|
|
void PyramidToppleDemo::initPhysics() {
|
|
|
|
_space = PyramidTopple.initFunc();
|
|
|
|
ChipmunkTestBed::initPhysics();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PyramidToppleDemo::update(float delta) {
|
2021-06-23 14:25:44 +08:00
|
|
|
updateMouseBody();
|
2021-06-18 15:47:48 +08:00
|
|
|
PyramidTopple.updateFunc(_space, PyramidTopple.timestep);
|
2021-06-17 14:22:52 +08:00
|
|
|
}
|
2021-06-18 15:47:48 +08:00
|
|
|
|
2021-06-17 14:22:52 +08:00
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
2021-06-16 19:34:09 +08:00
|
|
|
//
|
2021-06-18 15:47:48 +08:00
|
|
|
// ChainDemo
|
2021-06-16 19:34:09 +08:00
|
|
|
//
|
2021-06-17 14:22:52 +08:00
|
|
|
//------------------------------------------------------------------
|
2021-06-18 15:47:48 +08:00
|
|
|
void ChainsDemo::onEnter() {
|
2021-06-17 14:22:52 +08:00
|
|
|
ChipmunkTestBed::onEnter();
|
2021-06-16 19:34:09 +08:00
|
|
|
|
2021-06-17 14:22:52 +08:00
|
|
|
initPhysics();
|
2021-06-18 15:47:48 +08:00
|
|
|
}
|
2021-06-17 14:22:52 +08:00
|
|
|
|
2021-06-18 15:47:48 +08:00
|
|
|
std::string ChainsDemo::title() const {
|
|
|
|
return Chains.name;
|
|
|
|
}
|
2021-06-17 14:22:52 +08:00
|
|
|
|
2021-06-18 15:47:48 +08:00
|
|
|
void ChainsDemo::initPhysics() {
|
|
|
|
_space = Chains.initFunc();
|
|
|
|
ChipmunkTestBed::initPhysics();
|
2021-06-16 19:34:09 +08:00
|
|
|
}
|
|
|
|
|
2021-06-18 15:47:48 +08:00
|
|
|
void ChainsDemo::update(float delta) {
|
2021-06-23 14:25:44 +08:00
|
|
|
updateMouseBody();
|
2021-06-18 15:47:48 +08:00
|
|
|
Chains.updateFunc(_space, Chains.timestep);
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// OneWayDemo
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void OneWayDemo::onEnter() {
|
|
|
|
ChipmunkTestBed::onEnter();
|
|
|
|
|
|
|
|
initPhysics();
|
2021-06-17 14:22:52 +08:00
|
|
|
}
|
2021-06-16 19:34:09 +08:00
|
|
|
|
2021-06-18 15:47:48 +08:00
|
|
|
std::string OneWayDemo::title() const {
|
|
|
|
return OneWay.name;
|
|
|
|
}
|
2021-06-16 19:34:09 +08:00
|
|
|
|
2021-06-18 15:47:48 +08:00
|
|
|
void OneWayDemo::initPhysics() {
|
|
|
|
_space = OneWay.initFunc();
|
2021-06-17 14:22:52 +08:00
|
|
|
ChipmunkTestBed::initPhysics();
|
2021-06-16 19:34:09 +08:00
|
|
|
}
|
|
|
|
|
2021-06-18 15:47:48 +08:00
|
|
|
void OneWayDemo::update(float delta) {
|
2021-06-23 14:25:44 +08:00
|
|
|
updateMouseBody();
|
2021-06-18 15:47:48 +08:00
|
|
|
OneWay.updateFunc(_space, OneWay.timestep);
|
2021-06-17 14:22:52 +08:00
|
|
|
}
|
|
|
|
|
2021-06-23 14:25:44 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// PlanetDemo
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void PlanetDemo::onEnter() {
|
|
|
|
ChipmunkTestBed::onEnter();
|
|
|
|
|
|
|
|
initPhysics();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string PlanetDemo::title() const {
|
|
|
|
return Planet.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlanetDemo::initPhysics() {
|
|
|
|
_space = Planet.initFunc();
|
|
|
|
ChipmunkTestBed::initPhysics();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlanetDemo::update(float delta) {
|
|
|
|
updateMouseBody();
|
|
|
|
Planet.updateFunc(_space, Planet.timestep);
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TheoJansenDemo
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void TheoJansenDemo::onEnter() {
|
|
|
|
ChipmunkTestBed::onEnter();
|
|
|
|
|
|
|
|
initPhysics();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TheoJansenDemo::title() const {
|
|
|
|
return TheoJansen.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TheoJansenDemo::initPhysics() {
|
|
|
|
_space = TheoJansen.initFunc();
|
|
|
|
ChipmunkTestBed::initPhysics();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TheoJansenDemo::update(float delta) {
|
|
|
|
updateMouseBody();
|
|
|
|
TheoJansen.updateFunc(_space, TheoJansen.timestep);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TankDemo
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void TankDemo::onEnter() {
|
|
|
|
ChipmunkTestBed::onEnter();
|
|
|
|
|
|
|
|
initPhysics();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TankDemo::title() const {
|
|
|
|
return Tank.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TankDemo::initPhysics() {
|
|
|
|
_space = Tank.initFunc();
|
|
|
|
ChipmunkTestBed::initPhysics();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TankDemo::update(float delta) {
|
|
|
|
updateMouseBody();
|
|
|
|
Tank.updateFunc(_space, Tank.timestep);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// BouncyHexagonsDemo
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2021-06-24 00:04:29 +08:00
|
|
|
// void BouncyHexagonsDemo::onEnter() {
|
|
|
|
// ChipmunkTestBed::onEnter();
|
2021-06-23 14:25:44 +08:00
|
|
|
//
|
2021-06-24 00:04:29 +08:00
|
|
|
// initPhysics();
|
|
|
|
//}
|
2021-06-23 14:25:44 +08:00
|
|
|
//
|
2021-06-24 00:04:29 +08:00
|
|
|
// std::string BouncyHexagonsDemo::title() const {
|
|
|
|
// return BouncyHexagons.name;
|
|
|
|
//}
|
2021-06-23 14:25:44 +08:00
|
|
|
//
|
2021-06-24 00:04:29 +08:00
|
|
|
// void BouncyHexagonsDemo::initPhysics() {
|
|
|
|
// _space = BouncyHexagons.initFunc();
|
|
|
|
// ChipmunkTestBed::initPhysics();
|
|
|
|
//}
|
2021-06-23 14:25:44 +08:00
|
|
|
//
|
2021-06-24 00:04:29 +08:00
|
|
|
// void BouncyHexagonsDemo::update(float delta) {
|
|
|
|
// BouncyHexagons.updateFunc(_space, BouncyHexagons.timestep);
|
|
|
|
//}
|
2021-06-23 23:09:48 +08:00
|
|
|
|
2021-06-18 15:47:48 +08:00
|
|
|
|
2021-06-17 14:22:52 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
2021-06-24 00:04:29 +08:00
|
|
|
// SpringiesDemo
|
2021-06-23 23:09:48 +08:00
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2021-06-24 00:04:29 +08:00
|
|
|
// void SpringiesDemo::onEnter() {
|
|
|
|
// ChipmunkTestBed::onEnter();
|
2021-06-23 23:09:48 +08:00
|
|
|
//
|
2021-06-24 00:04:29 +08:00
|
|
|
// initPhysics();
|
|
|
|
//}
|
2021-06-23 23:09:48 +08:00
|
|
|
//
|
2021-06-24 00:04:29 +08:00
|
|
|
// std::string SpringiesDemo::title() const {
|
|
|
|
// return Springies.name;
|
|
|
|
//}
|
2021-06-23 23:09:48 +08:00
|
|
|
//
|
2021-06-24 00:04:29 +08:00
|
|
|
// void SpringiesDemo::initPhysics() {
|
|
|
|
// _space = Springies.initFunc();
|
|
|
|
// ChipmunkTestBed::initPhysics();
|
|
|
|
//}
|
2021-06-23 23:09:48 +08:00
|
|
|
//
|
2021-06-24 00:04:29 +08:00
|
|
|
// void SpringiesDemo::update(float delta) {
|
|
|
|
// Springies.updateFunc(_space, Springies.timestep);
|
|
|
|
//}
|
2021-06-23 23:09:48 +08:00
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
2021-06-24 00:04:29 +08:00
|
|
|
// Add Example
|
2021-06-23 23:09:48 +08:00
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2021-06-24 00:04:29 +08:00
|
|
|
void AddExample::onEnter() {
|
2021-06-23 23:09:48 +08:00
|
|
|
ChipmunkTestBed::onEnter();
|
|
|
|
|
2021-06-24 00:04:29 +08:00
|
|
|
_space = cpSpaceNew();
|
2021-06-23 23:09:48 +08:00
|
|
|
ChipmunkTestBed::initPhysics();
|
|
|
|
|
2021-06-24 00:04:29 +08:00
|
|
|
log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str());
|
2021-06-23 23:09:48 +08:00
|
|
|
}
|
|
|
|
|
2021-06-24 00:04:29 +08:00
|
|
|
std::string AddExample::title() const {
|
|
|
|
return " Here is the place for your\n Chipmunk2D example";
|
2021-06-23 23:09:48 +08:00
|
|
|
}
|
|
|
|
|
2021-06-24 00:04:29 +08:00
|
|
|
void AddExample::initPhysics() {
|
|
|
|
_space = cpSpaceNew();
|
2021-06-23 23:09:48 +08:00
|
|
|
ChipmunkTestBed::initPhysics();
|
|
|
|
|
2021-06-24 00:04:29 +08:00
|
|
|
log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str());
|
2021-06-23 23:09:48 +08:00
|
|
|
}
|
|
|
|
|
2021-06-24 00:04:29 +08:00
|
|
|
void AddExample::update(float delta) {
|
|
|
|
cpSpaceStep(_space, delta);
|
2021-06-16 19:34:09 +08:00
|
|
|
}
|
|
|
|
|
2021-06-17 14:22:52 +08:00
|
|
|
|
|
|
|
ChipmunkTestBedTests::ChipmunkTestBedTests() {
|
2021-06-18 15:47:48 +08:00
|
|
|
|
|
|
|
ADD_TEST_CASE(LogoSmashDemo);
|
|
|
|
ADD_TEST_CASE(PlinkDemo);
|
|
|
|
ADD_TEST_CASE(TumbleDemo);
|
|
|
|
ADD_TEST_CASE(PyramidToppleDemo);
|
|
|
|
ADD_TEST_CASE(PyramidStackDemo);
|
|
|
|
ADD_TEST_CASE(ChainsDemo);
|
|
|
|
ADD_TEST_CASE(OneWayDemo);
|
2021-06-23 14:25:44 +08:00
|
|
|
ADD_TEST_CASE(PlanetDemo);
|
|
|
|
ADD_TEST_CASE(TheoJansenDemo);
|
|
|
|
ADD_TEST_CASE(TankDemo);
|
2021-06-24 00:04:29 +08:00
|
|
|
// ADD_TEST_CASE(BouncyHexagonsDemo);
|
|
|
|
// ADD_TEST_CASE(SpringiesDemo);
|
2021-06-17 14:22:52 +08:00
|
|
|
|
2021-06-24 00:04:29 +08:00
|
|
|
ADD_TEST_CASE(AddExample);
|
2021-06-17 14:22:52 +08:00
|
|
|
}
|