Separate transform calc and render

This commit is contained in:
Charles J. Cliffe 2015-07-05 19:10:48 -04:00
parent 5ac0dc8c41
commit 237a7ad06f
3 changed files with 13 additions and 9 deletions

View File

@ -2,7 +2,9 @@
#include "GLPanel.h" #include "GLPanel.h"
#include "cubic_math.h" #include "cubic_math.h"
GLPanel::GLPanel() : fillType(GLPANEL_FILL_SOLID), contentsVisible(true), transform(CubicVR::mat4::identity()) { using namespace CubicVR;
GLPanel::GLPanel() : fillType(GLPANEL_FILL_SOLID), contentsVisible(true), transform(mat4::identity()) {
pos[0] = 0.0f; pos[0] = 0.0f;
pos[1] = 0.0f; pos[1] = 0.0f;
size[0] = 1.0f; size[0] = 1.0f;
@ -203,7 +205,8 @@ void GLPanel::drawChildren() {
std::vector<GLPanel *>::iterator panel_i; std::vector<GLPanel *>::iterator panel_i;
for (panel_i = children.begin(); panel_i != children.end(); panel_i++) { for (panel_i = children.begin(); panel_i != children.end(); panel_i++) {
(*panel_i)->draw(transform, this); (*panel_i)->calcTransform(transform);
(*panel_i)->draw();
} }
} }
} }
@ -212,10 +215,7 @@ void GLPanel::drawPanelContents() {
drawChildren(); drawChildren();
} }
void GLPanel::draw(CubicVR::mat4 transform_in, GLPanel *parent) { void GLPanel::calcTransform(mat4 transform_in) {
using namespace CubicVR;
// compute local transform // compute local transform
localTransform = mat4::translate(pos[0], pos[1], 0) * mat4::scale(size[0], size[1], 0); localTransform = mat4::translate(pos[0], pos[1], 0) * mat4::scale(size[0], size[1], 0);
// compute global transform // compute global transform
@ -247,7 +247,9 @@ void GLPanel::draw(CubicVR::mat4 transform_in, GLPanel *parent) {
if (marginPx) { if (marginPx) {
transform *= mat4::scale(1.0 - marginPx * 2.0 * pvec.x / size[0], 1.0 - marginPx * 2.0 * pvec.y / size[1], 0); transform *= mat4::scale(1.0 - marginPx * 2.0 * pvec.x / size[0], 1.0 - marginPx * 2.0 * pvec.y / size[1], 0);
} }
}
void GLPanel::draw() {
glLoadMatrixf(transform); glLoadMatrixf(transform);
if (fillType != GLPANEL_FILL_NONE) { if (fillType != GLPANEL_FILL_NONE) {

View File

@ -78,7 +78,8 @@ public:
void drawChildren(); void drawChildren();
virtual void drawPanelContents(); virtual void drawPanelContents();
void draw(CubicVR::mat4 transform, GLPanel *parent=NULL); void calcTransform(CubicVR::mat4 transform);
void draw();
}; };

View File

@ -57,7 +57,8 @@ void UITestContext::DrawBegin() {
} }
void UITestContext::Draw() { void UITestContext::Draw() {
testPanel.draw(CubicVR::mat4::identity()); testPanel.calcTransform(CubicVR::mat4::identity());
testPanel.draw();
} }
void UITestContext::DrawEnd() { void UITestContext::DrawEnd() {