by crowbars82 » Sat Jan 19, 2019 10:42 am
Hi everyone!
Can spotlights be defined similarly to the other dynamic lights?
For example a light that I have made to illuminate an actor when it fires their gun is:
Code: Select all
pointlight CROWENEMYFIRE
{
color 1.00 0.50 0.25
size 30
offset 0 32 0
}
... which then I can attach to the animation frame like this:
Code: Select all
Missile:
RTLG E 8 A_FaceTarget
RTLG F 8
RTLG G 8 Light("CROWENEMYFIRE") A_PosAttack
RTLG H 8
goto See
I am attempting to create a simple spotlight that will emit from a static actor's facing direction and simply point towards whatever is in front of it.
Can a spotlight be created like the other lights in GLDEFS?
I have downloaded and extracted
Steve's Flashlight Mod which I can see that the spotlight has been defined within the ZSCRIPT.txt, and I can identify how the spotlight is being attached to the player, however I am uncertain how to proceed for creating a standalone spotlight without using ZScript unless this is impossible at this stage?
Many thanks!
~Crow
Steve's Flashlight Mod ZSCRIPT.txt contents:
Code: Select all
version "3.3"
class Util {
play static void setupFlashlight (int playerID, int flashID) {
PlayerPawn act = PlayerPawn(ActorIterator.Create(playerID).Next());
if (act) {
ActorHeadLight light = ActorHeadLight(Actor.Spawn("ActorHeadLight"));
light.ChangeTid(flashID);
light.toFollow = act;
light.activate(null);
Util.LogDebug("Light created and 'attached'");
}
}
static void LogDebug (String text) {
if (CVar.GetCvar("debug")) {
Console.printf("[ZScript] "..text);
}
}
static int round (double num) {
int result = (num - floor(num) > 0.5) ? ceil(num) : floor(num);
return result;
}
}
class ActorHeadLight : Spotlight {
enum ELocation
{
HELMET = 0,
RIGHT_SHOULDER = 1,
LEFT_SHOULDER = 2,
CAMERA = 3
};
PlayerPawn toFollow;
Vector3 offset;
Vector3 finalOffset;
double zBump; // z offset for locations that are not CAMERA
double angleDiff;
double turnAnglePerTic;
bool ready;
bool on;
ELocation location;
void updateFromCvars () {
Color c = CVar.FindCVar("flashlight_color").GetString();
args[0] = c.r;
args[1] = c.g;
args[2] = c.b;
args[3] = CVar.FindCVar("flashlight_intensity").GetInt();
self.SpotInnerAngle = CVar.FindCVar("flashlight_inner").GetFloat();
self.SpotOuterAngle = CVar.FindCVar("flashlight_outer").GetFloat();
self.location = CVar.FindCVar("flashlight_location").GetInt();
Util.LogDebug("Light loc offset: "..self.offset);
}
override void Activate(Actor activator) {
updateFromCvars();
on = true;
super.Activate(activator);
}
override void DeActivate(Actor activator) {
on = false;
super.DeActivate(activator);
}
override void Tick() {
if (ready && on) {
switch (location) {
case HELMET:
offset = (0, 0, toFollow.player.viewheight + zBump);
break;
case RIGHT_SHOULDER:
offset = (toFollow.radius, 0, toFollow.player.viewheight + zBump);
break;
case LEFT_SHOULDER:
offset = (toFollow.radius * -1, 0, toFollow.player.viewheight + zBump);
break;
case CAMERA:
offset = (0, 0, toFollow.ViewHeight);
break;
default:
offset = (0, 0, 0);
}
A_SetAngle(toFollow.angle, 0);
Vector2 finalOffset2D = RotateVector ((offset.x, offset.y), toFollow.angle - 90.0);
finalOffset = (finalOffset2D.x, finalOffset2D.y, offset.z);
A_SetPitch(toFollow.pitch, SPF_INTERPOLATE);
SetOrigin(self.toFollow.pos + finalOffset, true);
} else if (on && self.toFollow) {
ready = true;
zBump = (toFollow.height - toFollow.viewheight) / 2;
Util.LogDebug('zBump assigned: '..zBump);
}
Super.Tick();
}
}
Hi everyone!
Can spotlights be defined similarly to the other dynamic lights?
For example a light that I have made to illuminate an actor when it fires their gun is:
[code]pointlight CROWENEMYFIRE
{
color 1.00 0.50 0.25
size 30
offset 0 32 0
}[/code]
... which then I can attach to the animation frame like this:
[code] Missile:
RTLG E 8 A_FaceTarget
RTLG F 8
RTLG G 8 Light("CROWENEMYFIRE") A_PosAttack
RTLG H 8
goto See[/code]
I am attempting to create a simple spotlight that will emit from a static actor's facing direction and simply point towards whatever is in front of it.
Can a spotlight be created like the other lights in GLDEFS?
I have downloaded and extracted [url=https://forum.zdoom.org/viewtopic.php?t=59429]Steve's Flashlight Mod[/url] which I can see that the spotlight has been defined within the ZSCRIPT.txt, and I can identify how the spotlight is being attached to the player, however I am uncertain how to proceed for creating a standalone spotlight without using ZScript unless this is impossible at this stage?
Many thanks!
~Crow
[b][u]Steve's Flashlight Mod ZSCRIPT.txt contents:[/u][/b]
[code]version "3.3"
class Util {
play static void setupFlashlight (int playerID, int flashID) {
PlayerPawn act = PlayerPawn(ActorIterator.Create(playerID).Next());
if (act) {
ActorHeadLight light = ActorHeadLight(Actor.Spawn("ActorHeadLight"));
light.ChangeTid(flashID);
light.toFollow = act;
light.activate(null);
Util.LogDebug("Light created and 'attached'");
}
}
static void LogDebug (String text) {
if (CVar.GetCvar("debug")) {
Console.printf("[ZScript] "..text);
}
}
static int round (double num) {
int result = (num - floor(num) > 0.5) ? ceil(num) : floor(num);
return result;
}
}
class ActorHeadLight : Spotlight {
enum ELocation
{
HELMET = 0,
RIGHT_SHOULDER = 1,
LEFT_SHOULDER = 2,
CAMERA = 3
};
PlayerPawn toFollow;
Vector3 offset;
Vector3 finalOffset;
double zBump; // z offset for locations that are not CAMERA
double angleDiff;
double turnAnglePerTic;
bool ready;
bool on;
ELocation location;
void updateFromCvars () {
Color c = CVar.FindCVar("flashlight_color").GetString();
args[0] = c.r;
args[1] = c.g;
args[2] = c.b;
args[3] = CVar.FindCVar("flashlight_intensity").GetInt();
self.SpotInnerAngle = CVar.FindCVar("flashlight_inner").GetFloat();
self.SpotOuterAngle = CVar.FindCVar("flashlight_outer").GetFloat();
self.location = CVar.FindCVar("flashlight_location").GetInt();
Util.LogDebug("Light loc offset: "..self.offset);
}
override void Activate(Actor activator) {
updateFromCvars();
on = true;
super.Activate(activator);
}
override void DeActivate(Actor activator) {
on = false;
super.DeActivate(activator);
}
override void Tick() {
if (ready && on) {
switch (location) {
case HELMET:
offset = (0, 0, toFollow.player.viewheight + zBump);
break;
case RIGHT_SHOULDER:
offset = (toFollow.radius, 0, toFollow.player.viewheight + zBump);
break;
case LEFT_SHOULDER:
offset = (toFollow.radius * -1, 0, toFollow.player.viewheight + zBump);
break;
case CAMERA:
offset = (0, 0, toFollow.ViewHeight);
break;
default:
offset = (0, 0, 0);
}
A_SetAngle(toFollow.angle, 0);
Vector2 finalOffset2D = RotateVector ((offset.x, offset.y), toFollow.angle - 90.0);
finalOffset = (finalOffset2D.x, finalOffset2D.y, offset.z);
A_SetPitch(toFollow.pitch, SPF_INTERPOLATE);
SetOrigin(self.toFollow.pos + finalOffset, true);
} else if (on && self.toFollow) {
ready = true;
zBump = (toFollow.height - toFollow.viewheight) / 2;
Util.LogDebug('zBump assigned: '..zBump);
}
Super.Tick();
}
}[/code]