-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[3DS] Implementing LineBatcher and RectangleBatcher and fixing a warn…
…ing in Entity.cpp
- Loading branch information
Showing
8 changed files
with
309 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// | ||
// DSCircleBatcher.cpp | ||
// gowengamedev-framework | ||
// | ||
// Created by Stephen Gowen on 8/25/15. | ||
// Copyright (c) 2015 Gowen Game Dev. All rights reserved. | ||
// | ||
|
||
#define DEGREE_SPACING 6 | ||
|
||
#include "DSCircleBatcher.h" | ||
#include "macros.h" | ||
#include "Circle.h" | ||
#include "Vector2D.h" | ||
#include "math.h" | ||
|
||
DSCircleBatcher::DSCircleBatcher() : CircleBatcher() | ||
{ | ||
// Empty | ||
} | ||
|
||
void DSCircleBatcher::renderCircle(Circle &circle, Color &color) | ||
{ | ||
// OGLESManager->m_colorVertices.clear(); | ||
|
||
int numPointsOnCircle = 0; | ||
|
||
for (int i = 0; i < 360; i += DEGREE_SPACING) | ||
{ | ||
float rad = DEGREES_TO_RADIANS(i); | ||
float cos = cosf(rad); | ||
float sin = sinf(rad); | ||
|
||
// OGLESManager->addVertexCoordinate(cos * circle.m_fRadius + circle.getCenter().getX(), sin * circle.m_fRadius + circle.getCenter().getY(), 0, color.red, color.green, color.blue, color.alpha); | ||
|
||
numPointsOnCircle++; | ||
} | ||
|
||
endBatch(numPointsOnCircle); | ||
} | ||
|
||
void DSCircleBatcher::renderPartialCircle(Circle &circle, int arcDegrees, Color &color) | ||
{ | ||
// OGLESManager->m_colorVertices.clear(); | ||
|
||
// OGLESManager->addVertexCoordinate(circle.getCenter().getX(), circle.getCenter().getY(), 0, color.red, color.green, color.blue, color.alpha); | ||
|
||
int numPointsOnCircle = 1; | ||
|
||
for (int i = 90 - arcDegrees; i > -270; i -= DEGREE_SPACING) | ||
{ | ||
float rad = DEGREES_TO_RADIANS(i); | ||
float cos = cosf(rad); | ||
float sin = sinf(rad); | ||
|
||
// OGLESManager->addVertexCoordinate(cos * circle.m_fRadius + circle.getCenter().getX(), sin * circle.m_fRadius + circle.getCenter().getY(), 0, color.red, color.green, color.blue, color.alpha); | ||
|
||
numPointsOnCircle++; | ||
} | ||
|
||
float rad = DEGREES_TO_RADIANS(-270); | ||
float cos = cosf(rad); | ||
float sin = sinf(rad); | ||
|
||
// OGLESManager->addVertexCoordinate(cos * circle.m_fRadius + circle.getCenter().getX(), sin * circle.m_fRadius + circle.getCenter().getY(), 0, color.red, color.green, color.blue, color.alpha); | ||
|
||
numPointsOnCircle++; | ||
|
||
endBatch(numPointsOnCircle); | ||
} | ||
|
||
void DSCircleBatcher::endBatch(int numPoints) | ||
{ | ||
// OGLESManager->prepareForGeometryRendering(); | ||
|
||
// glDrawArrays(GL_TRIANGLE_FAN, 0, numPoints); | ||
|
||
// OGLESManager->finishGeometryRendering(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// DSCircleBatcher.h | ||
// gowengamedev-framework | ||
// | ||
// Created by Stephen Gowen on 8/25/15. | ||
// Copyright (c) 2015 Gowen Game Dev. All rights reserved. | ||
// | ||
|
||
#ifndef __gowengamedev__DSCircleBatcher__ | ||
#define __gowengamedev__DSCircleBatcher__ | ||
|
||
#include "CircleBatcher.h" | ||
|
||
class DSCircleBatcher : public CircleBatcher | ||
{ | ||
public: | ||
DSCircleBatcher(); | ||
|
||
virtual void renderCircle(Circle &circle, Color &color); | ||
|
||
virtual void renderPartialCircle(Circle &circle, int arcDegrees, Color &color); | ||
|
||
private: | ||
void endBatch(int numPoints); | ||
}; | ||
|
||
#endif /* defined(__gowengamedev__DSCircleBatcher__) */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// DSLineBatcher.cpp | ||
// gowengamedev-framework | ||
// | ||
// Created by Stephen Gowen on 8/25/15. | ||
// Copyright (c) 2015 Gowen Game Dev. All rights reserved. | ||
// | ||
|
||
#include "DSLineBatcher.h" | ||
#include "macros.h" | ||
#include "Line.h" | ||
#include "Vector2D.h" | ||
#include "GameConstants.h" | ||
|
||
#include <sf2d.h> | ||
|
||
#define LINE_THICKNESS GAME_WIDTH / 1000.0f | ||
|
||
DSLineBatcher::DSLineBatcher(gfxScreen_t screen, int screenWidth, int screenHeight) : m_screen(screen), m_iScreenWidth(screenWidth), m_iScreenHeight(screenHeight) | ||
{ | ||
m_iNumLines = 0; | ||
} | ||
|
||
void DSLineBatcher::beginBatch() | ||
{ | ||
m_lines.clear(); | ||
m_iNumLines = 0; | ||
} | ||
|
||
void DSLineBatcher::endBatch() | ||
{ | ||
if (m_iNumLines > 0) | ||
{ | ||
for (std::vector<LINE>::iterator itr = m_lines.begin(); itr != m_lines.end(); ++itr) | ||
{ | ||
LINE l = *itr; | ||
|
||
sf2d_draw_line(l.oX, l.oY, l.eX, l.eY, LINE_THICKNESS, RGBA8((int) (l.r * 255), (int) (l.g * 255), (int) (l.b * 255), (int) (l.a * 255))); | ||
} | ||
} | ||
} | ||
|
||
void DSLineBatcher::renderLine(float originX, float originY, float endX, float endY, Color &color) | ||
{ | ||
LINE l = {originX, GAME_HEIGHT - originY, endX, GAME_HEIGHT - endY, color.red, color.green, color.blue, color.alpha}; | ||
m_lines.push_back(l); | ||
|
||
m_iNumLines++; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// DSLineBatcher.h | ||
// gowengamedev-framework | ||
// | ||
// Created by Stephen Gowen on 8/25/15. | ||
// Copyright (c) 2015 Gowen Game Dev. All rights reserved. | ||
// | ||
|
||
#ifndef __gowengamedev__DSLineBatcher__ | ||
#define __gowengamedev__DSLineBatcher__ | ||
|
||
#include "LineBatcher.h" | ||
|
||
#include <vector> | ||
|
||
#include <3ds.h> | ||
|
||
struct LINE | ||
{ | ||
float oX, oY, eX, eY; // Vertices | ||
float r, g, b, a; // Color for Vertices | ||
}; | ||
|
||
class DSLineBatcher : public LineBatcher | ||
{ | ||
public: | ||
DSLineBatcher(gfxScreen_t screen, int screenWidth, int screenHeight); | ||
|
||
virtual void beginBatch(); | ||
|
||
virtual void endBatch(); | ||
|
||
virtual void renderLine(float originX, float originY, float endX, float endY, Color &color); | ||
|
||
private: | ||
std::vector<LINE> m_lines; | ||
gfxScreen_t m_screen; | ||
int m_iScreenWidth; | ||
int m_iScreenHeight; | ||
}; | ||
|
||
#endif /* defined(__gowengamedev__DSLineBatcher__) */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// | ||
// DSRectangleBatcher.cpp | ||
// gowengamedev-framework | ||
// | ||
// Created by Stephen Gowen on 8/25/15. | ||
// Copyright (c) 2015 Gowen Game Dev. All rights reserved. | ||
// | ||
|
||
#include "DSRectangleBatcher.h" | ||
#include "macros.h" | ||
#include "Rectangle.h" | ||
#include "Vector2D.h" | ||
#include "GameConstants.h" | ||
|
||
#include <sf2d.h> | ||
|
||
#define RECT_LINE_THICKNESS GAME_WIDTH / 800.0f | ||
|
||
DSRectangleBatcher::DSRectangleBatcher(gfxScreen_t screen, int screenWidth, int screenHeight, bool isFill) : RectangleBatcher(isFill), m_screen(screen), m_iScreenWidth(screenWidth), m_iScreenHeight(screenHeight) | ||
{ | ||
m_iNumRectangles = 0; | ||
} | ||
|
||
void DSRectangleBatcher::beginBatch() | ||
{ | ||
m_rects.clear(); | ||
m_iNumRectangles = 0; | ||
} | ||
|
||
void DSRectangleBatcher::endBatch() | ||
{ | ||
if (m_iNumRectangles > 0) | ||
{ | ||
if (m_isFill) | ||
{ | ||
for (std::vector<RECT>::iterator itr = m_rects.begin(); itr != m_rects.end(); ++itr) | ||
{ | ||
RECT r = *itr; | ||
|
||
float width = r.x2 - r.x1; | ||
float height = r.y2 - r.y1; | ||
float x = r.x1 + width / 2; | ||
float y = r.y1 + height / 2; | ||
|
||
sf2d_draw_rectangle(x, y, width, height, RGBA8((int) (r.r * 255), (int) (r.g * 255), (int) (r.b * 255), (int) (r.a * 255))); | ||
} | ||
} | ||
else | ||
{ | ||
for (std::vector<RECT>::iterator itr = m_rects.begin(); itr != m_rects.end(); ++itr) | ||
{ | ||
RECT r = *itr; | ||
|
||
sf2d_draw_line(r.x1, r.y1, r.x2, r.y1, RECT_LINE_THICKNESS, RGBA8((int) (r.r * 255), (int) (r.g * 255), (int) (r.b * 255), (int) (r.a * 255))); | ||
sf2d_draw_line(r.x2, r.y1, r.x2, r.y2, RECT_LINE_THICKNESS, RGBA8((int) (r.r * 255), (int) (r.g * 255), (int) (r.b * 255), (int) (r.a * 255))); | ||
sf2d_draw_line(r.x2, r.y2, r.x1, r.y2, RECT_LINE_THICKNESS, RGBA8((int) (r.r * 255), (int) (r.g * 255), (int) (r.b * 255), (int) (r.a * 255))); | ||
sf2d_draw_line(r.x1, r.y2, r.x1, r.y1, RECT_LINE_THICKNESS, RGBA8((int) (r.r * 255), (int) (r.g * 255), (int) (r.b * 255), (int) (r.a * 255))); | ||
} | ||
} | ||
} | ||
} | ||
|
||
void DSRectangleBatcher::renderRectangle(float x1, float y1, float x2, float y2, Color &color) | ||
{ | ||
RECT r = {x1, GAME_HEIGHT - y1, x2, GAME_HEIGHT - y2, color.red, color.green, color.blue, color.alpha}; | ||
m_rects.push_back(r); | ||
|
||
m_iNumRectangles++; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// DSRectangleBatcher.h | ||
// gowengamedev-framework | ||
// | ||
// Created by Stephen Gowen on 8/25/15. | ||
// Copyright (c) 2015 Gowen Game Dev. All rights reserved. | ||
// | ||
|
||
#ifndef __gowengamedev__DSRectangleBatcher__ | ||
#define __gowengamedev__DSRectangleBatcher__ | ||
|
||
#include "RectangleBatcher.h" | ||
|
||
#include <vector> | ||
|
||
#include <3ds.h> | ||
|
||
struct RECT | ||
{ | ||
float x1, y1, x2, y2; // Rectangle Data | ||
float r, g, b, a; // Color for Vertices | ||
}; | ||
|
||
class DSRectangleBatcher : public RectangleBatcher | ||
{ | ||
public: | ||
DSRectangleBatcher(gfxScreen_t screen, int screenWidth, int screenHeight, bool isFill); | ||
|
||
virtual void beginBatch(); | ||
|
||
virtual void endBatch(); | ||
|
||
virtual void renderRectangle(float x1, float y1, float x2, float y2, Color &color); | ||
|
||
private: | ||
std::vector<RECT> m_rects; | ||
gfxScreen_t m_screen; | ||
int m_iScreenWidth; | ||
int m_iScreenHeight; | ||
}; | ||
|
||
#endif /* defined(__gowengamedev__DSRectangleBatcher__) */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters