Add PercCameraNode, use it for rain. Sadly the results atm are weird, I need to investigate...

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@7668 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria
2011-02-10 01:56:52 +00:00
parent ea02deac1e
commit 2f2b18df33
10 changed files with 197 additions and 11 deletions

View File

@@ -77,6 +77,8 @@ supertuxkart_SOURCES = \
graphics/particle_kind.hpp \
graphics/particle_kind_manager.cpp \
graphics/particle_kind_manager.hpp \
graphics/per_camera_node.cpp \
graphics/per_camera_node.hpp \
graphics/rain.cpp \
graphics/rain.hpp \
graphics/shadow.cpp \

View File

@@ -23,6 +23,7 @@
#include "graphics/camera.hpp"
#include "graphics/material_manager.hpp"
#include "graphics/particle_kind_manager.hpp"
#include "graphics/per_camera_node.hpp"
#include "guiengine/engine.hpp"
#include "guiengine/modaldialog.hpp"
#include "guiengine/scalable_font.hpp"
@@ -541,6 +542,15 @@ scene::IMeshSceneNode *IrrDriver::addMesh(scene::IMesh *mesh,
return m_scene_manager->addMeshSceneNode(mesh, parent);
} // addMesh
// ----------------------------------------------------------------------------
PerCameraNode *IrrDriver::addPerCameraMesh(scene::IMesh* mesh, scene::ICameraSceneNode* camera,
scene::ISceneNode *parent)
{
return new PerCameraNode((parent != NULL ? parent : m_scene_manager->getRootSceneNode()), m_scene_manager, -1, camera, mesh);
} // addMesh
// ----------------------------------------------------------------------------
/** Adds a billboard node to scene.
*/

View File

