Skip to content

Commit

Permalink
Added debug rendering. Thanks to Stefan Nguyen @ Vinova Pte Ltd! http…
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanSweet committed Mar 25, 2013
1 parent 42d072a commit 81a9c60
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 27 deletions.
5 changes: 3 additions & 2 deletions spine-cocos2dx/spine-cocos2dx/example/ExampleScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ bool ExampleScene::init() {

CCSkeleton* skeletonNode = new CCSkeleton(skeletonData);
skeletonNode->state->setAnimation(animation, true);
skeletonNode->debug = true;

CCSize winSize = CCDirector::sharedDirector()->getWinSize();
skeletonNode->setPosition(ccp(winSize.width / 2, 20));
CCSize windowSize = CCDirector::sharedDirector()->getWinSize();
skeletonNode->setPosition(ccp(windowSize.width / 2, 20));
addChild(skeletonNode);

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class CCSkeleton: public cocos2d::CCNode {
public:
Skeleton *skeleton;
AnimationState *state;
bool debug;

CCSkeleton (SkeletonData *skeletonData, AnimationStateData *stateData = 0);
virtual ~CCSkeleton ();
Expand Down
89 changes: 64 additions & 25 deletions spine-cocos2dx/spine-cocos2dx/src/spine-cocos2dx/CCSkeleton.cpp
Original file line number Diff line number Diff line change
@@ -1,39 +1,45 @@
/*******************************************************************************
* Copyright (c) 2013, Esoteric Software
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
******************************************************************************/
* Copyright (c) 2013, Esoteric Software
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
******************************************************************************/

#include <spine-cocos2dx/CCSkeleton.h>
#include <stdexcept>
#include <spine/SkeletonData.h>
#include <spine-cocos2dx/Skeleton.h>
#include <spine-cocos2dx/RegionAttachment.h>
#include <spine/SkeletonData.h>
#include <spine/AnimationState.h>
#include <spine/AnimationStateData.h>
#include <spine/Slot.h>
#include <spine/BoneData.h>
#include <spine/Bone.h>

using namespace spine;
USING_NS_CC;

CCSkeleton::CCSkeleton (SkeletonData *skeletonData, AnimationStateData *stateData) {
CCSkeleton::CCSkeleton (SkeletonData *skeletonData, AnimationStateData *stateData) :
debug(false)
{
if (!skeletonData) throw std::invalid_argument("skeletonData cannot be null.");
skeleton = new Skeleton(skeletonData);
state = new AnimationState(stateData);
Expand All @@ -58,4 +64,37 @@ void CCSkeleton::draw () {
CC_NODE_DRAW_SETUP();
glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
skeleton->draw();

if (debug) {
// Slots.
ccDrawColor4B(0, 0, 255, 10);
glLineWidth(1);
CCPoint points[4];
for (int i = 0, n = skeleton->slots.size(); i < n; i++) {
if (!skeleton->slots[i]->attachment) continue;
ccV3F_C4B_T2F_Quad quad = ((RegionAttachment*)skeleton->slots[i]->attachment)->quad;
points[0] = ccp(quad.bl.vertices.x, quad.bl.vertices.y);
points[1] = ccp(quad.br.vertices.x, quad.br.vertices.y);
points[2] = ccp(quad.tr.vertices.x, quad.tr.vertices.y);
points[3] = ccp(quad.tl.vertices.x, quad.tl.vertices.y);
ccDrawPoly(points, 4, true);
}
// Bone lengths.
glLineWidth(2);
ccDrawColor4B(255, 0, 0, 255);
for (int i = 0, n = skeleton->bones.size(); i < n; i++) {
Bone *bone = skeleton->bones[i];
float x = bone->data->length * bone->m00 + bone->worldX;
float y = bone->data->length * bone->m10 + bone->worldY;
ccDrawLine(ccp(bone->worldX, bone->worldY), ccp(x, y));
}
// Bone origins.
ccPointSize(4);
ccDrawColor4B(0, 0, 255, 255); // Root bone is blue.
for (int i = 0, n = skeleton->bones.size(); i < n; i++) {
Bone *bone = skeleton->bones[i];
ccDrawPoint(ccp(bone->worldX, bone->worldY));
if (i == 0) ccDrawColor4B(0, 255, 0, 255);
}
}
}

0 comments on commit 81a9c60

Please sign in to comment.