Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6464 was 6458, checked in by bensch, 19 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
RevLine 
[4597]1/*
[3416]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:
[4261]12   main-programmer: Benjamin Grauer
13   co-programmer: ...
[3411]14*/
15
[3590]16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
17
[6455]18#include "water.h"
19#include "factory.h"
[5356]20#include "load_param.h"
[3608]21
[6455]22#include "grid.h"
[6457]23#include "material.h"
[6455]24
[5356]25using namespace std;
[5357]26
[6455]27CREATE_FACTORY(Water, CL_WATER);
[3608]28
[4010]29
[6455]30Water::Water(const TiXmlElement* root)
[4010]31{
[6456]32  this->setClassID(CL_WATER, "Water");
[6457]33  this->toList(OM_ENVIRON);
[6456]34
[6455]35  this->resX = this->resY = 10;
[6458]36  this->sizeX = this->sizeY = 1.0f;
37  this->height = 0.5f;
[6455]38  this->grid = NULL;
[4010]39
[6455]40  if (root != NULL)
41    this->loadParams(root);
[6456]42
43  this->rebuildGrid();
[6457]44  this->waterMaterial = new Material();
[4010]45}
46
[6455]47Water::~Water()
[4261]48{
[6456]49  delete this->grid;
[6457]50  delete this->waterMaterial;
[4261]51}
52
[6455]53void Water::loadParams(const TiXmlElement* root)
[4010]54{
[6455]55  WorldEntity::loadParams(root);
[4620]56
[6455]57  LoadParam(root, "size", this, Water, setSize)
58      .describe("the size of the WaterSurface")
59      .defaultValues(2, 1.0f, 1.0f);
[6341]60
[6455]61  LoadParam(root, "resolution", this, Water, setResolution)
62      .describe("sets the resolution of the water surface")
63      .defaultValues(2, 10, 10);
[6458]64
65  LoadParam(root, "height", this, Water, setHeight)
66      .describe("the height of the Waves")
67      .defaultValues(1, 0.5f);
[4012]68}
[3803]69
[6455]70void Water::rebuildGrid()
[4012]71{
[6455]72  if (this->grid != NULL)
73    delete this->grid;
74  this->grid = new Grid(this->sizeX, this->sizeY, this->resX, this->resY);
[3411]75
[6456]76  this->setModel(this->grid, 0);
[6307]77}
[3411]78
[6455]79void Water::setResolution(unsigned int resX, unsigned int resY)
[3803]80{
[6455]81  this->resX = resX;
82  this->resY = resY;
[3803]83}
84
[6455]85void Water::setSize(float sizeX, float sizeY)
[3803]86{
[6455]87  this->sizeX = sizeX;
88  this->sizeY = sizeY;
[3803]89}
90
[6458]91void Water::setHeight(float height)
92{
93  this->height = height;
94}
95
96
[6457]97void Water::draw() const
98{
99  this->waterMaterial->select();
100  WorldEntity::draw();
101}
[6456]102
103void Water::tick(float dt)
104{
[6457]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    {
[6458]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);
[6457]112    }
113  }
[6458]114  this->grid->rebuildNormals(this->height);
[6456]115}
Note: See TracBrowser for help on using the repository browser.