Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: Texture loading with GL_TEXTURE_* in ResourceManager and Material

File size: 2.7 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
25#include "resource_manager.h"
26#include "shader.h"
27
28
29using namespace std;
30
31CREATE_FACTORY(Water, CL_WATER);
32
33
34Water::Water(const TiXmlElement* root)
35{
36  this->setClassID(CL_WATER, "Water");
37  this->toList(OM_ENVIRON);
38
39  this->resX = this->resY = 10;
40  this->sizeX = this->sizeY = 1.0f;
41  this->height = 0.5f;
42  this->grid = NULL;
43
44  if (root != NULL)
45    this->loadParams(root);
46
47  this->rebuildGrid();
48  this->waterMaterial = new Material();
49  this->waterShader = (Shader*)ResourceManager::getInstance()->load("shaders/water.vert", SHADER, RP_GAME, (void*)"shaders/water.frag");
50
51}
52
53Water::~Water()
54{
55  delete this->grid;
56  delete this->waterMaterial;
57}
58
59void Water::loadParams(const TiXmlElement* root)
60{
61  WorldEntity::loadParams(root);
62
63  LoadParam(root, "size", this, Water, setSize)
64      .describe("the size of the WaterSurface")
65      .defaultValues(2, 1.0f, 1.0f);
66
67  LoadParam(root, "resolution", this, Water, setResolution)
68      .describe("sets the resolution of the water surface")
69      .defaultValues(2, 10, 10);
70
71  LoadParam(root, "height", this, Water, setHeight)
72      .describe("the height of the Waves")
73      .defaultValues(1, 0.5f);
74}
75
76void Water::rebuildGrid()
77{
78  if (this->grid != NULL)
79    delete this->grid;
80  this->grid = new Grid(this->sizeX, this->sizeY, this->resX, this->resY);
81
82  this->setModel(this->grid, 0);
83}
84
85void Water::setResolution(unsigned int resX, unsigned int resY)
86{
87  this->resX = resX;
88  this->resY = resY;
89}
90
91void Water::setSize(float sizeX, float sizeY)
92{
93  this->sizeX = sizeX;
94  this->sizeY = sizeY;
95}
96
97void Water::setHeight(float height)
98{
99  this->height = height;
100}
101
102
103void Water::draw() const
104{
105  this->waterShader->activateShader();
106//  this->waterMaterial->select();
107  WorldEntity::draw();
108  Shader::deactivateShader();
109}
110
111void Water::tick(float dt)
112{
113  phase += dt *.1;
114  for (unsigned int i = 0; i < this->grid->rows(); i++)
115  {
116    for (unsigned int j = 0; j < this->grid->columns(); j++)
117    {
118      this->grid->height(i,j) = this->height*sin(((float)i/(float)this->grid->rows() *phase)+
119          this->height*cos((float)j/(float)this->grid->columns()) * phase * 2.0);
120    }
121  }
122  this->grid->rebuildNormals(this->height);
123}
Note: See TracBrowser for help on using the repository browser.