Image Effect Scope / Night Vision
by Jonathan Farris · 06/02/2005 (1:50 am) · 23 comments
Download Code File
All of this code was inspired by froggy on the IRC channel, so credit is given to him for inspiring this work.
Installation
MAKE A BACKUP OF YOUR SOURCE BEFORE DOING ANY MOD
Download the zip file, and move the files into your source tree. Add GuiViewport.cc in the gui directory, and all of the files in the gui/IProc directory to your project. Compile, and you are done.
Fire up your script editor and open up example/starter.fps/client/ui/playGui.gui
Before the line
Launch torque, enter your mission, and you should have a big green box!
Wow.... thats because the default mode is night vision.
Open up the console and type:
Using the Effect Window in script
The follow script commands are supplied:
obj.setEffect( index or name )
- This selects the current effect.
obj.getEffectIndex()
- Retruns the index of the current effect.
obj.getEffectName( [index] )
- Return the name of the effect index, or if index is not supplied, the name of the current effect.
obj.getEffectParamName( param_index )
- param_index is an integer. This function returns the name of the param_index'th parameter.
obj.getEffectParam( param_name )
- Returns the value of the specified effect parameter.
obj.setEffectParam( param_name, param_value )
- Set the value of an effect parameter.
So for example, say you are using the night vision mode...
the scope color to red.
Most transforms support the following parameters:
border_size - specifies the border width in pixels.
border_color - color of the border.
interlace_size - erases every nth row.
interlace_alpha - The alpha of the erasure.
The Night vision scope supports:
color - color of the scope output.
The Video effect supports:
ChanceOfNoise - (-1 - 100) percent chance of the transmission having noise. -1 disables
ChanceOfFailure - (-1 - 100) percent chance of the transmission having a failure -1 disables
FailureDelay - number of frames before the effect re-draws after a failure.
StandardDelay - number of frames before the effect re-draws normally.
ForceError - (boolean) set to true to force Error blocks.
ForceFailure - (boolean) set to true to force transmission errors to occur.
Notes
The camera code for camera mode really needs some work, but overlay mode works very well.
To add a new effect take a look at ImageProcessor.h, IP_Config.cc, and IP_Null.cc in the IProc directory.
All of this code was inspired by froggy on the IRC channel, so credit is given to him for inspiring this work.
Installation
MAKE A BACKUP OF YOUR SOURCE BEFORE DOING ANY MOD
Download the zip file, and move the files into your source tree. Add GuiViewport.cc in the gui directory, and all of the files in the gui/IProc directory to your project. Compile, and you are done.
Fire up your script editor and open up example/starter.fps/client/ui/playGui.gui
Before the line
new GuiBitmapCtrl(CenterPrintDlg) {Add:new GuiViewport(EffWin) {
profile = "GuiDefaultProfile";
horizSizing = "width";
vertSizing = "height";
position = "160 100";
extent = "320 240";
minExtent = "240 240";
visible = "1";
cameraZRot = "0";
forceFOV = "0";
isOverlay = "true";
};Launch torque, enter your mission, and you should have a big green box!
Wow.... thats because the default mode is night vision.
Open up the console and type:
effWin.setEffect(3);You should now be treated to some trippy graphics.... unless my code is broken which is entirely possible. Good thing you made a backup eh?
Using the Effect Window in script
The follow script commands are supplied:
obj.setEffect( index or name )
- This selects the current effect.
obj.getEffectIndex()
- Retruns the index of the current effect.
obj.getEffectName( [index] )
- Return the name of the effect index, or if index is not supplied, the name of the current effect.
obj.getEffectParamName( param_index )
- param_index is an integer. This function returns the name of the param_index'th parameter.
obj.getEffectParam( param_name )
- Returns the value of the specified effect parameter.
obj.setEffectParam( param_name, param_value )
- Set the value of an effect parameter.
So for example, say you are using the night vision mode...
effWin.setEffectParam( border_size, 2 ); effWin.setEffectParam( border_color, "1.0, 0, 0, 0.80"); effWin.setEffectParam( color, "1.0, 0, 0, 1.0" );Would draw a 2 pixel border in slightly transparent red around the window, and change
the scope color to red.
Most transforms support the following parameters:
border_size - specifies the border width in pixels.
border_color - color of the border.
interlace_size - erases every nth row.
interlace_alpha - The alpha of the erasure.
The Night vision scope supports:
color - color of the scope output.
The Video effect supports:
ChanceOfNoise - (-1 - 100) percent chance of the transmission having noise. -1 disables
ChanceOfFailure - (-1 - 100) percent chance of the transmission having a failure -1 disables
FailureDelay - number of frames before the effect re-draws after a failure.
StandardDelay - number of frames before the effect re-draws normally.
ForceError - (boolean) set to true to force Error blocks.
ForceFailure - (boolean) set to true to force transmission errors to occur.
Notes
The camera code for camera mode really needs some work, but overlay mode works very well.
To add a new effect take a look at ImageProcessor.h, IP_Config.cc, and IP_Null.cc in the IProc directory.
About the author
#22
Everyone needs this anyway.
How and where should I initialize those 2 variables, I'm just tired of seeing the Warnings on compile.
As I said before this works with TGE1.5.2, everyone should have it at least to see what it does and if anyone has any trouble getting this in, let me know I've got it into Torque1.5.2 many times... lol.
03/16/2009 (1:37 pm)
*Bump* Everyone needs this anyway.
How and where should I initialize those 2 variables, I'm just tired of seeing the Warnings on compile.
As I said before this works with TGE1.5.2, everyone should have it at least to see what it does and if anyone has any trouble getting this in, let me know I've got it into Torque1.5.2 many times... lol.
#23
getServerConnection is now getConnectionToServer
04/09/2009 (10:29 am)
If anyones getting a guiviewport error like I did with the serverconnection, its changed as follows....getServerConnection is now getConnectionToServer

Torque Owner CSMP
MP Studios
There was an error inside GuiViewport in the setEffect function that was returning "Null" and vs2008 was not liking it.
GuiViewPort.cc line 339 directly below: object->setImageProcessor( x ); Add:
Please correct me if there is a more efficient method.
and im getting these two warnings
not sure if/where to initialize them, seems like it works i just dont like seeing these.
P.S. this does compile with TGE1.5.2 and VS2008 and works very well... Must Have Resource.