cleanup and improvement

This commit is contained in:
aismann 2021-08-18 04:16:21 +02:00
parent bd4d07b86e
commit 288941a63f
46 changed files with 323 additions and 347 deletions

View File

@ -677,6 +677,29 @@ void DrawNode::drawSolidPoly(const Vec2 *poli, unsigned int numberOfPoints, cons
drawPolygon(poli, numberOfPoints, color, 0.0, Color4F());
}
void DrawNode::drawSolidCircle(const Vec2& center, float radius, float angle, unsigned int segments, float scaleX, float scaleY, const Color4F& fillColor, float borderWidth, const Color4F& borderColor)
{
const float coef = 2.0f * (float)M_PI / segments;
Vec2* vertices = new (std::nothrow) Vec2[segments];
if (!vertices)
return;
for (unsigned int i = 0; i < segments; i++)
{
float rads = i * coef;
float j = radius * cosf(rads + angle) * scaleX + center.x;
float k = radius * sinf(rads + angle) * scaleY + center.y;
vertices[i].x = j;
vertices[i].y = k;
}
drawPolygon(vertices, segments, fillColor, borderWidth, borderColor);
CC_SAFE_DELETE_ARRAY(vertices);
}
void DrawNode::drawSolidCircle(const Vec2& center, float radius, float angle, unsigned int segments, float scaleX, float scaleY, const Color4F &color)
{
const float coef = 2.0f * (float)M_PI/segments;
@ -700,6 +723,9 @@ void DrawNode::drawSolidCircle(const Vec2& center, float radius, float angle, un
CC_SAFE_DELETE_ARRAY(vertices);
}
void DrawNode::drawSolidCircle( const Vec2& center, float radius, float angle, unsigned int segments, const Color4F& color)
{
drawSolidCircle(center, radius, angle, segments, 1.0f, 1.0f, color);

View File

@ -215,6 +215,20 @@ public:
* @js NA
*/
void drawSolidPoly(const Vec2 *poli, unsigned int numberOfPoints, const Color4F &color);
/** Draws a solid circle given the center, radius and number of segments.
* @param center The circle center point.
* @param radius The circle rotate of radius.
* @param angle The circle angle.
* @param segments The number of segments.
* @param scaleX The scale value in x.
* @param scaleY The scale value in y.
* @param fillColor The color will fill in polygon.
* @param borderWidth The border of line width.
* @param borderColor The border of line color.
* @js NA
*/
void drawSolidCircle(const Vec2& center, float radius, float angle, unsigned int segments, float scaleX, float scaleY, const Color4F& fillColor, float borderWidth, const Color4F& borderColor);
/** Draws a solid circle given the center, radius and number of segments.
* @param center The circle center point.

View File

@ -16,23 +16,9 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <stdbool.h>
#include <limits.h>
#include "CCPhysicsDebugNodeBox2D.h"
USING_NS_CC;
#if defined(CC_PLATFORM_PC)
extern cocos2d::Label* labelDebugDraw;
#endif
NS_CC_EXT_BEGIN
#define BUFFER_OFFSET(x) ((const void*) (x))
@ -47,11 +33,6 @@ DebugDraw::~DebugDraw()
{
}
void DebugDraw::initShader(void)
{
// initShader is unsupported
}
cocos2d::DrawNode* DebugDraw::GetDrawNode()
{
return drawBP;
@ -59,7 +40,6 @@ cocos2d::DrawNode* DebugDraw::GetDrawNode()
void DebugDraw::SetDrawNode(cocos2d::DrawNode* drawNode)
{
CCASSERT(!drawBP, "drawBP is not NULL");
drawBP = drawNode;
}
@ -75,7 +55,6 @@ void DebugDraw::DrawPolygon(const b2Vec2* verts, int vertexCount, const b2Color&
for (size_t i = 0; i < vertexCount; i++) {
vec[i] = Vec2(verts[i].x * mRatio, verts[i].y * mRatio) + debugNodeOffset;
}
// drawBP->drawPolygon(vec, vertexCount, Color4F(color.r, color.g, color.b, color.a), 1, Color4F(color.r, color.g, color.b, color.a));
drawBP->drawPolygon(vec, vertexCount, Color4F::BLACK, 0.4f, Color4F(color.r, color.g, color.b, color.a));
}
@ -86,7 +65,6 @@ void DebugDraw::DrawSolidPolygon(const b2Vec2* verts, int vertexCount, const b2C
vec[i] = Vec2(verts[i].x * mRatio, verts[i].y * mRatio) + debugNodeOffset;
}
drawBP->drawPolygon(vec, vertexCount, Color4F(color.r / 2, color.g / 2, color.b / 2, color.a), 0.4f, Color4F(color.r, color.g, color.b, color.a));
//drawBP->drawSolidPoly(vec, vertexCount, Color4F(color.r, color.g, color.b, color.a));
}
void DebugDraw::DrawCircle(const b2Vec2& center, float radius, const b2Color& color)
@ -97,9 +75,8 @@ void DebugDraw::DrawCircle(const b2Vec2& center, float radius, const b2Color& co
void DebugDraw::DrawSolidCircle(const b2Vec2& center, float radius, const b2Vec2& axis, const b2Color& color)
{
// DrawSolidCircle Maybe have to fix later
Vec2 c = { Vec2(center.x * mRatio, center.y * mRatio) + debugNodeOffset };
drawBP->drawCircle(c, radius * mRatio, CC_DEGREES_TO_RADIANS(0), 20, false, 1.0f, 1.0f, Color4F(color.r, color.g, color.b, color.a));
drawBP->drawSolidCircle(c, radius * mRatio, CC_DEGREES_TO_RADIANS(0), 20, 1.0f, 1.0f, Color4F(color.r / 2, color.g / 2, color.b / 2, color.a), 0.4f, Color4F(color.r, color.g, color.b, color.a));
// Draw a line fixed in the circle to animate rotation.
b2Vec2 pp = { (center + radius * axis) };
@ -128,45 +105,4 @@ void DebugDraw::DrawPoint(const b2Vec2& p, float size, const b2Color& color)
drawBP->drawPoint(Vec2(p.x * mRatio, p.y * mRatio) + debugNodeOffset, size, Color4F(color.r, color.g, color.b, color.a));
}
void DebugDraw::DrawString(int x, int y, const char* fmt, ...)
{
#if defined(CC_PLATFORM_PC)
debugString.append(std::string(fmt));
debugString.append("\n");
labelDebugDraw->setString(debugString);
// labelDebugDraw->setPosition(x, y);
#endif
}
void DebugDraw::DrawString(const b2Vec2& pw, const char* fmt, ...)
{
#if defined(CC_PLATFORM_PC)
debugString.append(std::string(fmt));
debugString.append("\n");
labelDebugDraw->setString(debugString);
// labelDebugDraw->setPosition(pw.x, pw.y);
#endif
}
void DebugDraw::DrawAABB(b2AABB* aabb, const b2Color& color)
{
b2Vec2 p1 = aabb->lowerBound;
b2Vec2 p2 = b2Vec2(aabb->upperBound.x, aabb->lowerBound.y);
b2Vec2 p3 = aabb->upperBound;
b2Vec2 p4 = b2Vec2(aabb->lowerBound.x, aabb->upperBound.y);
Vec2 verts[] = {
Vec2(p1.x * mRatio, p1.y * mRatio) + debugNodeOffset ,
Vec2(p2.x * mRatio, p2.y * mRatio) + debugNodeOffset ,
Vec2(p3.x * mRatio, p3.y * mRatio) + debugNodeOffset ,
Vec2(p4.x * mRatio, p4.y * mRatio) + debugNodeOffset ,
};
drawBP->drawPolygon(verts, sizeof(verts) / sizeof(verts[0]), Color4F(color.r / 2, color.g / 2, color.b / 2, 0), 0.4f, Color4F(color.r, color.g, color.b, color.a));
}
void DebugDraw::Flush()
{
// Flush is unsupported
}
NS_CC_EXT_END

View File

@ -20,25 +20,21 @@
#ifndef __PHYSICSNODES_DEBUGNODE_BOX2D_H__
#define __PHYSICSNODES_DEBUGNODE_BOX2D_H__
#define GLFW_INCLUDE_NONE
#include "extensions/ExtensionMacros.h"
#include "2d/CCDrawNode.h"
#include "extensions/ExtensionExport.h"
#include "2d/CCDrawNode.h"
#include "box2d/box2d.h"
#include "cocos2d.h"
NS_CC_EXT_BEGIN
// This class implements debug drawing callbacks that are invoked
// inside b2World::Step.
//PhysicsDebugNode : public DrawNode
// This class implements debug drawing callbacks that are invoked inside b2World::Step.
class CC_EX_DLL DebugDraw : public b2Draw
{
public:
void initShader( void );
DebugDraw();
~DebugDraw();
@ -60,28 +56,19 @@ public:
void DrawPoint(const b2Vec2& p, float size, const b2Color& color) override;
void DrawString(int x, int y, const char* fmt, ...);
void DrawString(const b2Vec2& p, const char* fmt, ...);
void DrawAABB(b2AABB* aabb, const b2Color& color);
void Flush();
// adxe stuffs
cocos2d::DrawNode* GetDrawNode();
void SetDrawNode(cocos2d::DrawNode* drawNode);
cocos2d::Vec2& GetDebugNodeOffset();
float mRatio;
cocos2d::DrawNode* drawBP = NULL;
std::string debugString = "";
cocos2d::DrawNode* drawBP = NULL; // adxe "interface"!
cocos2d::Vec2 debugNodeOffset;
float mRatio;
private:
};
#endif //__PHYSICSNODES_DEBUGNODE_BOX2D_H__
NS_CC_EXT_END
#endif //__PHYSICSNODES_DEBUGNODE_BOX2D_H__

View File

@ -59,7 +59,7 @@ private:
cocos2d::Texture2D* _spriteTexture;
cocos2d::DrawNode* drawBox2D;
DebugDraw g_debugDraw;
cocos2d::extension::DebugDraw g_debugDraw;
bool showDebugDraw = true;
} ;

View File

@ -23,11 +23,13 @@
****************************************************************************/
#include "platform/CCPlatformConfig.h"
#include "Box2DTestBed.h"
#include "extensions/cocos-ext.h"
#include "ImGuiEXT/CCImGuiEXT.h"
#include "cocos2d.h"
#include "Box2DTestBed.h"
#include "tests/test.h"
#include "tests/settings.h"
#include "ImGuiEXT/CCImGuiEXT.h"
USING_NS_CC;
USING_NS_CC_EXT;
@ -36,16 +38,7 @@ enum {
kTagParentNode = 1,
};
#define kAccelerometerFrequency 30
#define FRAMES_BETWEEN_PRESSES_FOR_DOUBLE_CLICK 10
#define PTM_RATIO 32
Settings settings;
cocos2d::Label* labelDebugDraw;
enum
@ -123,15 +116,11 @@ bool Box2DTestBed::initWithEntryID(int entryId)
m_test->debugDrawNode = debugDrawNode;
m_test->g_debugDraw = g_debugDraw;
TestCase::addChild(debugDrawNode, 100);
// init physics
this->initPhysics();
auto label = Label::createWithTTF(m_entry->name, "fonts/arial.ttf", 28);
TestCase::addChild(label, 1);
label->setPosition(visibleOrigin.x + visibleSize.width / 2, visibleOrigin.y + visibleSize.height - 50);
@ -142,14 +131,20 @@ bool Box2DTestBed::initWithEntryID(int entryId)
_touchListener->onTouchBegan = CC_CALLBACK_2(Box2DTestBed::onTouchBegan, this);
_touchListener->onTouchMoved = CC_CALLBACK_2(Box2DTestBed::onTouchMoved, this);
_touchListener->onTouchEnded = CC_CALLBACK_2(Box2DTestBed::onTouchEnded, this);
TestCase::_eventDispatcher->addEventListenerWithFixedPriority(_touchListener,1);
TestCase::_eventDispatcher->addEventListenerWithFixedPriority(_touchListener,10);
// Adds Keyboard event listener
_keyboardListener = EventListenerKeyboard::create();
_keyboardListener->onKeyPressed = CC_CALLBACK_2(Box2DTestBed::onKeyPressed, this);
_keyboardListener->onKeyReleased = CC_CALLBACK_2(Box2DTestBed::onKeyReleased, this);
TestCase::_eventDispatcher->addEventListenerWithFixedPriority(_keyboardListener,1);
TestCase::_eventDispatcher->addEventListenerWithFixedPriority(_keyboardListener,11);
auto _mouseListener = EventListenerMouse::create();
_mouseListener->onMouseMove = CC_CALLBACK_1(Box2DTestBed::onMouseMove, this);
_mouseListener->onMouseUp = CC_CALLBACK_1(Box2DTestBed::onMouseUp, this);
_mouseListener->onMouseDown = CC_CALLBACK_1(Box2DTestBed::onMouseDown, this);
_mouseListener->onMouseScroll = CC_CALLBACK_1(Box2DTestBed::onMouseScroll, this);
TestCase::_eventDispatcher->addEventListenerWithFixedPriority(_mouseListener, 12);
// Demo messageString
labelDebugDraw = Label::createWithTTF("TEST", "fonts/arial.ttf", 8.0f);
@ -165,7 +160,6 @@ bool Box2DTestBed::initWithEntryID(int entryId)
bool Box2DTestBed::onTouchBegan(Touch* touch, Event* event)
{
CCLOG("onTouchBegan");
auto location = touch->getLocation() - g_debugDraw.debugNodeOffset;
b2Vec2 pos = { location.x / g_debugDraw.mRatio, location.y / g_debugDraw.mRatio };
return m_test->MouseDown(pos);
@ -173,36 +167,77 @@ bool Box2DTestBed::onTouchBegan(Touch* touch, Event* event)
void Box2DTestBed::onTouchMoved(Touch* touch, Event* event)
{
CCLOG("onTouchMoved");
auto location = touch->getLocation() - g_debugDraw.debugNodeOffset;
b2Vec2 pos = { location.x / g_debugDraw.mRatio, location.y / g_debugDraw.mRatio };
m_test->MouseMove(pos);
}
void Box2DTestBed::onTouchEnded(Touch* touch, Event* event)
{
CCLOG("onTouchEnded");
auto location = touch->getLocation() - g_debugDraw.debugNodeOffset;
b2Vec2 pos = { location.x / g_debugDraw.mRatio, location.y / g_debugDraw.mRatio };
m_test->MouseUp(pos);
}
void Box2DTestBed::onKeyPressed(EventKeyboard::KeyCode code, Event* event)
{
CCLOG("onKeyPressed, keycode: %d", static_cast<int>(code));
m_test->Keyboard((static_cast<int>(code) - 59));
m_test->Keyboard((static_cast<int>(code) - 59)); // its a bad hack!
}
void Box2DTestBed::onKeyReleased(EventKeyboard::KeyCode code, Event* event)
{
CCLOG("onKeyPressed, keycode: %d", static_cast<int>(code));
m_test->KeyboardUp((static_cast<int>(code) - 59));
m_test->KeyboardUp((static_cast<int>(code) - 59)); // its a bad hack!
}
void Box2DTestBed::onMouseDown(Event* event)
{
EventMouse* e = (EventMouse*)event;
switch (e->getMouseButton())
{
button[(int)EventMouse::MouseButton::BUTTON_LEFT] = false;
button[(int)EventMouse::MouseButton::BUTTON_RIGHT] = false;
button[(int)EventMouse::MouseButton::BUTTON_MIDDLE] = false;
case EventMouse::MouseButton::BUTTON_LEFT:
button[(int)EventMouse::MouseButton::BUTTON_LEFT] = true;
break;
case EventMouse::MouseButton::BUTTON_RIGHT:
button[(int)EventMouse::MouseButton::BUTTON_RIGHT] = true;
break;
case EventMouse::MouseButton::BUTTON_MIDDLE:
button[(int)EventMouse::MouseButton::BUTTON_MIDDLE] = true;
break;
}
}
void Box2DTestBed::onMouseUp(Event* event)
{
button[(int)EventMouse::MouseButton::BUTTON_LEFT] = false;
button[(int)EventMouse::MouseButton::BUTTON_RIGHT] = false;
button[(int)EventMouse::MouseButton::BUTTON_MIDDLE] = false;
}
void Box2DTestBed::onMouseMove(Event* event)
{
EventMouse* e = (EventMouse*)event;
pos = { e->getCursorX() / g_debugDraw.mRatio , e->getCursorY() / g_debugDraw.mRatio };
if (button[(int)EventMouse::MouseButton::BUTTON_RIGHT])
{
(pos.x > oldPos.x) ? g_debugDraw.debugNodeOffset.x += 4 : g_debugDraw.debugNodeOffset.x -= 4;
(pos.y < oldPos.y) ? g_debugDraw.debugNodeOffset.y -= 2 : g_debugDraw.debugNodeOffset.y += 2;
}
oldPos = pos;
}
void Box2DTestBed::onMouseScroll(Event* event)
{
EventMouse* e = (EventMouse*)event;
g_debugDraw.mRatio += e->getScrollY();
}
void Box2DTestBed::onEnter()
{
Scene::onEnter();
@ -213,13 +248,12 @@ void Box2DTestBed::onExit()
{
Scene::onExit();
ImGuiEXT::getInstance()->removeRenderLoop("#im01");
}
void Box2DTestBed::update(float dt)
{
// Debug draw
m_test->g_debugDraw.debugString = "";
m_test->debugString = "";
labelDebugDraw->setString("");
debugDrawNode->clear();
m_test->Step(settings);
@ -234,7 +268,7 @@ void Box2DTestBed::initPhysics()
flags += 0 * b2Draw::e_aabbBit;
flags += 0 * b2Draw::e_centerOfMassBit;
g_debugDraw.SetFlags(flags);
g_debugDraw.mRatio = PTM_RATIO / 4;
g_debugDraw.mRatio = 8;
m_test->m_world->SetDebugDraw(&g_debugDraw);
m_test->g_debugDraw = g_debugDraw;
g_debugDraw.debugNodeOffset = { 250, 70 };

View File

@ -28,8 +28,6 @@
#include "cocos2d.h"
#include "box2d/box2d.h"
#include "../BaseTest.h"
#include "renderer/CCCustomCommand.h"
DEFINE_TEST_SUITE(Box2DTestBedTests);
@ -76,6 +74,11 @@ public:
void onKeyPressed(cocos2d::EventKeyboard::KeyCode code, cocos2d::Event* event) override;
void onKeyReleased(cocos2d::EventKeyboard::KeyCode code, cocos2d::Event* event) override;
void onMouseDown(cocos2d::Event* event);
void onMouseUp(cocos2d::Event* event);
void onMouseMove(cocos2d::Event* event);
void onMouseScroll(cocos2d::Event* event);
cocos2d::EventListenerTouchOneByOne* _touchListener;
cocos2d::EventListenerKeyboard* _keyboardListener;
@ -88,9 +91,13 @@ private:
b2World* world;
cocos2d::Texture2D* _spriteTexture;
b2Vec2 pos;
b2Vec2 oldPos;
bool button[2];
// Debug stuff
cocos2d::DrawNode* debugDrawNode;
DebugDraw g_debugDraw;
cocos2d::extension::DebugDraw g_debugDraw;
};

View File

@ -22,6 +22,12 @@
#include <stdio.h>
USING_NS_CC;
USING_NS_CC_EXT;
#if defined(CC_PLATFORM_PC)
extern cocos2d::Label* labelDebugDraw;
#endif
void DestructionListener::SayGoodbye(b2Joint * joint)
{
@ -104,7 +110,7 @@ void Test::PreSolve(b2Contact * contact, const b2Manifold * oldManifold)
void Test::DrawTitle(const char* string)
{
g_debugDraw.DrawString(5, 5, string);
DrawString(5, 5, string);
m_textLine = int32(26.0f);
}
@ -291,8 +297,8 @@ void Test::Step(Settings& settings)
timeStep = 0.0f;
}
g_debugDraw.DrawString(5, m_textLine, "****PAUSED****");
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "****PAUSED****");
}
uint32 flags = 0;
@ -323,15 +329,15 @@ void Test::Step(Settings& settings)
int32 bodyCount = m_world->GetBodyCount();
int32 contactCount = m_world->GetContactCount();
int32 jointCount = m_world->GetJointCount();
g_debugDraw.DrawString(5, m_textLine, "bodies/contacts/joints = %d/%d/%d", bodyCount, contactCount, jointCount);
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "bodies/contacts/joints = %d/%d/%d", bodyCount, contactCount, jointCount);
int32 proxyCount = m_world->GetProxyCount();
int32 height = m_world->GetTreeHeight();
int32 balance = m_world->GetTreeBalance();
float quality = m_world->GetTreeQuality();
g_debugDraw.DrawString(5, m_textLine, "proxies/height/balance/quality = %d/%d/%d/%g", proxyCount, height, balance, quality);
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "proxies/height/balance/quality = %d/%d/%d/%g", proxyCount, height, balance, quality);
}
// Track maximum profile times
@ -375,22 +381,14 @@ void Test::Step(Settings& settings)
aveProfile.broadphase = scale * m_totalProfile.broadphase;
}
g_debugDraw.DrawString(5, m_textLine, "step [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.step, aveProfile.step, m_maxProfile.step);
m_textLine += m_textIncrement;
g_debugDraw.DrawString(5, m_textLine, "collide [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.collide, aveProfile.collide, m_maxProfile.collide);
m_textLine += m_textIncrement;
g_debugDraw.DrawString(5, m_textLine, "solve [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.solve, aveProfile.solve, m_maxProfile.solve);
m_textLine += m_textIncrement;
g_debugDraw.DrawString(5, m_textLine, "solve init [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.solveInit, aveProfile.solveInit, m_maxProfile.solveInit);
m_textLine += m_textIncrement;
g_debugDraw.DrawString(5, m_textLine, "solve velocity [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.solveVelocity, aveProfile.solveVelocity, m_maxProfile.solveVelocity);
m_textLine += m_textIncrement;
g_debugDraw.DrawString(5, m_textLine, "solve position [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.solvePosition, aveProfile.solvePosition, m_maxProfile.solvePosition);
m_textLine += m_textIncrement;
g_debugDraw.DrawString(5, m_textLine, "solveTOI [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.solveTOI, aveProfile.solveTOI, m_maxProfile.solveTOI);
m_textLine += m_textIncrement;
g_debugDraw.DrawString(5, m_textLine, "broad-phase [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.broadphase, aveProfile.broadphase, m_maxProfile.broadphase);
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "step [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.step, aveProfile.step, m_maxProfile.step);
DrawString(5, m_textLine, "collide [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.collide, aveProfile.collide, m_maxProfile.collide);
DrawString(5, m_textLine, "solve [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.solve, aveProfile.solve, m_maxProfile.solve);
DrawString(5, m_textLine, "solve init [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.solveInit, aveProfile.solveInit, m_maxProfile.solveInit);
DrawString(5, m_textLine, "solve velocity [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.solveVelocity, aveProfile.solveVelocity, m_maxProfile.solveVelocity);
DrawString(5, m_textLine, "solve position [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.solvePosition, aveProfile.solvePosition, m_maxProfile.solvePosition);
DrawString(5, m_textLine, "solveTOI [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.solveTOI, aveProfile.solveTOI, m_maxProfile.solveTOI);
DrawString(5, m_textLine, "broad-phase [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.broadphase, aveProfile.broadphase, m_maxProfile.broadphase);
}
if (m_bombSpawning)
@ -450,4 +448,52 @@ void Test::Step(Settings& settings)
void Test::ShiftOrigin(const b2Vec2 & newOrigin)
{
m_world->ShiftOrigin(newOrigin);
}
void Test::initShader(void)
{
// initShader is unsupported
}
void Test::DrawString(int x, int y, const char* fmt, ...)
{
#if defined(CC_PLATFORM_PC)
debugString.append(std::string(fmt));
debugString.append("\n");
labelDebugDraw->setString(debugString);
// labelDebugDraw->setPosition(x, y);
#endif
}
void Test::DrawString(const b2Vec2& pw, const char* fmt, ...)
{
#if defined(CC_PLATFORM_PC)
debugString.append(std::string(fmt));
debugString.append("\n");
labelDebugDraw->setString(debugString);
// labelDebugDraw->setPosition(pw.x, pw.y);
#endif
}
void Test::DrawAABB(b2AABB* aabb, const b2Color& color)
{
b2Vec2 p1 = aabb->lowerBound;
b2Vec2 p2 = b2Vec2(aabb->upperBound.x, aabb->lowerBound.y);
b2Vec2 p3 = aabb->upperBound;
b2Vec2 p4 = b2Vec2(aabb->lowerBound.x, aabb->upperBound.y);
Vec2 verts[] = {
Vec2(p1.x * g_debugDraw.mRatio, p1.y * g_debugDraw.mRatio) + g_debugDraw.debugNodeOffset ,
Vec2(p2.x * g_debugDraw.mRatio, p2.y * g_debugDraw.mRatio) + g_debugDraw.debugNodeOffset ,
Vec2(p3.x * g_debugDraw.mRatio, p3.y * g_debugDraw.mRatio) + g_debugDraw.debugNodeOffset ,
Vec2(p4.x * g_debugDraw.mRatio, p4.y * g_debugDraw.mRatio) + g_debugDraw.debugNodeOffset ,
};
debugDrawNode->drawPolygon(verts, sizeof(verts) / sizeof(verts[0]), Color4F(color.r / 2, color.g / 2, color.b / 2, 0), 0.4f, Color4F(color.r, color.g, color.b, color.a));
}
void Test::Flush()
{
// Flush is unsupported
}

View File

@ -1,83 +0,0 @@
// MIT License
// Copyright (c) 2019 Erin Catto
// 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.
#pragma once
struct Settings
{
Settings()
{
Reset();
}
void Reset()
{
m_testIndex = 0;
m_windowWidth = 1600;
m_windowHeight = 900;
m_hertz = 60.0f;
m_velocityIterations = 8;
m_positionIterations = 1;
m_drawShapes = true;
m_drawJoints = true;
m_drawAABBs = false;
m_drawContactPoints = false;
m_drawContactNormals = false;
m_drawContactImpulse = false;
m_drawFrictionImpulse = false;
m_drawCOMs = false;
m_drawStats = false;
m_drawProfile = false;
m_enableWarmStarting = true;
m_enableContinuous = true;
m_enableSubStepping = false;
m_enableSleep = true;
m_pause = false;
m_singleStep = false;
}
void Save();
void Load();
int m_testIndex;
int m_windowWidth;
int m_windowHeight;
float m_hertz;
int m_velocityIterations;
int m_positionIterations;
bool m_drawShapes;
bool m_drawJoints;
bool m_drawAABBs;
bool m_drawContactPoints;
bool m_drawContactNormals;
bool m_drawContactImpulse;
bool m_drawFrictionImpulse;
bool m_drawCOMs;
bool m_drawStats;
bool m_drawProfile;
bool m_enableWarmStarting;
bool m_enableContinuous;
bool m_enableSubStepping;
bool m_enableSleep;
bool m_pause;
bool m_singleStep;
};

View File

@ -169,8 +169,8 @@ public:
void Step(Settings& settings) override
{
g_debugDraw.DrawString(5, m_textLine, "Forward (W), Turn (A) and (D)");
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "Forward (W), Turn (A) and (D)");
//if (glfwGetKey(g_mainWindow, GLFW_KEY_W) == GLFW_PRESS)
//{

View File

@ -146,8 +146,8 @@ public:
Test::Step(settings);
g_debugDraw.DrawString(5, m_textLine, "Keys: (d) dynamic, (s) static, (k) kinematic");
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "Keys: (d) dynamic, (s) static, (k) kinematic");
}
static Test* Create()

View File

@ -128,9 +128,9 @@ public:
void Step(Settings& settings) override
{
Test::Step(settings);
g_debugDraw.DrawString(5, m_textLine, "Press: (,) to launch a bullet.");
m_textLine += m_textIncrement;
g_debugDraw.DrawString(5, m_textLine, "Blocksolve = %d", g_blockSolve);
DrawString(5, m_textLine, "Press: (,) to launch a bullet.");
DrawString(5, m_textLine, "Blocksolve = %d", g_blockSolve);
if (m_stepCount == 300)
{
if (m_bullet != NULL)

View File

@ -104,20 +104,20 @@ public:
if (b2_gjkCalls > 0)
{
g_debugDraw.DrawString(5, m_textLine, "gjk calls = %d, ave gjk iters = %3.1f, max gjk iters = %d",
DrawString(5, m_textLine, "gjk calls = %d, ave gjk iters = %3.1f, max gjk iters = %d",
b2_gjkCalls, b2_gjkIters / float(b2_gjkCalls), b2_gjkMaxIters);
m_textLine += m_textIncrement;
}
if (b2_toiCalls > 0)
{
g_debugDraw.DrawString(5, m_textLine, "toi calls = %d, ave toi iters = %3.1f, max toi iters = %d",
DrawString(5, m_textLine, "toi calls = %d, ave toi iters = %3.1f, max toi iters = %d",
b2_toiCalls, b2_toiIters / float(b2_toiCalls), b2_toiMaxRootIters);
m_textLine += m_textIncrement;
g_debugDraw.DrawString(5, m_textLine, "ave toi root iters = %3.1f, max toi root iters = %d",
DrawString(5, m_textLine, "ave toi root iters = %3.1f, max toi root iters = %d",
b2_toiRootIters / float(b2_toiCalls), b2_toiMaxRootIters);
m_textLine += m_textIncrement;
}
if (m_stepCount % 60 == 0)

View File

@ -264,8 +264,8 @@ public:
void Step(Settings& settings) override
{
g_debugDraw.DrawString(5, m_textLine, "Keys: left = a, brake = s, right = d, hz down = q, hz up = e");
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "Keys: left = a, brake = s, right = d, hz down = q, hz up = e");
//g_camera.m_center.x = m_car->GetPosition().x;
g_debugDraw.debugNodeOffset.x += m_car->GetPosition().x;

View File

@ -237,12 +237,12 @@ public:
m_character->SetLinearVelocity(v);
Test::Step(settings);
g_debugDraw.DrawString(5, m_textLine, "This tests various character collision shapes.");
m_textLine += m_textIncrement;
g_debugDraw.DrawString(5, m_textLine, "Limitation: square and hexagon can snag on aligned boxes.");
m_textLine += m_textIncrement;
g_debugDraw.DrawString(5, m_textLine, "Feature: edge chains have smooth collision inside and out.");
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "This tests various character collision shapes.");
DrawString(5, m_textLine, "Limitation: square and hexagon can snag on aligned boxes.");
DrawString(5, m_textLine, "Feature: edge chains have smooth collision inside and out.");
}
static Test* Create()

View File

@ -157,8 +157,8 @@ public:
}
}
g_debugDraw.DrawString(5, m_textLine, "Press 'c' to create a circle.");
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "Press 'c' to create a circle.");
}
static Test* Create()

View File

@ -118,9 +118,9 @@ public:
if (b2_gjkCalls > 0)
{
g_debugDraw.DrawString(5, m_textLine, "gjk calls = %d, ave gjk iters = %3.1f, max gjk iters = %d",
DrawString(5, m_textLine, "gjk calls = %d, ave gjk iters = %3.1f, max gjk iters = %d",
b2_gjkCalls, b2_gjkIters / float(b2_gjkCalls), b2_gjkMaxIters);
m_textLine += m_textIncrement;
}
extern B2_API int32 b2_toiCalls, b2_toiIters;
@ -129,17 +129,17 @@ public:
if (b2_toiCalls > 0)
{
g_debugDraw.DrawString(5, m_textLine, "toi calls = %d, ave [max] toi iters = %3.1f [%d]",
DrawString(5, m_textLine, "toi calls = %d, ave [max] toi iters = %3.1f [%d]",
b2_toiCalls, b2_toiIters / float(b2_toiCalls), b2_toiMaxRootIters);
m_textLine += m_textIncrement;
g_debugDraw.DrawString(5, m_textLine, "ave [max] toi root iters = %3.1f [%d]",
DrawString(5, m_textLine, "ave [max] toi root iters = %3.1f [%d]",
b2_toiRootIters / float(b2_toiCalls), b2_toiMaxRootIters);
m_textLine += m_textIncrement;
g_debugDraw.DrawString(5, m_textLine, "ave [max] toi time = %.1f [%.1f] (microseconds)",
DrawString(5, m_textLine, "ave [max] toi time = %.1f [%.1f] (microseconds)",
1000.0f * b2_toiTime / float(b2_toiCalls), 1000.0f * b2_toiMaxTime);
m_textLine += m_textIncrement;
}
if (m_stepCount % 60 == 0)

View File

@ -77,15 +77,15 @@ public:
b2PolygonShape shape;
shape.Set(m_points, m_count);
g_debugDraw.DrawString(5, m_textLine, "Press g to generate a new random convex hull");
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "Press g to generate a new random convex hull");
g_debugDraw.DrawPolygon(shape.m_vertices, shape.m_count, b2Color(0.9f, 0.9f, 0.9f));
for (int32 i = 0; i < m_count; ++i)
{
g_debugDraw.DrawPoint(m_points[i], 3.0f, b2Color(0.3f, 0.9f, 0.3f));
g_debugDraw.DrawString(m_points[i] + b2Vec2(0.05f, 0.05f), "%d", i);
DrawString(m_points[i] + b2Vec2(0.05f, 0.05f), "%d", i);
}
if (shape.Validate() == false)

View File

@ -63,11 +63,11 @@ public:
b2DistanceOutput output;
b2Distance(&output, &cache, &input);
g_debugDraw.DrawString(5, m_textLine, "distance = %g", output.distance);
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "distance = %g", output.distance);
g_debugDraw.DrawString(5, m_textLine, "iterations = %d", output.iterations);
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "iterations = %d", output.iterations);
{
b2Color color(0.9f, 0.9f, 0.9f);

View File

@ -71,8 +71,8 @@ public:
float ke = 0.5f * massData.mass * b2Dot(v, v) + 0.5f * massData.I * omega * omega;
g_debugDraw.DrawString(5, m_textLine, "kinetic energy = %.6f", ke);
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "kinetic energy = %.6f", ke);
Test::Step(settings);
}

View File

@ -109,11 +109,11 @@ public:
c.Set(0.6f, 0.6f, 0.9f);
}
g_debugDraw.DrawAABB(&actor->aabb, c);
DrawAABB(&actor->aabb, c);
}
b2Color c(0.7f, 0.7f, 0.7f);
g_debugDraw.DrawAABB(&m_queryAABB, c);
DrawAABB(&m_queryAABB, c);
g_debugDraw.DrawSegment(m_rayCastInput.p1, m_rayCastInput.p2, c);
@ -131,8 +131,8 @@ public:
{
int32 height = m_tree.GetHeight();
g_debugDraw.DrawString(5, m_textLine, "dynamic tree height = %d", height);
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "dynamic tree height = %d", height);
}
++m_stepCount;

View File

@ -205,8 +205,8 @@ public:
bool advanceRay = settings.m_pause == 0 || settings.m_singleStep;
Test::Step(settings);
g_debugDraw.DrawString(5, m_textLine, "Press 1-5 to drop stuff");
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "Press 1-5 to drop stuff");
float L = 25.0f;
b2Vec2 point1(0.0f, 10.0f);

View File

@ -156,13 +156,13 @@ public:
ratio = m_joint4->GetRatio();
value = m_joint1->GetJointAngle() + ratio * m_joint2->GetJointAngle();
g_debugDraw.DrawString(5, m_textLine, "theta1 + %4.2f * theta2 = %4.2f", (float) ratio, (float) value);
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "theta1 + %4.2f * theta2 = %4.2f", (float) ratio, (float) value);
ratio = m_joint5->GetRatio();
value = m_joint2->GetJointAngle() + ratio * m_joint3->GetJointTranslation();
g_debugDraw.DrawString(5, m_textLine, "theta2 + %4.2f * delta = %4.2f", (float) ratio, (float) value);
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "theta2 + %4.2f * delta = %4.2f", (float) ratio, (float) value);
}
static Test* Create()

View File

@ -101,7 +101,7 @@ public:
g_debugDraw.DrawPoint(linearOffset, 4.0f, b2Color(0.9f, 0.9f, 0.9f));
Test::Step(settings);
g_debugDraw.DrawString(5, m_textLine, "Keys: (s) pause");
DrawString(5, m_textLine, "Keys: (s) pause");
m_textLine += 15;
}

View File

@ -131,8 +131,8 @@ public:
Test::Step(settings);
g_debugDraw.DrawString(5, m_textLine, "Press 'a' to control the flippers");
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "Press 'a' to control the flippers");
}

View File

@ -115,8 +115,8 @@ public:
Test::Step(settings);
b2Vec2 v = m_character->GetBody()->GetLinearVelocity();
g_debugDraw.DrawString(5, m_textLine, "Character Linear Velocity: %f", v.y);
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "Character Linear Velocity: %f", v.y);
}
static Test* Create()

