Commit 678f84e9 authored by hybrid's avatar hybrid

Changed some internals of the Volume light and gave it an interface.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1171 dfc29bdd-3216-0410-991c-e03cc46cb475
parent b8642656
// Copyright (C) 2002-2007 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
//
// created by Dean Wadsworth aka Varmint Dec 31 2007
#ifndef __I_VOLUME_LIGHT_SCENE_NODE_H_INCLUDED__
#define __I_VOLUME_LIGHT_SCENE_NODE_H_INCLUDED__
#include "ISceneNode.h"
namespace irr
{
namespace scene
{
class IVolumeLightSceneNode : public ISceneNode
{
public:
//! constructor
IVolumeLightSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id,
const core::vector3df& position,
const core::vector3df& rotation,
const core::vector3df& scale)
: ISceneNode(parent, mgr, id, position, rotation, scale) {};
//! Returns type of the scene node
virtual ESCENE_NODE_TYPE getType() const { return ESNT_CUBE; }
virtual void setSubDivideU (const u32 inU) =0;
virtual void setSubDivideV (const u32 inV) =0;
virtual u32 getSubDivideU () const =0;
virtual u32 getSubDivideV () const =0;
virtual void setFootColour(const video::SColor inColour) =0;
virtual void setTailColour(const video::SColor inColour) =0;
virtual video::SColor getFootColour () const =0;
virtual video::SColor getTailColour () const =0;
};
} // end namespace scene
} // end namespace irr
#endif
...@@ -113,6 +113,7 @@ ...@@ -113,6 +113,7 @@
#include "IReferenceCounted.h" #include "IReferenceCounted.h"
#include "IVideoDriver.h" #include "IVideoDriver.h"
#include "IVideoModeList.h" #include "IVideoModeList.h"
#include "IVolumeLightSceneNode.h"
#include "IWriteFile.h" #include "IWriteFile.h"
#include "IXMLReader.h" #include "IXMLReader.h"
#include "IXMLWriter.h" #include "IXMLWriter.h"
......
...@@ -151,7 +151,6 @@ void CCameraFPSSceneNode::animate( u32 timeMs ) ...@@ -151,7 +151,6 @@ void CCameraFPSSceneNode::animate( u32 timeMs )
LastAnimationTime = timeMs; LastAnimationTime = timeMs;
} }
// update position // update position
core::vector3df pos = getPosition(); core::vector3df pos = getPosition();
...@@ -172,10 +171,10 @@ void CCameraFPSSceneNode::animate( u32 timeMs ) ...@@ -172,10 +171,10 @@ void CCameraFPSSceneNode::animate( u32 timeMs )
RelativeRotation.Y *= -1.0f; RelativeRotation.Y *= -1.0f;
RelativeRotation.Y += (0.5f - cursorpos.X) * RotateSpeed; RelativeRotation.Y += (0.5f - cursorpos.X) * RotateSpeed;
RelativeRotation.X = core::clamp ( RelativeRotation.X + (0.5f - cursorpos.Y) * RotateSpeed, RelativeRotation.X = core::clamp(
-MAX_VERTICAL_ANGLE, RelativeRotation.X + (0.5f - cursorpos.Y) * RotateSpeed,
+MAX_VERTICAL_ANGLE -MAX_VERTICAL_ANGLE,
); +MAX_VERTICAL_ANGLE);
RelativeRotation.X *= -1.0f; RelativeRotation.X *= -1.0f;
RelativeRotation.Y *= -1.0f; RelativeRotation.Y *= -1.0f;
...@@ -230,7 +229,6 @@ void CCameraFPSSceneNode::animate( u32 timeMs ) ...@@ -230,7 +229,6 @@ void CCameraFPSSceneNode::animate( u32 timeMs )
} }
// write translation // write translation
setPosition(pos); setPosition(pos);
} }
...@@ -238,9 +236,9 @@ void CCameraFPSSceneNode::animate( u32 timeMs ) ...@@ -238,9 +236,9 @@ void CCameraFPSSceneNode::animate( u32 timeMs )
TargetVector = Target; TargetVector = Target;
Target += pos; Target += pos;
} }
void CCameraFPSSceneNode::allKeysUp() void CCameraFPSSceneNode::allKeysUp()
{ {
for (s32 i=0; i<6; ++i) for (s32 i=0; i<6; ++i)
......
...@@ -135,7 +135,7 @@ public: ...@@ -135,7 +135,7 @@ public:
glEnable(GL_ALPHA_TEST); glEnable(GL_ALPHA_TEST);
glEnable(GL_BLEND); glEnable(GL_BLEND);
if ( getTexelAlpha ( srcFact ) + getTexelAlpha ( dstFact ) ) if ( getTexelAlpha(srcFact) || getTexelAlpha(dstFact) )
{ {
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE); glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_TEXTURE); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_TEXTURE);
......
...@@ -22,7 +22,7 @@ CVolumeLightSceneNode::CVolumeLightSceneNode(ISceneNode* parent, ISceneManager* ...@@ -22,7 +22,7 @@ CVolumeLightSceneNode::CVolumeLightSceneNode(ISceneNode* parent, ISceneManager*
const video::SColor tail, const video::SColor tail,
const core::vector3df& position, const core::vector3df& position,
const core::vector3df& rotation, const core::vector3df& scale) const core::vector3df& rotation, const core::vector3df& scale)
: ISceneNode(parent, mgr, id, position, rotation, scale), Buffer(0), : IVolumeLightSceneNode(parent, mgr, id, position, rotation, scale),
LPDistance(8.0f), SubdivideU(subdivU), SubdivideV(subdivV), LPDistance(8.0f), SubdivideU(subdivU), SubdivideV(subdivV),
FootColour(foot), TailColour(tail), FootColour(foot), TailColour(tail),
LightDimensions(core::vector3df(1.0f, 1.2f, 1.0f)) LightDimensions(core::vector3df(1.0f, 1.2f, 1.0f))
...@@ -35,26 +35,17 @@ CVolumeLightSceneNode::CVolumeLightSceneNode(ISceneNode* parent, ISceneManager* ...@@ -35,26 +35,17 @@ CVolumeLightSceneNode::CVolumeLightSceneNode(ISceneNode* parent, ISceneManager*
} }
//! destructor
CVolumeLightSceneNode::~CVolumeLightSceneNode()
{
if (Buffer)
Buffer->drop();
}
void CVolumeLightSceneNode::addToBuffer(video::S3DVertex v) void CVolumeLightSceneNode::addToBuffer(video::S3DVertex v)
{ {
const s32 tnidx = Buffer->Vertices.linear_reverse_search(v); const s32 tnidx = Buffer.Vertices.linear_reverse_search(v);
const bool alreadyIn = (tnidx != -1); const bool alreadyIn = (tnidx != -1);
u16 nidx = (u16)tnidx; u16 nidx = (u16)tnidx;
if (!alreadyIn) { if (!alreadyIn) {
nidx = Buffer->Vertices.size(); nidx = Buffer.Vertices.size();
Buffer->Indices.push_back(nidx); Buffer.Indices.push_back(nidx);
Buffer->Vertices.push_back(v); Buffer.Vertices.push_back(v);
} else } else
Buffer->Indices.push_back(nidx); Buffer.Indices.push_back(nidx);
} }
...@@ -64,10 +55,10 @@ void CVolumeLightSceneNode::constructLight() ...@@ -64,10 +55,10 @@ void CVolumeLightSceneNode::constructLight()
const f32 ax = LightDimensions.X * 0.5f; // X Axis const f32 ax = LightDimensions.X * 0.5f; // X Axis
const f32 az = LightDimensions.Z * 0.5f; // Z Axis const f32 az = LightDimensions.Z * 0.5f; // Z Axis
if (Buffer) Buffer.Vertices.clear();
Buffer->drop(); Buffer.Vertices.reallocate(6+12*(SubdivideU+SubdivideV));
Buffer = new SMeshBuffer(); Buffer.Indices.clear();
Buffer.Indices.reallocate(6+12*(SubdivideU+SubdivideV));
//draw the bottom foot.. the glowing region //draw the bottom foot.. the glowing region
addToBuffer(video::S3DVertex(-ax, 0, az, 0,0,0, FootColour, 0, 1)); addToBuffer(video::S3DVertex(-ax, 0, az, 0,0,0, FootColour, 0, 1));
addToBuffer(video::S3DVertex(ax , 0, az, 0,0,0, FootColour, 1, 1)); addToBuffer(video::S3DVertex(ax , 0, az, 0,0,0, FootColour, 1, 1));
...@@ -169,13 +160,13 @@ void CVolumeLightSceneNode::constructLight() ...@@ -169,13 +160,13 @@ void CVolumeLightSceneNode::constructLight()
bz += bzStep; bz += bzStep;
} }
Buffer->recalculateBoundingBox(); Buffer.recalculateBoundingBox();
Buffer->Material.MaterialType = video::EMT_ONETEXTURE_BLEND; Buffer.Material.MaterialType = video::EMT_ONETEXTURE_BLEND;
Buffer->Material.MaterialTypeParam = pack_texureBlendFunc( video::EBF_SRC_COLOR, video::EBF_SRC_ALPHA, video::EMFN_MODULATE_1X ); Buffer.Material.MaterialTypeParam = pack_texureBlendFunc( video::EBF_SRC_COLOR, video::EBF_SRC_ALPHA, video::EMFN_MODULATE_1X );
Buffer->Material.Lighting = false; Buffer.Material.Lighting = false;
Buffer->Material.ZWriteEnable = false; Buffer.Material.ZWriteEnable = false;
} }
...@@ -185,18 +176,18 @@ void CVolumeLightSceneNode::render() ...@@ -185,18 +176,18 @@ void CVolumeLightSceneNode::render()
video::IVideoDriver* driver = SceneManager->getVideoDriver(); video::IVideoDriver* driver = SceneManager->getVideoDriver();
driver->setTransform(video::ETS_WORLD, AbsoluteTransformation); driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
driver->setMaterial(Buffer->Material); driver->setMaterial(Buffer.Material);
driver->drawVertexPrimitiveList( driver->drawVertexPrimitiveList(
Buffer->getVertices(), Buffer->getVertexCount(), Buffer.getVertices(), Buffer.getVertexCount(),
Buffer->getIndices(), Buffer->getIndexCount() / 3 , Buffer.getIndices(), Buffer.getIndexCount() / 3 ,
Buffer->getVertexType(), EPT_TRIANGLES); Buffer.getVertexType(), EPT_TRIANGLES);
} }
//! returns the axis aligned bounding box of this node //! returns the axis aligned bounding box of this node
const core::aabbox3d<f32>& CVolumeLightSceneNode::getBoundingBox() const const core::aabbox3d<f32>& CVolumeLightSceneNode::getBoundingBox() const
{ {
return Buffer->BoundingBox; return Buffer.BoundingBox;
} }
...@@ -205,13 +196,13 @@ void CVolumeLightSceneNode::OnRegisterSceneNode() ...@@ -205,13 +196,13 @@ void CVolumeLightSceneNode::OnRegisterSceneNode()
if (IsVisible) if (IsVisible)
{ {
//lie to sceneManager //lie to sceneManager
Buffer->Material.MaterialType = video::EMT_TRANSPARENT_ADD_COLOR; Buffer.Material.MaterialType = video::EMT_TRANSPARENT_ADD_COLOR;
Buffer->Material.MaterialTypeParam = 0.01f; Buffer.Material.MaterialTypeParam = 0.01f;
SceneManager->registerNodeForRendering(this, ESNRP_AUTOMATIC); SceneManager->registerNodeForRendering(this, ESNRP_AUTOMATIC);
//restore state //restore state
Buffer->Material.MaterialType = video::EMT_ONETEXTURE_BLEND; Buffer.Material.MaterialType = video::EMT_ONETEXTURE_BLEND;
Buffer->Material.MaterialTypeParam = pack_texureBlendFunc( video::EBF_SRC_COLOR, video::EBF_SRC_ALPHA, video::EMFN_MODULATE_1X ); Buffer.Material.MaterialTypeParam = pack_texureBlendFunc( video::EBF_SRC_COLOR, video::EBF_SRC_ALPHA, video::EMFN_MODULATE_1X );
} }
ISceneNode::OnRegisterSceneNode(); ISceneNode::OnRegisterSceneNode();
} }
...@@ -224,7 +215,7 @@ void CVolumeLightSceneNode::OnRegisterSceneNode() ...@@ -224,7 +215,7 @@ void CVolumeLightSceneNode::OnRegisterSceneNode()
//! to directly modify the material of a scene node. //! to directly modify the material of a scene node.
video::SMaterial& CVolumeLightSceneNode::getMaterial(u32 i) video::SMaterial& CVolumeLightSceneNode::getMaterial(u32 i)
{ {
return Buffer->Material; return Buffer.Material;
} }
...@@ -286,7 +277,7 @@ ISceneNode* CVolumeLightSceneNode::clone(ISceneNode* newParent, ISceneManager* n ...@@ -286,7 +277,7 @@ ISceneNode* CVolumeLightSceneNode::clone(ISceneNode* newParent, ISceneManager* n
newManager, ID, SubdivideU, SubdivideV, FootColour, TailColour, RelativeTranslation); newManager, ID, SubdivideU, SubdivideV, FootColour, TailColour, RelativeTranslation);
nb->cloneMembers(this, newManager); nb->cloneMembers(this, newManager);
nb->Buffer->Material = Buffer->Material; nb->Buffer.Material = Buffer.Material;
nb->drop(); nb->drop();
return nb; return nb;
......
...@@ -7,14 +7,14 @@ ...@@ -7,14 +7,14 @@
#ifndef __VOLUME_LIGHT_SCENE_NODE_H_INCLUDED__ #ifndef __VOLUME_LIGHT_SCENE_NODE_H_INCLUDED__
#define __VOLUME_LIGHT_SCENE_NODE_H_INCLUDED__ #define __VOLUME_LIGHT_SCENE_NODE_H_INCLUDED__
#include "ISceneNode.h" #include "IVolumeLightSceneNode.h"
#include "SMeshBuffer.h" #include "SMeshBuffer.h"
namespace irr namespace irr
{ {
namespace scene namespace scene
{ {
class CVolumeLightSceneNode : public ISceneNode class CVolumeLightSceneNode : public IVolumeLightSceneNode
{ {
public: public:
...@@ -27,9 +27,6 @@ namespace scene ...@@ -27,9 +27,6 @@ namespace scene
const core::vector3df& rotation = core::vector3df(0,0,0), const core::vector3df& rotation = core::vector3df(0,0,0),
const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f)); const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f));
//! destructor
virtual ~CVolumeLightSceneNode();
virtual void OnRegisterSceneNode(); virtual void OnRegisterSceneNode();
//! renders the node. //! renders the node.
...@@ -59,25 +56,25 @@ namespace scene ...@@ -59,25 +56,25 @@ namespace scene
//! Creates a clone of this scene node and its children. //! Creates a clone of this scene node and its children.
virtual ISceneNode* clone(ISceneNode* newParent=0, ISceneManager* newManager=0); virtual ISceneNode* clone(ISceneNode* newParent=0, ISceneManager* newManager=0);
void setSubDivideU (const u32 inU) { SubdivideU = inU; } virtual void setSubDivideU (const u32 inU) { SubdivideU = inU; }
void setSubDivideV (const u32 inV) { SubdivideV = inV; } virtual void setSubDivideV (const u32 inV) { SubdivideV = inV; }
u32 getSubDivideU () const { return SubdivideU; } virtual u32 getSubDivideU () const { return SubdivideU; }
u32 getSubDivideV () const { return SubdivideV; } virtual u32 getSubDivideV () const { return SubdivideV; }
void setFootColour(const video::SColor inColouf) { FootColour = inColouf; } virtual void setFootColour(const video::SColor inColouf) { FootColour = inColouf; }
void setTailColour(const video::SColor inColouf) { TailColour = inColouf; } virtual void setTailColour(const video::SColor inColouf) { TailColour = inColouf; }
video::SColor getFootColour () const { return FootColour; } virtual video::SColor getFootColour () const { return FootColour; }
video::SColor getTailColour () const { return TailColour; } virtual video::SColor getTailColour () const { return TailColour; }
private: private:
void addToBuffer(video::S3DVertex v); void addToBuffer(video::S3DVertex v);
void constructLight(); void constructLight();
SMeshBuffer * Buffer; SMeshBuffer Buffer;
f32 LPDistance; // Distance to hypothetical lightsource point -- affects fov angle f32 LPDistance; // Distance to hypothetical lightsource point -- affects fov angle
u32 SubdivideU; // Number of subdivisions in U and V space. u32 SubdivideU; // Number of subdivisions in U and V space.
...@@ -87,7 +84,7 @@ namespace scene ...@@ -87,7 +84,7 @@ namespace scene
video::SColor FootColour; // Color at the source video::SColor FootColour; // Color at the source
video::SColor TailColour; // Color at the end. video::SColor TailColour; // Color at the end.
core::vector3df LightDimensions; // LightDimensions.Y Distance of shooting -- Length of beams core::vector3df LightDimensions; // LightDimensions.Y Distance of shooting -- Length of beams
// LightDimensions.X and LightDimensions.Z determine the size/dimension of the plane // LightDimensions.X and LightDimensions.Z determine the size/dimension of the plane
}; };
...@@ -96,3 +93,4 @@ namespace scene ...@@ -96,3 +93,4 @@ namespace scene
} // end namespace irr } // end namespace irr
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment