Jump to content
john_the_late

Dynamically creating/setting a render surface

Recommended Posts

Hi, I am trying to get a "helmet camera to monitor" script to work. My script works when I hardcode the render surface values, but when I tried to make the script dynamic (so that it can be called with parameters instead of having to make a lot of copy scripts) I ran into an issue with the render surface. It expects a name, but doesn't want it in the String format. Later on, it is used as a String, and that is not a problem.

Here is the code I used for my script file (based on this):
 

params ["_monitor", "_target"]; 

_pipcam = format ["pipsc_%1", _target]; 
hint _pipcam; 

/* create render surface */ 
_monitor setObjectTexture [0, "#(argb,512,512,1)r2t(_pipcam,1)"]; // this line gives the error 

/* create camera and stream to render surface */ 
_cam = "camera" camCreate [0,0,0]; 
_cam cameraEffect ["Terminate", "Back", _pipcam]; // to reset cam 
_cam cameraEffect ["Internal", "Back", _pipcam]; 

/* attach cam to head */ 
_cam attachTo [_target, [0,0,0.18], "head"]; 
_cam camSetFov 0.4; 

/* adjust cam orientation */ 
addMissionEventHandler ["Draw3D", { 
    _dir = 
    	(_target selectionPosition "head") 
        	vectorFromTo 
        (_target selectionPosition "head" vectorAdd (getCameraViewDirection _target)); 
    _cam setVectorDirAndUp [ 
    	_dir, 
        _dir vectorCrossProduct [-(_dir select 1), _dir select 0, 0] 
    ]; 
}];

 

Share this post


Link to post
Share on other sites
params ["_monitor", "_target"]; 

_pipcam = format ["pipsc_%1", toLower (name _target)]; 
hint _pipcam; 

/* create render surface */ 
_monitor setObjectTexture [0, format ["#(argb,512,512,1)r2t(%1,1)",_pipcam]];
/* create camera and stream to render surface */ 
_cam = "camera" camCreate [0,0,0]; 
_cam cameraEffect ["Terminate", "Back", _pipcam]; // to reset cam 
_cam cameraEffect ["Internal", "Back", _pipcam]; 

/* attach cam to head */ 
_cam attachTo [_target, [0,0,0.18], "head"]; 
_cam camSetFov 0.4; 

/* adjust cam orientation */ 
addMissionEventHandler ["Draw3D", { 
    _dir = 
    	(_target selectionPosition "head") 
        	vectorFromTo 
        (_target selectionPosition "head" vectorAdd (getCameraViewDirection _target)); 
    _cam setVectorDirAndUp [ 
    	_dir, 
        _dir vectorCrossProduct [-(_dir select 1), _dir select 0, 0] 
    ]; 
}];

 

  • Like 3

Share this post


Link to post
Share on other sites

Thanks!

 

Yeah, I'm a complete dumbass. :D For some reason, I managed to miss the fact that the entire definition is a string already. It's quite embarrassing since I'm not even new to programming... :huh2:

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×