View File

@ -55,8 +55,8 @@ public:
b2WorldManifold worldManifold;
worldManifold.Initialize(&manifold, m_transformA, m_polygonA.m_radius, m_transformB, m_polygonB.m_radius);
g_debugDraw.DrawString(5, m_textLine, "point count = %d", manifold.pointCount);
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "point count = %d", manifold.pointCount);
{
b2Color color(0.9f, 0.9f, 0.9f);

View File

@ -243,12 +243,12 @@ public:
b2Color color(0.4f, 0.7f, 0.8f);
g_debugDraw.DrawCircle(callback.m_circle.m_p, callback.m_circle.m_radius, color);
g_debugDraw.DrawString(5, m_textLine, "Press 1-5 to drop stuff, maximum of %d overlaps detected", PolygonShapesCallback::e_maxCount);
m_textLine += m_textIncrement;
g_debugDraw.DrawString(5, m_textLine, "Press 'a' to enable/disable some bodies");
m_textLine += m_textIncrement;
g_debugDraw.DrawString(5, m_textLine, "Press 'd' to destroy a body");
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "Press 1-5 to drop stuff, maximum of %d overlaps detected", PolygonShapesCallback::e_maxCount);
DrawString(5, m_textLine, "Press 'a' to enable/disable some bodies");
DrawString(5, m_textLine, "Press 'd' to destroy a body");
}
static Test* Create()

