Skip to content

Commit

Permalink
bambi rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
nietup committed Jun 14, 2015
1 parent 42d578f commit 24a9839
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
Binary file modified Bamboo.sdf
Binary file not shown.
21 changes: 21 additions & 0 deletions BambooStick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const int BambooStick::leafness = 3;
const float BambooStick::botTopFraction = 1.2f;
const float BambooStick::botHeightFraction = 0.2f;
const float BambooStick::maxRotation = 33.f;

BambooStick::BambooStick() {
}
Expand All @@ -11,6 +12,8 @@ BambooStick::BambooStick(GLUquadric * pQobj, std::default_random_engine * genera
position.x = x;
position.y = y;
position.z = z;
rotation.x = rotation.z = 0;
dRotation.x = dRotation.z = 1.f;
qobj = pQobj;
segments = new std::vector<Segment *>();

Expand All @@ -22,7 +25,24 @@ BambooStick::~BambooStick() {
delete segments;
}

void BambooStick::updateRotation() {

rotation.x += dRotation.x;
rotation.z += dRotation.z;
if (rotation.x >= maxRotation)
rotation.x = maxRotation;
if (rotation.z >= maxRotation)
rotation.z = maxRotation;
}

void BambooStick::render() {
updateRotation();
glPushMatrix();

glTranslatef(position.x, position.y, position.z);
glRotatef(maxRotation*sin((rotation.z / maxRotation)*1.570796), 0, 0, 1);
glRotatef(maxRotation*sin((rotation.x / maxRotation)*1.570796), 1, 0, 0);
glTranslatef(-position.x, -position.y, -position.z);
float height = 0;
for (int i = 0; i < segments->size(); i++) {
glPushMatrix();
Expand All @@ -38,6 +58,7 @@ void BambooStick::render() {

height += getSegment(i)->height;
}
glPopMatrix();
}

void BambooStick::generate(std::default_random_engine * generator) {
Expand Down
5 changes: 5 additions & 0 deletions BambooStick.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,23 @@ class BambooStick : public Entity{
Segment * getSegment(int x);

private:

static const int leafness; //denominator in chance of leaf in each segment (where numerator is 1)
static const float botTopFraction;
static const float botHeightFraction;
static const float maxRotation;

Position position;
float baseSegmentHeight;


float width, height;
GLUquadricObj *qobj;
std::vector<Segment *> * segments;
Position dRotation, rotation;

void generate(std::default_random_engine * generator);
void updateRotation();
Segment * generateSegment(float y); //global height of segment
};

Binary file modified Debug/vc120.idb
Binary file not shown.
4 changes: 2 additions & 2 deletions gkom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ int main(int argc, char** argv) {
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); //pojedyncze buforowanie - single, double; depth - zbufor

glutInitWindowPosition(0, 0);
width = 1500;
height = 800;
width = 1400;
height = 700;
glutInitWindowSize(width, height);

glutCreateWindow("GKOM: Bamboo Ulimate Elite");
Expand Down

0 comments on commit 24a9839

Please sign in to comment.