@@ -38,6 +38,7 @@ using namespace irr;
class Camera;
class Kart;
class PerCameraNode;
struct VideoMode
{
@@ -120,6 +121,7 @@ public:
scene::IMeshSceneNode*addOctTree(scene::IMesh *mesh);
scene::IMeshSceneNode*addMesh(scene::IMesh *mesh,
scene::ISceneNode *parent=NULL);
PerCameraNode *addPerCameraMesh(scene::IMesh* mesh, scene::ICameraSceneNode* node, scene::ISceneNode *parent = NULL);
scene::ISceneNode *addBillboard(const core::dimension2d< f32 > size, video::ITexture *texture, scene::ISceneNode* parent=NULL);
scene::IParticleSystemSceneNode

View File

@@ -0,0 +1,70 @@
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2011 Marianne Gagnon
// based on code Copyright (C) 2002-2010 Nikolaus Gebhardt
//
// 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 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "graphics/irr_driver.hpp"
#include "graphics/per_camera_node.hpp"
PerCameraNode::PerCameraNode(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id,
scene::ICameraSceneNode* camera, scene::IMesh* mesh)
: IDummyTransformationSceneNode(parent, mgr, id)
{
#ifdef DEBUG
if (camera)
setName(camera->getName());
#endif
m_camera = camera;
//m_child = mgr->addMeshSceneNode(mesh, this);
m_child = mgr->addCubeSceneNode(0.5f, this, -1);
setAutomaticCulling(scene::EAC_OFF);
parent->addChild(this);
}
PerCameraNode::~PerCameraNode()
{
}
void PerCameraNode::render()
{
if (irr_driver->getSceneManager()->getSceneNodeRenderPass() != scene::ESNRP_SKY_BOX)
{
return;
}
scene::ICameraSceneNode* curr_cam = irr_driver->getSceneManager()->getActiveCamera();
//printf("cam %s <--> %s\n", curr_cam->getName(), m_camera->getName());
m_child->setVisible(curr_cam == m_camera);
}
void PerCameraNode::OnRegisterSceneNode()
{
irr_driver->getSceneManager()->registerNodeForRendering(this, scene::ESNRP_SKY_BOX);
ISceneNode::OnRegisterSceneNode();
}
void PerCameraNode::setCamera(scene::ICameraSceneNode* camera)
{
m_camera = camera;
#ifdef DEBUG
if (camera)
setDebugName(camera->getDebugName());
#endif
}

View File

@@ -0,0 +1,67 @@
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2011 Marianne Gagnon
// based on code Copyright (C) 2002-2010 Nikolaus Gebhardt
//
// 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 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_PER_CAMERA_HPP
#define HEADER_PER_CAMERA_HPP
#include "irrlicht.h"
using namespace irr;
/**
* \brief manages smoke particle effects
* \ingroup graphics
*/
class PerCameraNode : public scene::IDummyTransformationSceneNode
{
private:
core::matrix4 RelativeTransformationMatrix;
core::aabbox3d<f32> Box;
scene::ICameraSceneNode* m_camera;
scene::ISceneNode* m_child;
public:
PerCameraNode(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id,
scene::ICameraSceneNode* camera, scene::IMesh* mesh);
virtual ~PerCameraNode();
//! returns the axis aligned bounding box of this node
virtual const core::aabbox3d<f32>& getBoundingBox() const { return Box; }
//! Returns a reference to the current relative transformation matrix.
//! This is the matrix, this scene node uses instead of scale, translation
//! and rotation.
virtual core::matrix4& getRelativeTransformationMatrix() { return RelativeTransformationMatrix; }
//! Returns the relative transformation of the scene node.
virtual core::matrix4 getRelativeTransformation() const { return RelativeTransformationMatrix; }
void setCamera(scene::ICameraSceneNode* camera);
virtual void OnRegisterSceneNode();
virtual void render();
virtual scene::ESCENE_NODE_TYPE getType() const { return scene::ESNT_DUMMY_TRANSFORMATION; }
scene::ISceneNode* getChild() { return m_child; }
};
#endif

View File

@@ -20,6 +20,7 @@
#include "graphics/irr_driver.hpp"
#include "graphics/material_manager.hpp"
#include "graphics/material.hpp"
#include "graphics/per_camera_node.hpp"
#include "graphics/rain.hpp"
#include "utils/constants.hpp"
@@ -32,7 +33,7 @@ const float TEXTURE_X_TILES[RAIN_RING_COUNT] = { 2.0f, 2.5f, 3.5f, 5.0f, 8.0f };
const float TEXTURE_Y_TILES[RAIN_RING_COUNT] = { 8.0f, 7.0f, 6.0f, 4.0f, 4.0f };
Rain::Rain(irr::scene::ISceneNode* parent)
Rain::Rain(irr::scene::ICameraSceneNode* camera, irr::scene::ISceneNode* parent)
{
m_y = 0.0f;
@@ -90,8 +91,9 @@ Rain::Rain(irr::scene::ISceneNode* parent)
scene::SMesh* mesh = new scene::SMesh();
mesh->addMeshBuffer(buffer);
mesh->recalculateBoundingBox();
m_node[r] = irr_driver->addMesh(mesh);
m_node[r] = irr_driver->addPerCameraMesh(mesh, camera);
if (parent != NULL) m_node[r]->setParent(parent);
mesh->drop();
@@ -119,7 +121,7 @@ void Rain::update(float dt)
//const int count = m_materials.size();
for (int m=0; m<RAIN_RING_COUNT; m++)
{
core::matrix4& matrix = m_node[m]->getMaterial(0).getTextureMatrix(0);
core::matrix4& matrix = m_node[m]->getChild()->getMaterial(0).getTextureMatrix(0);
matrix.setTextureTranslate(0, m_y);
}
@@ -131,7 +133,13 @@ void Rain::setPosition(const core::vector3df& position)
{
for (int m=0; m<RAIN_RING_COUNT; m++)
{
m_node[m]->setPosition(position);
m_node[m]->getChild()->setPosition(position);
}
} // setPosition
// ----------------------------------------------------------------------------
void Rain::setCamera(scene::ICameraSceneNode* camera)
{
for (int n=0; n<RAIN_RING_COUNT; n++) m_node[n]->setCamera(camera);
}

View File

@@ -20,22 +20,27 @@
#ifndef HEADER_RAIN_HPP
#define HEADER_RAIN_HPP
class PerCameraNode;
#include <irrlicht.h>
const int RAIN_RING_COUNT = 5;
class Rain
{
irr::scene::ISceneNode* m_node[RAIN_RING_COUNT];
PerCameraNode* m_node[RAIN_RING_COUNT];
std::vector<irr::video::SMaterial*> m_materials;
float m_y;
public:
Rain(irr::scene::ISceneNode* parent);
Rain(irr::scene::ICameraSceneNode* camera, irr::scene::ISceneNode* parent);
~Rain();
void update(float dt);
void setPosition(const irr::core::vector3df& position);
void setCamera(scene::ICameraSceneNode* camera);
};
#endif

View File

@@ -424,6 +424,7 @@
95D950D20FE473CA002E10AD /* stk_config.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95D950CE0FE473CA002E10AD /* stk_config.cpp */; };
95D950D30FE473CA002E10AD /* user_config.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95D950D00FE473CA002E10AD /* user_config.cpp */; };
95DFC5021106933B00A043A9 /* slip_stream.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95DFC5001106933B00A043A9 /* slip_stream.cpp */; };
95E1FCDF130369EB004D83CC /* per_camera_node.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95E1FCDD130369EB004D83CC /* per_camera_node.cpp */; };
95E246BE111A2959000C965D /* confirm_resolution_dialog.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95E246BC111A2959000C965D /* confirm_resolution_dialog.cpp */; };
95E6A0C011DCF37800AE088A /* addons_loading.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95E6A0BE11DCF37800AE088A /* addons_loading.cpp */; };
95ECA10010124C5000D47C5F /* button_widget.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95ECA0EC10124C5000D47C5F /* button_widget.cpp */; };
@@ -991,7 +992,6 @@
9556A87F119EF976009C558F /* options_screen_video.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = options_screen_video.hpp; path = ../../states_screens/options_screen_video.hpp; sourceTree = SOURCE_ROOT; };
955764E412FB67EF005CE479 /* btKartRaycast.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = btKartRaycast.cpp; path = ../../physics/btKartRaycast.cpp; sourceTree = SOURCE_ROOT; };
955764E512FB67EF005CE479 /* btKartRaycast.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = btKartRaycast.hpp; path = ../../physics/btKartRaycast.hpp; sourceTree = SOURCE_ROOT; };
9559DE7D12FF777600350DE8 /* rain.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = rain.h; path = games/supertuxkart/src/graphics/rain.h; sourceTree = SYSTEM_DEVELOPER_DIR; };
9559DE7E12FF777600350DE8 /* rain.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = rain.cpp; path = games/supertuxkart/src/graphics/rain.cpp; sourceTree = SYSTEM_DEVELOPER_DIR; };
955DE88110042701006A4F3C /* check_manager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = check_manager.cpp; path = ../../tracks/check_manager.cpp; sourceTree = SOURCE_ROOT; };
955DE88210042701006A4F3C /* check_manager.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = check_manager.hpp; path = ../../tracks/check_manager.hpp; sourceTree = SOURCE_ROOT; };
@@ -1412,6 +1412,9 @@
95D950D10FE473CA002E10AD /* user_config.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = user_config.hpp; path = ../../config/user_config.hpp; sourceTree = SOURCE_ROOT; };
95DFC5001106933B00A043A9 /* slip_stream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = slip_stream.cpp; path = ../../graphics/slip_stream.cpp; sourceTree = SOURCE_ROOT; };
95DFC5011106933B00A043A9 /* slip_stream.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = slip_stream.hpp; path = ../../graphics/slip_stream.hpp; sourceTree = SOURCE_ROOT; };
95E1FCDD130369EB004D83CC /* per_camera_node.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = per_camera_node.cpp; path = ../../graphics/per_camera_node.cpp; sourceTree = SOURCE_ROOT; };
95E1FCDE130369EB004D83CC /* per_camera_node.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = per_camera_node.hpp; path = ../../graphics/per_camera_node.hpp; sourceTree = SOURCE_ROOT; };
95E1FCE0130369F4004D83CC /* rain.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = rain.hpp; path = ../../graphics/rain.hpp; sourceTree = SOURCE_ROOT; };
95E246BC111A2959000C965D /* confirm_resolution_dialog.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = confirm_resolution_dialog.cpp; path = ../../states_screens/dialogs/confirm_resolution_dialog.cpp; sourceTree = SOURCE_ROOT; };
95E246BD111A2959000C965D /* confirm_resolution_dialog.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = confirm_resolution_dialog.hpp; path = ../../states_screens/dialogs/confirm_resolution_dialog.hpp; sourceTree = SOURCE_ROOT; };
95E6A0BE11DCF37800AE088A /* addons_loading.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = addons_loading.cpp; path = ../../states_screens/dialogs/addons_loading.cpp; sourceTree = SOURCE_ROOT; };
@@ -1553,8 +1556,10 @@
9542FD4B12D3E0D700C00366 /* particle_kind.hpp */,
9528C71412D69494006E9167 /* particle_kind_manager.cpp */,
9528C71512D69494006E9167 /* particle_kind_manager.hpp */,
95E1FCDD130369EB004D83CC /* per_camera_node.cpp */,
95E1FCDE130369EB004D83CC /* per_camera_node.hpp */,
9559DE7E12FF777600350DE8 /* rain.cpp */,
9559DE7D12FF777600350DE8 /* rain.h */,
95E1FCE0130369F4004D83CC /* rain.hpp */,
952A153D103F66D600B1895D /* shadow.cpp */,
952A153E103F66D600B1895D /* shadow.hpp */,
952A153F103F66D600B1895D /* skid_marks.cpp */,
@@ -3346,6 +3351,7 @@
955764E612FB67EF005CE479 /* btKartRaycast.cpp in Sources */,
9559DE7F12FF777600350DE8 /* rain.cpp in Sources */,
9592DC6D13021B350039DBC8 /* minimal_race_gui.cpp in Sources */,
95E1FCDF130369EB004D83CC /* per_camera_node.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@@ -921,6 +921,22 @@ void Kart::update(float dt)
}
} // update
//-----------------------------------------------------------------------------
void Kart::setCamera(Camera *camera)
{
m_camera = camera;
#ifdef DEBUG
m_camera->getCameraSceneNode()->setName((m_kart_properties->getIdent() + "'s camera").c_str());
#endif
if (m_rain)
{
m_rain->setCamera( camera->getCameraSceneNode() );
}
}
//-----------------------------------------------------------------------------
/** Sets zipper time, and apply one time additional speed boost. It can be
* used with a specific material, in which case the zipper parmaters are
@@ -1488,7 +1504,7 @@ void Kart::loadData(RaceManager::KartType type, Track* track, bool animatedModel
if (UserConfigParams::m_weather_effects && track->getWeatherType() == WEATHER_RAIN && type == RaceManager::KT_PLAYER)
{
m_rain = new Rain(NULL);
m_rain = new Rain((m_camera != NULL ? m_camera->getCameraSceneNode() : NULL), NULL);
}
//m_water_splash_system = new WaterSplash(this);

View File

@@ -265,7 +265,7 @@ public:
const Camera* getCamera () const {return m_camera;}
// ------------------------------------------------------------------------
/** Sets the camera for this kart. Takes ownership of the camera and will delete it. */
void setCamera(Camera *camera) {m_camera=camera; }
void setCamera(Camera *camera);
// ------------------------------------------------------------------------
/** Returns the current powerup. */
const Powerup *getPowerup () const { return &m_powerup; }