View File

@ -100,8 +100,8 @@ public:
{
Test::Step(settings);
float force = m_joint->GetMotorForce(settings.m_hertz);
g_debugDraw.DrawString(5, m_textLine, "Motor Force = %4.0f", force);
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "Motor Force = %4.0f", force);
}
static Test* Create()

View File

@ -81,8 +81,8 @@ public:
float ratio = m_joint1->GetRatio();
float L = m_joint1->GetCurrentLengthA() + ratio * m_joint1->GetCurrentLengthB();
g_debugDraw.DrawString(5, m_textLine, "L1 + %4.2f * L2 = %4.2f", (float) ratio, (float) L);
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "L1 + %4.2f * L2 = %4.2f", (float) ratio, (float) L);
}
static Test* Create()

View File

@ -345,24 +345,24 @@ public:
{
Test::Step(settings);
g_debugDraw.DrawString(5, m_textLine, "Shape 1 is intentionally ignored by the ray");
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "Shape 1 is intentionally ignored by the ray");
switch (m_mode)
{
case e_closest:
g_debugDraw.DrawString(5, m_textLine, "Ray-cast mode: closest - find closest fixture along the ray");
DrawString(5, m_textLine, "Ray-cast mode: closest - find closest fixture along the ray");
break;
case e_any:
g_debugDraw.DrawString(5, m_textLine, "Ray-cast mode: any - check for obstruction");
DrawString(5, m_textLine, "Ray-cast mode: any - check for obstruction");
break;
case e_multiple:
g_debugDraw.DrawString(5, m_textLine, "Ray-cast mode: multiple - gather multiple fixtures");
DrawString(5, m_textLine, "Ray-cast mode: multiple - gather multiple fixtures");
break;
}
m_textLine += m_textIncrement;
float angle = b2_pi * m_degrees / 180.0f;
float L = 11.0f;

