DebugDraw
°´Ã¼ÀÇ ¿òÁ÷ÀÌ´Â °æ·Î¸¦ ±×¸®±â À§ÇØ ¶óÀÎÀ̳ª Á¡À» ±×¸®´Â ¹æ¹ý¿¡ ´ëÇؼ ¾Ë¾Æº»´Ù. ¾Æ·¡ ´Ù¸¥ ºÐÀÇ ¼Ò½º¸¦ ±×´ë·Î °¡Á®¿Ô´Ù. http://discuss.cocos2d-x.org/t/debugdraw-draw-lines-points-easy/769
¼Ò½º : DebugDraw.h DebugDraw.cpp
»ç¿ë¹ý : Ä®¶ó´Â appendLine, appendPoint ½Ã¿¡ ÁöÁ¤ ÇÒ ¼ö ÀÖ´Ù. »ç¿ë¹ý
#include "DebugDraw.h" //Á¡ ±×¸®±â
¾Æ·¡´Â DebugDrawÀÇ ¼Ò½ºÀÌ´Ù. DebugDraw.h
//DebugDraw.h
#ifndef __DEBUG_DRAW_H__ #define __DEBUG_DRAW_H__ #include "cocos2d.h" using namespace cocos2d; typedef struct { CCPoint pt1; CCPoint pt2; float r; float g; float b; } DebugLine; typedef struct { CCPoint pt; float r; float g; float b; } DebugPoint; class DebugDraw : public CCNode { public: static DebugDraw* create(); DebugDraw(); ~DebugDraw(); virtual void draw(void); void appendLine(CCPoint pt1, CCPoint pt2, float r = 1, float g = 0, float b = 0); void appendPoint(float x, float y, float r = 1, float g = 0, float b = 0); void appendPoint(CCPoint pt, float r = 1, float g = 0, float b = 0); private: std::vector<DebugLine>* m_lines; std::vector<DebugPoint>* m_points; }; #endif // __DEBUG_DRAW_H__
DebugDraw.cpp
//DebugDraw.cpp
#include "DebugDraw.h" inline unsigned char FloatToByte(float value) { return (unsigned int) (value * 255); } DebugDraw* DebugDraw::create() { DebugDraw* draw = new DebugDraw(); draw->autorelease(); return draw; } DebugDraw::DebugDraw() { m_lines = new std::vector<DebugLine>(); m_points = new std::vector<DebugPoint>(); } DebugDraw::~DebugDraw() { delete m_lines; delete m_points; } void DebugDraw::draw(void) { int c = m_lines->size(); for (int i = 0; i < c; i++) { DebugLine line = m_lines->at(i); //glColor4f(line.r, line.g, line.b, 1); //glLineWidth(1); ccDrawColor4F(line.r, line.g, line.b, 1); ccDrawLine(line.pt1, line.pt2); } c = m_points->size(); for (int i = 0; i < c; i++) { DebugPoint pt = m_points->at(i); //glPointSize(1); //glColor4f(pt.r, pt.g, pt.b, 1); ccDrawColor4F(pt.r, pt.g, pt.b, 1); ccDrawPoint(pt.pt); } } void DebugDraw::appendLine(CCPoint pt1, CCPoint pt2, float r, float g, float b) { DebugLine line; line.pt1 = pt1; line.pt2 = pt2; line.r = r; line.g = g; line.b = b; m_lines->push_back(line); } void DebugDraw::appendPoint(float x, float y, float r, float g, float b) { appendPoint(ccp(x, y), r, g, b); } void DebugDraw::appendPoint(CCPoint pt, float r, float g, float b) { DebugPoint dp; dp.pt = pt; dp.r = r; dp.g = g; dp.b = b; m_points->push_back(dp); }
|