Skip to content
Permalink
Browse files

Section: BONUS! Interactive Light

  • Loading branch information...
enobayram committed Nov 14, 2015
1 parent 8a1b8be commit 4b5208dd7efd5d562b54ace76751d97ec3d74ce0
Showing with 50 additions and 2 deletions.
  1. BIN light_bulb.png
  2. +41 −1 text_and_shaders.cpp
  3. +9 −1 text_and_shaders.ini
BIN +14 KB light_bulb.png
Binary file not shown.
@@ -1,14 +1,54 @@
#include <orx.h>

orxOBJECT * light_bulb;

// Now we need to keep the viewport in a global variable
orxVIEWPORT * viewport;

// This method will be called whenever Orx needs the parameters for our shader
orxSTATUS orxFASTCALL lightPosHandler(const orxEVENT *_pstEvent) {
if(_pstEvent->eID == orxSHADER_EVENT_SET_PARAM) {
orxSHADER_EVENT_PAYLOAD * payload = (orxSHADER_EVENT_PAYLOAD *)_pstEvent->pstPayload;
if(strcmp(payload->zParamName, "LightPos") == 0) {
// Here we set the "LightPos" parameter to be the mouse position
orxMouse_GetPosition(&(payload->vValue));
payload->vValue.fZ = 100;
}
}
return orxSTATUS_SUCCESS;
}

orxSTATUS orxFASTCALL Init()
{
orxViewport_CreateFromConfig("Viewport");
viewport = orxViewport_CreateFromConfig("Viewport");
orxObject_CreateFromConfig("TextObject");

// Create the light bulb
light_bulb = orxObject_CreateFromConfig("LightBulb");

// Register our shader parameter handler
orxEvent_AddHandler ( orxEVENT_TYPE_SHADER, lightPosHandler);
return orxSTATUS_SUCCESS;
}

orxSTATUS orxFASTCALL Run()
{
orxVECTOR mousePos;
orxVECTOR mouseInWorld;

// Get the mouse position on screen
orxMouse_GetPosition(&mousePos);

// Get the mouse position in the game world,
// note that the mouse might not be in our game's window
orxVECTOR * inWindow = orxRender_GetWorldPosition(&mousePos, viewport, &mouseInWorld);
if(inWindow) {
mouseInWorld.fZ = -0.1;
} else {
mouseInWorld.fZ = -2; // Out of camera frustum, so the light_bulb is hidden
}
orxObject_SetPosition(light_bulb, &mouseInWorld);

return orxSTATUS_SUCCESS;
}

@@ -55,6 +55,14 @@ void main() {
}"
BorderColor = (0,0,255) ; Let's make the border blue, just for fun.
LightPos = (200,150,100) ;
LightColor = (1,0.7,0.7) ;
LightColor = (1,1,0.18) ;
UseCustomParam = true ; Since the LightPos parameter will change at runtime we need this.

[LightBulb]
Graphic = @
Texture = light_bulb.png
Pivot = (64,53,0)
Scale = 0.5
Position = (0,0,-0.1)

@plump.ini@

0 comments on commit 4b5208d

Please sign in to comment.
You can’t perform that action at this time.