/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Benjamin Grauer co-programmer: ... */ #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY #include "water.h" #include "factory.h" #include "load_param.h" #include "grid.h" #include "material.h" #include "resource_manager.h" #include "shader.h" #include "skybox.h" using namespace std; CREATE_FACTORY(Water, CL_WATER); Water::Water(const TiXmlElement* root) { this->setClassID(CL_WATER, "Water"); this->toList(OM_ENVIRON); this->resX = this->resY = 10; this->sizeX = this->sizeY = 1.0f; this->height = 0.5f; this->grid = NULL; if (root != NULL) this->loadParams(root); this->rebuildGrid(); this->waterMaterial = new Material(); this->waterShader = (Shader*)ResourceManager::getInstance()->load("shaders/water.vert", SHADER, RP_GAME, (void*)"shaders/water.frag"); } Water::~Water() { delete this->grid; delete this->waterMaterial; } void Water::loadParams(const TiXmlElement* root) { WorldEntity::loadParams(root); LoadParam(root, "size", this, Water, setSize) .describe("the size of the WaterSurface") .defaultValues(2, 1.0f, 1.0f); LoadParam(root, "resolution", this, Water, setResolution) .describe("sets the resolution of the water surface") .defaultValues(2, 10, 10); LoadParam(root, "height", this, Water, setHeight) .describe("the height of the Waves") .defaultValues(1, 0.5f); } void Water::rebuildGrid() { if (this->grid != NULL) delete this->grid; this->grid = new Grid(this->sizeX, this->sizeY, this->resX, this->resY); this->setModel(this->grid, 0); } void Water::setResolution(unsigned int resX, unsigned int resY) { this->resX = resX; this->resY = resY; } void Water::setSize(float sizeX, float sizeY) { this->sizeX = sizeX; this->sizeY = sizeY; } void Water::setHeight(float height) { this->height = height; } void Water::draw() const { SkyBox::enableCubeMap(); // this->waterShader->activateShader(); // this->waterMaterial->select(); WorldEntity::draw(); //Shader::deactivateShader(); SkyBox::disableCubeMap(); } void Water::tick(float dt) { phase += dt *.1; for (unsigned int i = 0; i < this->grid->rows(); i++) { for (unsigned int j = 0; j < this->grid->columns(); j++) { this->grid->height(i,j) = this->height*sin(((float)i/(float)this->grid->rows() *phase)+ this->height*cos((float)j/(float)this->grid->columns()) * phase * 2.0); } } this->grid->rebuildNormals(this->height); }