Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/environments/water.cc @ 6458

Last change on this file since 6458 was 6458, checked in by bensch, 18 years ago

orxonox/trunk: wave now also rebuilds the Normals (do not know if this is really necesarry, but i sure hope so for all the work :)

File size: 2.4 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14*/
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
17
18#include "water.h"
19#include "factory.h"
20#include "load_param.h"
21
22#include "grid.h"
23#include "material.h"
24
25using namespace std;
26
27CREATE_FACTORY(Water, CL_WATER);
28
29
30Water::Water(const TiXmlElement* root)
31{
32  this->setClassID(CL_WATER, "Water");
33  this->toList(OM_ENVIRON);
34
35  this->resX = this->resY = 10;
36  this->sizeX = this->sizeY = 1.0f;
37  this->height = 0.5f;
38  this->grid = NULL;
39
40  if (root != NULL)
41    this->loadParams(root);
42
43  this->rebuildGrid();
44  this->waterMaterial = new Material();
45}
46
47Water::~Water()
48{
49  delete this->grid;
50  delete this->waterMaterial;
51}
52
53void Water::loadParams(const TiXmlElement* root)
54{
55  WorldEntity::loadParams(root);
56
57  LoadParam(root, "size", this, Water, setSize)
58      .describe("the size of the WaterSurface")
59      .defaultValues(2, 1.0f, 1.0f);
60
61  LoadParam(root, "resolution", this, Water, setResolution)
62      .describe("sets the resolution of the water surface")
63      .defaultValues(2, 10, 10);
64
65  LoadParam(root, "height", this, Water, setHeight)
66      .describe("the height of the Waves")
67      .defaultValues(1, 0.5f);
68}
69
70void Water::rebuildGrid()
71{
72  if (this->grid != NULL)
73    delete this->grid;
74  this->grid = new Grid(this->sizeX, this->sizeY, this->resX, this->resY);
75
76  this->setModel(this->grid, 0);
77}
78
79void Water::setResolution(unsigned int resX, unsigned int resY)
80{
81  this->resX = resX;
82  this->resY = resY;
83}
84
85void Water::setSize(float sizeX, float sizeY)
86{
87  this->sizeX = sizeX;
88  this->sizeY = sizeY;
89}
90
91void Water::setHeight(float height)
92{
93  this->height = height;
94}
95
96
97void Water::draw() const
98{
99  this->waterMaterial->select();
100  WorldEntity::draw();
101}
102
103void Water::tick(float dt)
104{
105  phase += dt *.1;
106  for (unsigned int i = 0; i < this->grid->rows(); i++)
107  {
108    for (unsigned int j = 0; j < this->grid->columns(); j++)
109    {
110      this->grid->height(i,j) = this->height*sin(((float)i/(float)this->grid->rows() *phase)+
111          this->height*cos((float)j/(float)this->grid->columns()) * phase);
112    }
113  }
114  this->grid->rebuildNormals(this->height);
115}
Note: See TracBrowser for help on using the repository browser.