View File

@ -138,12 +138,12 @@ public:
Test::Step(settings);
float torque1 = m_joint1->GetMotorTorque(settings.m_hertz);
g_debugDraw.DrawString(5, m_textLine, "Motor Torque 1= %4.0f", torque1);
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "Motor Torque 1= %4.0f", torque1);
float torque2 = m_joint2->GetMotorTorque(settings.m_hertz);
g_debugDraw.DrawString(5, m_textLine, "Motor Torque 2= %4.0f", torque2);
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "Motor Torque 2= %4.0f", torque2);
}
static Test* Create()

View File

@ -263,8 +263,8 @@ public:
m_rope1.Draw(&g_debugDraw);
m_rope2.Draw(&g_debugDraw);
g_debugDraw.DrawString(5, m_textLine, "Press comma and period to move left and right");
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "Press comma and period to move left and right");
}
static Test* Create()

View File

@ -20,7 +20,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#pragma once
#ifndef SETTINGS_H
#define SETTINGS_H
struct Settings
{
@ -80,4 +81,6 @@ struct Settings
bool m_enableSleep;
bool m_pause;
bool m_singleStep;
};
};
#endif

View File

@ -120,9 +120,9 @@ public:
b2Distance(&distanceOutput, &simplexCache, &distanceInput);
g_debugDraw.DrawString(5, m_textLine, "hit = %s, iters = %d, lambda = %g, distance = %g",
DrawString(5, m_textLine, "hit = %s, iters = %d, lambda = %g, distance = %g",
hit ? "true" : "false", output.iterations, output.lambda, distanceOutput.distance);
m_textLine += m_textIncrement;
b2Vec2 vertices[b2_maxPolygonVertices];

View File

@ -88,10 +88,10 @@ public:
void Step(Settings& settings) override
{
Test::Step(settings);
g_debugDraw.DrawString(5, m_textLine, "Press: (c) create a shape, (d) destroy a shape.");
m_textLine += m_textIncrement;
g_debugDraw.DrawString(5, m_textLine, "sensor = %d", m_sensor);
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "Press: (c) create a shape, (d) destroy a shape.");
DrawString(5, m_textLine, "sensor = %d", m_sensor);
}
static Test* Create()

