...
| Code Block | ||||||||
|---|---|---|---|---|---|---|---|---|
| ||||||||
#include "nwnx_area"
const float SM_WIND_SHADER_NONE = 0.00;
const float SM_WIND_SHADER_ETHEREAL = 0.01;
const float SM_WIND_SHADER_ULTRAVISION = 0.02;
void SetWindShader(object oPlayer, float fWindShader=SM_WIND_SHADER_NONE);
void SetWindShader(object oPlayer, float fWindShader=SM_WIND_SHADER_NONE)
{
object oArea = GetArea(oPlayer);
// I'm using the default game vector, a normalized vector (length 1) would be "easier", but I have not tested it
vector vDirection = Vector(1.0, 1.0, 0.0);
int nWindPower = NWNX_Area_GetWindPower(oArea);
float fYaw, fPitch;
switch(nWindPower)
{
case 0:
fYaw = 0.0;
fPitch = 0.0;
break;
case 1:
fYaw = 100.0;
fPitch = 3.0;
break;
case 2:
fYaw = 150.0;
fPitch = 5.0;
break;
}
// We will work with the squared modulus to avoid the use of sqrt() operation in the shader
float fSqModulus = IntToFloat(2*nWindPower*nWindPower);
//We want the shader to see fSqModulus + fWindShader
fSqModulus+=fWindShader;
// From the desired result, calculate the magnitude we will use for the NWNX_Player_UpdateWind function
float fMagnitude = fSqModulus/2.0; // 2.0 is the squared modulus of vDirection
fMagnitude = sqrt(fMagnitude);
// Apply it to the player
NWNX_AreaPlayer_UpdateWind(oPlayer, vDirection, fMagnitude, fYaw, fPitch);
} |
...