Skip to content
Browse files

Ice Shader base and box sensor collision for once event type

  • Loading branch information...
1 parent f65551a commit 1e1919ab5ee6fa7f02119ced0137f18df2797033 @is06 committed Mar 28, 2012
Showing with 75 additions and 5 deletions.
  1. +1 −0 include/3d/AnimatedModel.h
  2. +3 −0 include/Shaders.h
  3. +42 −0 include/shader/IceShaderCallback.h
  4. +16 −2 src/3d/AnimatedModel.cpp
  5. +13 −3 src/Game.cpp
View
1 include/3d/AnimatedModel.h
@@ -79,6 +79,7 @@ class AnimatedModel : public ModelEntity
s32 currentAnimationId;
f32 currentAnimationSpeed;
map<s32, MeshAnimationInfo> animationList;
+ map<Sensor*, bool> sensorOnce;
};
#endif
View
3 include/Shaders.h
@@ -11,6 +11,9 @@ is06.com. Permissions beyond the scope of this license may be available at
struct Shaders
{
s32 diffuse;
+ s32 ice;
+ s32 metal;
+ s32 glass;
s32 verticalBlur;
s32 horizontalBlur;
};
View
42 include/shader/IceShaderCallback.h
@@ -0,0 +1,42 @@
+/******************************************************************************
+Invisible Spirit by Thomas Noury is licensed under a Creative Commons
+Attribution-NonCommercial-ShareAlike 3.0 Unported License. Based on a work at
+is06.com. Permissions beyond the scope of this license may be available at
+http://www.is06.com. Legal code in license.txt
+*******************************************************************************/
+
+#ifndef __ICE_SHADER_CALLBACK_H__
+#define __ICE_SHADER_CALLBACK_H__
+
+#include "../3d/Camera.h"
+
+using namespace irr;
+
+class IceShaderCallback : public video::IShaderConstantSetCallBack
+{
+ public:
+ const video::SMaterial* usedMaterial;
+
+ virtual void OnSetMaterial(const video::SMaterial& material)
+ {
+ usedMaterial = &material;
+ }
+
+ virtual void OnSetConstants(video::IMaterialRendererServices* services, s32 userData)
+ {
+ // Inversed world matrix
+ core::matrix4 invWorld = Game::getVideoDriver()->getTransform(video::ETS_WORLD);
+ services->setVertexShaderConstant("invWorldMatrix", invWorld.pointer(), 16);
+
+ // Camera position
+ core::vector3df pos = Game::getCurrentScene()->getActiveCamera()->getNode()->getAbsolutePosition();
+ services->setVertexShaderConstant("cameraPosition", reinterpret_cast<f32*>(&pos), 3);
+
+ // Light color
+ video::SColorf col(0.0f, 1.0f, 1.0f, 0.0f);
+ services->setVertexShaderConstant("lightColor", reinterpret_cast<f32*>(&col), 4);
+ }
+};
+
+#endif
+
View
18 src/3d/AnimatedModel.cpp
@@ -367,11 +367,25 @@ bool AnimatedModel::collidesWithPlaneSensor(PlaneSensor* sensor, EventType type)
/**
* Returns true if the object is in the box sensor
- * @todo manage event type
*/
bool AnimatedModel::isInBoxSensor(BoxSensor* sensor, EventType type)
{
- return sensor->getBox().isPointInside(mainNode->getPosition());
+ bool inside = sensor->getBox().isPointInside(mainNode->getPosition());
+ if (type == EVENT_ONCE) {
+ if (!sensorOnce[sensor]) {
+ if (inside) {
+ sensorOnce[sensor] = true;
+ return true;
+ }
+ } else {
+ if (!inside) {
+ sensorOnce[sensor] = false;
+ }
+ }
+ return false;
+ } else {
+ return inside;
+ }
}
/**
View
16 src/Game.cpp
@@ -17,6 +17,7 @@ is06.com. Permissions beyond the scope of this license may be available at
#include "../include/scene/SceneMenu.h"
#include "../include/scene/SceneGameplay.h"
#include "../include/shader/DiffuseShaderCallback.h"
+#include "../include/shader/IceShaderCallback.h"
#include "../include/ref/maps.h"
#include "../include/Translation.h"
@@ -345,13 +346,22 @@ void Game::initShaders()
if (gpuManager) {
// Shader Diffuse (2D Elements)
- DiffuseShaderCallback* cb = new DiffuseShaderCallback();
+ DiffuseShaderCallback* diffuseCallback = new DiffuseShaderCallback();
shaders.diffuse = gpuManager->addHighLevelShaderMaterialFromFiles(
"resource/shader/diffuse.vert", "vertexMain", video::EVST_VS_1_1,
"resource/shader/diffuse.frag", "pixelMain", video::EPST_PS_1_1,
- cb, video::EMT_TRANSPARENT_ALPHA_CHANNEL
+ diffuseCallback, video::EMT_TRANSPARENT_ALPHA_CHANNEL
);
- cb->drop();
+ diffuseCallback->drop();
+
+ // Ice shader
+ IceShaderCallback* iceCallback = new IceShaderCallback();
+ shaders.ice = gpuManager->addHighLevelShaderMaterialFromFiles(
+ "resource/shader/ice.vert", "vertexMain", video::EVST_VS_1_1,
+ "resource/shader/ice.frag", "pixelMain", video::EPST_PS_1_1,
+ iceCallback, video::EMT_SOLID
+ );
+ iceCallback->drop();
// Horizontal Blur Shader
shaders.horizontalBlur = gpuManager->addHighLevelShaderMaterialFromFiles(

0 comments on commit 1e1919a

Please sign in to comment.
Something went wrong with that request. Please try again.