View File

@ -126,8 +126,8 @@ public:
void Step(Settings& settings) override
{
g_debugDraw.DrawString(5, m_textLine, "Keys: c = Camera fixed/tracking");
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "Keys: c = Camera fixed/tracking");
if(!m_fixed_camera)
{

View File

@ -141,11 +141,11 @@ public:
void Step(Settings& settings) override
{
Test::Step(settings);
g_debugDraw.DrawString(5, m_textLine, "Keys: (f) toggle friction, (m) toggle motor");
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "Keys: (f) toggle friction, (m) toggle motor");
float torque = m_joint1->GetMotorTorque(settings.m_hertz);
g_debugDraw.DrawString(5, m_textLine, "Motor Torque = %5.0f", (float) torque);
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "Motor Torque = %5.0f", (float) torque);
}
static Test* Create()

View File

@ -27,8 +27,6 @@
class Test;
struct Settings;
#define RAND_LIMIT 32767
#define DRAW_STRING_NEW_LINE 25
@ -113,9 +111,15 @@ public:
void ShiftOrigin(const b2Vec2& newOrigin);
DebugDraw g_debugDraw;
cocos2d::DrawNode* debugDrawNode;
void initShader(void);
void DrawString(int x, int y, const char* fmt, ...);
void DrawString(const b2Vec2& p, const char* fmt, ...);
void DrawAABB(b2AABB* aabb, const b2Color& color);
void Flush();
cocos2d::extension::DebugDraw g_debugDraw;
cocos2d::DrawNode* debugDrawNode;
std::string debugString = "";
b2World* m_world;

