|
|
878d83 |
|
|
|
878d83 |
#include <math.h></math.h>
|
|
|
878d83 |
#include <stdio.h></stdio.h>
|
|
|
878d83 |
#include <stdlib.h></stdlib.h>
|
|
|
878d83 |
#include <string.h></string.h>
|
|
|
878d83 |
|
|
|
878d83 |
#define GL_GLEXT_PROTOTYPES
|
|
|
878d83 |
#include <gl gl.h=""></gl>
|
|
|
878d83 |
#include <gl glext.h=""></gl>
|
|
|
878d83 |
#include <gl glu.h=""></gl>
|
|
|
878d83 |
|
|
|
878d83 |
#include <helianthus.h></helianthus.h>
|
|
|
878d83 |
|
|
|
878d83 |
|
|
|
878d83 |
#include "gl3d.inc.c"
|
|
|
878d83 |
#include "hmap.inc.c"
|
|
|
878d83 |
#include "water.inc.c"
|
|
|
878d83 |
|
|
|
878d83 |
|
|
|
878d83 |
double mx, my;
|
|
|
878d83 |
HMap hmap, wmap;
|
|
|
878d83 |
Water water;
|
|
|
878d83 |
|
|
|
878d83 |
|
|
|
878d83 |
void generate() {
|
|
|
878d83 |
hmapGenerate(&hmap);
|
|
|
878d83 |
for(int i = 0; i < HMAP_SIZE; ++i)
|
|
|
878d83 |
for(int j = 0; j < HMAP_SIZE; ++j)
|
|
|
878d83 |
wmap.map[i][j] = hmap.map[i][j] + 0.1;
|
|
|
878d83 |
for(int i = 0; i < 100; ++i)
|
|
|
878d83 |
waterCycle(&water, 1, 0.8, 0.0);
|
|
|
878d83 |
hmapCalcNormals(&hmap);
|
|
|
878d83 |
hmapCalcNormals(&wmap);
|
|
|
878d83 |
hmapBuildBuf(&hmap);
|
|
|
878d83 |
hmapBuildBuf(&wmap);
|
|
|
878d83 |
}
|
|
|
878d83 |
|
|
|
878d83 |
|
|
|
878d83 |
void init() {
|
|
|
878d83 |
hmapInit(&hmap, 1, 1, 1, 1, 1, 1);
|
|
|
878d83 |
hmapInit(&wmap, 1, 1, 0, 0, 1, 0.25);
|
|
|
878d83 |
waterInit(&water, &hmap, &wmap);
|
|
|
878d83 |
generate();
|
|
|
878d83 |
|
|
|
878d83 |
background(COLOR_BLACK);
|
|
|
878d83 |
}
|
|
|
878d83 |
|
|
|
878d83 |
|
|
|
878d83 |
void deinit() {
|
|
|
878d83 |
hmapDeinit(&hmap);
|
|
|
878d83 |
hmapDeinit(&wmap);
|
|
|
878d83 |
}
|
|
|
878d83 |
|
|
|
878d83 |
|
|
|
878d83 |
void draw() {
|
|
|
878d83 |
double pmx = mx, pmy = my;
|
|
|
878d83 |
mx = mouseX();
|
|
|
878d83 |
my = mouseY();
|
|
|
878d83 |
double dmx = mx - pmx;
|
|
|
878d83 |
double dmy = my - pmy;
|
|
|
878d83 |
|
|
|
878d83 |
if (keyWentDown("space"))
|
|
|
878d83 |
generate();
|
|
|
878d83 |
|
|
|
878d83 |
if (mouseDown("left")) {
|
|
|
878d83 |
cameraRot[1] += dmx;
|
|
|
878d83 |
cameraRot[0] += dmy;
|
|
|
878d83 |
}
|
|
|
878d83 |
|
|
|
878d83 |
if (mouseDown("right")) {
|
|
|
878d83 |
cameraPos[2] *= pow(1.01, dmy);
|
|
|
878d83 |
if (cameraPos[2] > -2) cameraPos[2] = -2;
|
|
|
878d83 |
}
|
|
|
878d83 |
|
|
|
878d83 |
begin3d();
|
|
|
878d83 |
cubeDraw(1);
|
|
|
878d83 |
hmapDraw(&hmap);
|
|
|
878d83 |
|
|
|
878d83 |
glDepthMask(GL_FALSE);
|
|
|
878d83 |
glPushMatrix();
|
|
|
878d83 |
glTranslated(0, 0, -0.01);
|
|
|
878d83 |
for(int i = 0; i < 1; ++i) {
|
|
|
878d83 |
hmapDraw(&wmap);
|
|
|
878d83 |
glTranslated(0, 0, 0.5);
|
|
|
878d83 |
}
|
|
|
878d83 |
glPopMatrix();
|
|
|
878d83 |
glDepthMask(GL_TRUE);
|
|
|
878d83 |
|
|
|
878d83 |
end3d();
|
|
|
878d83 |
}
|
|
|
878d83 |
|
|
|
878d83 |
|
|
|
878d83 |
int main() {
|
|
|
878d83 |
windowSetResizable(TRUE);
|
|
|
878d83 |
windowSetVariableFrameRate();
|
|
|
878d83 |
windowSetInit(&init);
|
|
|
878d83 |
windowSetDeinit(&deinit);
|
|
|
878d83 |
windowSetDraw(&draw);
|
|
|
878d83 |
windowRun();
|
|
|
878d83 |
return 0;
|
|
|
878d83 |
}
|