Skip to content

Commit

Permalink
wind
Browse files Browse the repository at this point in the history
  • Loading branch information
nietup committed Jun 14, 2015
1 parent 24a9839 commit 690fd00
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 22 deletions.
Binary file modified Bamboo.sdf
Binary file not shown.
45 changes: 28 additions & 17 deletions BambooStick.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include "BambooStick.h"
#include <iostream>

const int BambooStick::leafness = 3;
const int BambooStick::leafness = 2;
const float BambooStick::botTopFraction = 1.2f;
const float BambooStick::botHeightFraction = 0.2f;
const float BambooStick::maxRotation = 33.f;
const float BambooStick::maxRotation = 10.f;
Entity::Position BambooStick::rotation = {0,0,0};

BambooStick::BambooStick() {
}
Expand All @@ -12,8 +14,6 @@ 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 @@ -26,23 +26,34 @@ BambooStick::~BambooStick() {
}

void BambooStick::updateRotation() {
if (abs(BambooStick::rotation.x + Map::windX) <= maxRotation)
BambooStick::rotation.x += Map::windX;

rotation.x += dRotation.x;
rotation.z += dRotation.z;
if (rotation.x >= maxRotation)
rotation.x = maxRotation;
if (rotation.z >= maxRotation)
rotation.z = maxRotation;
if (abs(BambooStick::rotation.z + Map::windZ) <= maxRotation)
BambooStick::rotation.z += Map::windZ;

if (abs(BambooStick::rotation.x) > 0.031f) {
if (BambooStick::rotation.x >= 0.f)
BambooStick::rotation.x -= 0.03;
else
BambooStick::rotation.x += 0.03;
}

if (abs(BambooStick::rotation.z) > 0.031f) {
if (BambooStick::rotation.z >= 0.f)
BambooStick::rotation.z -= 0.03;
else
BambooStick::rotation.z += 0.03;
}
}

void BambooStick::render() {
updateRotation();
glPushMatrix();
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);
glTranslatef(position.x, position.y, position.z);
glRotatef(maxRotation*sin((BambooStick::rotation.z / maxRotation)*1.570796), 0, 0, 1);
glRotatef(maxRotation*sin((BambooStick::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 @@ -58,7 +69,7 @@ void BambooStick::render() {

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

void BambooStick::generate(std::default_random_engine * generator) {
Expand Down
5 changes: 3 additions & 2 deletions BambooStick.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include "Entity.h"
#include "Leaf.h"
#include "Map.h"

class BambooStick : public Entity{
public:
Expand All @@ -17,6 +18,7 @@ class BambooStick : public Entity{
~BambooStick();

void render();
static void updateRotation();
Segment * getSegment(int x);

private:
Expand All @@ -33,10 +35,9 @@ class BambooStick : public Entity{
float width, height;
GLUquadricObj *qobj;
std::vector<Segment *> * segments;
Position dRotation, rotation;
static Position rotation;

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

4 changes: 2 additions & 2 deletions Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@


Camera::Camera() {
position.z = 10.f;
position.y = 1.f;
position.z = -90.f;
position.y = 100.f;
position.x = position.lx = position.angleVertical = position.ly = position.angle = position.deltaAngle = position.deltaAngleVertical = position.deltaMove = 0;
position.lz = -10.f;
speed = 17.f;
Expand Down
Binary file modified Debug/Bamboo.tlog/CL.read.1.tlog
Binary file not shown.
Binary file modified Debug/Bamboo.tlog/cl.write.1.tlog
Binary file not shown.
Binary file modified Debug/vc120.idb
Binary file not shown.
31 changes: 30 additions & 1 deletion Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "Perlin.h"
#include <iostream>

float Map::windX = 0.025f, Map::windZ = 0.5f;

Map::Map(std::default_random_engine * generator) {
entities = new std::vector<Entity *>();

Expand Down Expand Up @@ -34,7 +36,7 @@ Map::Map(std::default_random_engine * generator) {
hi = (float)(10 * z) + 5.f;
lo = (float)(10 * z) - 4.5f;
float genZ = lo + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX / (hi - lo)));
e = new BambooStick(qobj, generator, genX, 0, -genZ);
e = new BambooStick(qobj, generator, genX, -0.3f, -genZ);
}
entities->push_back(e);
}
Expand All @@ -45,7 +47,34 @@ Map::Map(std::default_random_engine * generator) {
Map::~Map() {
}

void Map::updateWind() {
if (!(rand() % 100)) {
if (!(rand() % 2))
Map::windX += 0.01f;
else
Map::windX -= 0.01f;
}

if (!(rand() % 100)) {
if (!(rand() % 2))
Map::windZ += 0.01f;
else
Map::windZ -= 0.01f;
}

if (!(rand() % 3000)) {
Map::windX = -Map::windX;
}

if (!(rand() % 10000)) {
Map::windZ = -Map::windZ;
}
}

void Map::render() {

updateWind();

for (int i = 0; i < entities->size(); i++)
(*entities)[i]->render();
}
4 changes: 4 additions & 0 deletions Map.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ class Map {
std::vector<Entity *> * entities;
GLUquadric * qobj;
float width, height;

void updateWind();
public:
Map(std::default_random_engine * generator);
~Map();

static float windX, windZ;

void render();
};

1 change: 1 addition & 0 deletions gkom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ void displayObjects() {
glPushMatrix();

map->render();
BambooStick::updateRotation();

glPopMatrix();
}
Expand Down

0 comments on commit 690fd00

Please sign in to comment.