View File

@ -222,8 +222,8 @@ public:
void Step(Settings& settings) override
{
g_debugDraw.DrawString(5, m_textLine, "Keys: left = a, brake = s, right = d, toggle motor = m");
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "Keys: left = a, brake = s, right = d, toggle motor = m");
Test::Step(settings);
}

View File

@ -130,14 +130,14 @@ public:
int32 leafCount = cm.m_broadPhase.GetProxyCount();
int32 minimumNodeCount = 2 * leafCount - 1;
float minimumHeight = ceilf(logf(float(minimumNodeCount)) / logf(2.0f));
g_debugDraw.DrawString(5, m_textLine, "dynamic tree height = %d, min = %d", height, int32(minimumHeight));
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "dynamic tree height = %d, min = %d", height, int32(minimumHeight));
Test::Step(settings);
g_debugDraw.DrawString(5, m_textLine, "create time = %6.2f ms, fixture count = %d",
DrawString(5, m_textLine, "create time = %6.2f ms, fixture count = %d",
m_createTime, m_fixtureCount);
m_textLine += m_textIncrement;
//b2DynamicTree* tree = &m_world->m_contactManager.m_broadPhase.m_tree;

View File

@ -69,12 +69,12 @@ public:
b2TimeOfImpact(&output, &input);
g_debugDraw.DrawString(5, m_textLine, "toi = %g", output.t);
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "toi = %g", output.t);
extern B2_API int32 b2_toiMaxIters, b2_toiMaxRootIters;
g_debugDraw.DrawString(5, m_textLine, "max toi iters = %d, max root iters = %d", b2_toiMaxIters, b2_toiMaxRootIters);
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "max toi iters = %d, max root iters = %d", b2_toiMaxIters, b2_toiMaxRootIters);
b2Vec2 vertices[b2_maxPolygonVertices];

