Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/spaceshipcontrol/src/world_entities/environments/water.cc @ 6509

Last change on this file since 6509 was 6471, checked in by bensch, 19 years ago

orxonox/trunk: testing, but not working

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