Re: ZScript "Standard Library" - Brainstorming

ZZYZX wrote:I'm actually talking about whatever coordinate that often gets stored in the shaders as W and means distance from screen plane to the point (it's just that there is no vector4 IIRC and just easier to store it as Z, as Z is unused otherwise).
That's needed so that user code can take the -1..1 coordinates and draw with corresponding virtual screen size to scale their pictures according to the distance to the point.
ZZYZX wrote:What does the regular HUD code do in this case? Does it render twice? It's not supposed to work outside of the drawing hooks, so maybe just use whatever matrix that's active in currently drawn half? (this may as well make zero sense because I don't know how VR works really)
dpJudas wrote:Yes, but the problem is that the depth is unknown when you only have a Vector2 for the screen position. However, if you multiply the depth value with the vector returned by the unproject function I listed, then you get the vector you are interested in (which is exactly what the SSAO pass does, using the zbuffer to get the depth).
dpJudas wrote:ZZYZX wrote:I think this should be native and based on the active renderer, in Screen or StatusBar class. Probably sbar, since active statusbar affects viewport size.
Also, it probably should return a vector3 with -1..1 coordinates where 0 is the center of the screen, and Z coordinate would be the distance from the screen plane.
Assuming you're talking about eye/view space, the Z coordinate would always be 1. Getting from there to world space would mean multiplying with the inverse of the world to eye normal matrix (just doing the inverse rotate from Viewpoint is probably easier). To get the point the user clicked at requires a follow up ray shooting.
The code required to do the unproject and project looks like this (in pseudo C++):
(snip)
Major Cooke wrote:By the way, whoever wants cylindrical hitbox detection, ZScript allows it.
It was easier than I thought.
- Code: Select all • Expand view
override bool CanCollideWith(Actor other, bool passive)
{
if (!passive)
{
if (!other) return false;
return (Distance2D(other) <= other.radius);
}
return true;
}
//'waiter' is a variable that ticks down elsewhere, once per tic doing waiter--;
// When it hits 0, it shuts off bTHRUACTORS.
override bool CanCollideWith(Actor other, bool passive)
{
if (!passive)
{
if (!other || other is "DWMonster" || other is "DarwinianPlayer") return false;
if (other is "DWBuilding")
{
if (Distance2D(other) <= other.Radius)
{
if (waiter > 0) return false;
bTHRUACTORS = true;
waiter = 7;
angle += 180;
vel.x *= -1.0;
vel.y *= -1.0;
return true;
}
return false;
}
}
return true;
}
Gez wrote:I think this ought to be included in a standard library, if not in GZDoom itself. It's a variant of the RandomSpawner.