View File

@ -190,8 +190,8 @@ public:
void Step(Settings& settings) override
{
Test::Step(settings);
g_debugDraw.DrawString(5, m_textLine, "Press: (b) to delete a body, (j) to delete a joint");
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "Press: (b) to delete a body, (j) to delete a joint");
}
void JointDestroyed(b2Joint* joint) override

View File

@ -80,12 +80,12 @@ public:
Test::Step(settings);
float torque = m_joint->GetMotorTorque(settings.m_hertz);
g_debugDraw.DrawString(5, m_textLine, "Motor Torque = %4.0f", torque);
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "Motor Torque = %4.0f", torque);
b2Vec2 F = m_joint->GetReactionForce(settings.m_hertz);
g_debugDraw.DrawString(5, m_textLine, "Reaction Force = (%4.1f, %4.1f)", F.x, F.y);
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "Reaction Force = (%4.1f, %4.1f)", F.x, F.y);
}
void UpdateUI() override

View File

@ -143,13 +143,13 @@ public:
if (m_distanceJoint)
{
g_debugDraw.DrawString(5, m_textLine, "Distance Joint ON");
DrawString(5, m_textLine, "Distance Joint ON");
}
else
{
g_debugDraw.DrawString(5, m_textLine, "Distance Joint OFF");
DrawString(5, m_textLine, "Distance Joint OFF");
}
m_textLine += m_textIncrement;
}
static Test* Create()

View File

@ -123,7 +123,7 @@ void SpritePolygonTestCase::updateDrawNode()
//draw 3 lines
Vec3 from = verts[indices[i*3]].vertices;
Vec3 to = verts[indices[i*3+1]].vertices;
drawnode->drawLine(Vec2(from.x, from.y), Vec2(to.x,to.y), Color4F::GREEN);
drawnode->drawLine(Vec2(from.x, from.y), Vec2(to.x,to.y), Color4F::BLUE);
from = verts[indices[i*3+1]].vertices;
to = verts[indices[i*3+2]].vertices;
@ -131,7 +131,7 @@ void SpritePolygonTestCase::updateDrawNode()
from = verts[indices[i*3+2]].vertices;
to = verts[indices[i*3]].vertices;
drawnode->drawLine(Vec2(from.x, from.y), Vec2(to.x,to.y), Color4F::GREEN);
drawnode->drawLine(Vec2(from.x, from.y), Vec2(to.x,to.y), Color4F::RED);
}
}
}
@ -791,7 +791,7 @@ void SpritePolygonTestFrameAnim::initSprites()
_drawNodes.pushBack(spDrawNode);
}
updateDrawNode();
Vector<SpriteFrame*> animFrames(5);
@ -803,6 +803,8 @@ void SpritePolygonTestFrameAnim::initSprites()
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
sprite->runAction(RepeatForever::create(Animate::create(animation)));
updateDrawNode();
}
//