Level and screen projections (now with resize handling)

Post your example zscripts/ACS scripts/etc here.
Forum rules
The Projects forums are only for projects. If you are asking questions about a project, either find that project's thread, or start a thread in the General section instead.

Got a cool project idea but nothing else? Put it in the project ideas thread instead!

Projects for any Doom-based engine (especially 3DGE) are perfectly acceptable here too.

Please read the full rules for more details.
User avatar
KeksDose
 
 
Posts: 591
Joined: Thu Jul 05, 2007 6:13 pm

Level and screen projections (now with resize handling)

Post by KeksDose »

Use this zscript library I've made to deal with screen and world projections. It allows you to:

1. Find an actor's screen position (maybe to draw text over a target, like HudMessageOnActor)
2. Click a screen location to fire a bullet in that direction
3. Determine if a location is in your view

in both opengl and old software render modes. You don't need to know any of the involved maths, and it runs very very fast, too.

Examples included are free aiming (kinda like in Metroid Prime 3), drawing actors' bounding boxes and... a candle with some text over it. Just load the pk3 to test this. Here's an easy example:

Code: Select all

// Setup:
proj.CacheResolution();
proj.CacheFov(players [consoleplayer].fov);
proj.OrientForRenderOverlay(event);
proj.BeginProjection();

// Now you can project as much as you like, just like this:
proj.ProjectWorldPos(mo.vec3offset(0, 0, mo.height));

if(proj.IsInFront()) {
    let draw_pos = proj.ProjectToScreen();
    
    Screen.DrawText(
        smallfont,
        Font.CR_ICE,
        draw_pos.x,
        draw_pos.y,
        "achachachachach");
}
(You shouldn't view the free aim as a complete mod. It'll cause multiplayer issues. It merely demonstrates it works.)

You may do whatever you like with this. There's a lil note in the libeye directory. If you also include that, we're golden.

Feel free to post suggestions, questions about usage, or issues you encountered.
Last edited by KeksDose on Sat Aug 03, 2019 8:01 am, edited 2 times in total.
User avatar
m8f
 
 
Posts: 1433
Joined: Fri Dec 29, 2017 4:15 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Manjaro Linux
Location: Siberia (UTC+7)

Re: Level and screen projections (+ free aiming)

Post by m8f »

How does it compare to the similar functionality from Gutamatics? Does the coordinate results differ much?

This library seems to be easier to use.
User avatar
Nash
 
 
Posts: 17340
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: Level and screen projections (+ free aiming)

Post by Nash »

Siiiiiiiick, thanks for this!

Already found a bug: it doesn't handle screen size properly. :D

User avatar
KeksDose
 
 
Posts: 591
Joined: Thu Jul 05, 2007 6:13 pm

Re: Level and screen projections (+ free aiming)

Post by KeksDose »

@Nash: Looks like it's too early to thank me. I'll be working on it.

@m8f: Thanks! I hope modders will find this easy to use.

Both appear to output the same coordinates. I skipped a step concerning some depth business, cuz in gzd, it amounts to virtually no change. znear and zfar may ring a bell. I don't see deprojection or software render in Gutamatics, so I can't judge that.

Performance may be of interest. I tested my library to produce only 4% of the vm calls Gutamatics does, and it runs at least 3.5 times as fast.
User avatar
StroggVorbis
Posts: 861
Joined: Wed Nov 08, 2017 4:23 pm
Graphics Processor: nVidia with Vulkan support
Location: Germany

Re: Level and screen projections (+ free aiming)

Post by StroggVorbis »

I've seen your video about it in the WIP thread. Does that mean it can be used as a base for GoldenEye/Perfect Dark/TimeSplitters like aiming? :O

It also reminded me of the console in Bethesda's games, where you can click on entities and it would display a unique ID which you can use to do all sorts of stuff.
User avatar
KeksDose
 
 
Posts: 591
Joined: Thu Jul 05, 2007 6:13 pm

Re: Level and screen projections (+ free aiming)

Post by KeksDose »

Aye. Implementing such a thing properly and meaningfully sounds tough. I have doubts we'll see such a mod, since its easier to simply look with your mouse.

Concerning screen resize, I know what must be done. Given other projects and testing required, I'd estimate an update to this within Sunday in two weeks.
User avatar
Nash
 
 
Posts: 17340
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: Level and screen projections (+ free aiming)

Post by Nash »

I have a suggestion:

Option to check if projection is not blocked by solid geometry or other actors. So if you can't see the thing, it will not project.
User avatar
Gutawer
User Accounts Assistant
Posts: 464
Joined: Sat Apr 16, 2016 6:01 am
Preferred Pronouns: She/Her

Re: Level and screen projections (+ free aiming)

Post by Gutawer »

KeksDose wrote: Both appear to output the same coordinates. I skipped a step concerning some depth business, cuz in gzd, it amounts to virtually no change. znear and zfar may ring a bell. I don't see deprojection or software render in Gutamatics, so I can't judge that.

Performance may be of interest. I tested my library to produce only 4% of the vm calls Gutamatics does, and it runs at least 3.5 times as fast.
Yeah, I never bothered to implement the software renderer or deprojection into Gutamatics, I hadn't really worked out the maths for the latter at the time and was never interested in bothering with the former. I'm also not massively interested in adding more in that area to it because I'd honestly rather spend my time coding it into gzdoom natively, since I remember Graf saying that's what would be preferrable (and also obviously because this now exists).

I'm also not surprised this runs much faster - mine spends a lot of time in VM calls doing manual matrix multiplication which is bound to be much slower than the dot product matrix multiplication you're doing. Gutamatics was more of an experiment that ended up influencing much better matrix/quaternion classes in the game engine project that I started (and need to finish, lol).
User avatar
KeksDose
 
 
Posts: 591
Joined: Thu Jul 05, 2007 6:13 pm

Re: Level and screen projections (+ free aiming)

Post by KeksDose »

Strange situation when the main attraction of a library wasn't its focus. I had more to say but I forgot, so do your best on your projects!

@Nash: Plenty of considerations to be made here. I'll see what can be done.
User avatar
kodi
 
 
Posts: 1351
Joined: Mon May 06, 2013 8:02 am

Re: Level and screen projections (+ free aiming)

Post by kodi »

Thanks a ton for this! I tried but couldn't make heads or tails of your PM in the end. Awesome to have my deprojection 'accurized' now! :D
User avatar
Nash
 
 
Posts: 17340
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: Level and screen projections (+ free aiming)

Post by Nash »

Another suggestion: option to enable distance scaling with projected image. Probably would be easier done if the projections were drawn using Shape2D...
User avatar
KeksDose
 
 
Posts: 591
Joined: Thu Jul 05, 2007 6:13 pm

Re: Level and screen projections (+ free aiming)

Post by KeksDose »

I'll let the projector return the view distance, then you can rescale the screen (or shape) yourself for drawing.

@kodi: I think I should've asked beforehand what you already have. If it works now and everybody agrees, that's good.
User avatar
kodi
 
 
Posts: 1351
Joined: Mon May 06, 2013 8:02 am

Re: Level and screen projections (+ free aiming)

Post by kodi »

You said you were going to release it, so I just waited patiently. Had much else to work on too!
User avatar
KeksDose
 
 
Posts: 591
Joined: Thu Jul 05, 2007 6:13 pm

Re: Level and screen projections (+ free aiming)

Post by KeksDose »

You and me both. As scheduled, here is the update for resize handling... (well, at least it was Sunday when I started typing♪)

With the Le_Viewport struct, you can bring a projected position into view if it has been resized with screenblocks and status bar scaling. For this, I named two spaces: Viewport is what you see, while the scene is what gets shifted by the status bar.

I only updated the bounding box viewer and opengl text candle to use this handling at the moment. Scopes for the free aim are a mess to figure out, so aiming will be weird with the status bar, till I sort it out.

For now, you can turn around and play with screenblocks to see how the new checks work. If you hold alt fire, you will see the viewport and scene bounds. Here's how to use it:

Code: Select all

// Assuming proj is a projector you set up like in the OP. This brings the projected
// position into your resized viewport at your window resolution.
Le_Viewport viewport;
viewport.FromHud();

proj.ProjectWorldPos(mo.pos + (0, 0, 0.5 * mo.height));
let draw_pos = viewport.SceneToWindow(proj.ProjectToNormal());

// (Insert some draw stuff here)      
I'm not forgetting about visibility or scaling. For now, I'm fixing up Guncaster (rather, I've been doing so for a while, and now we're crunching again). I should also document this. One step at a time.
User avatar
m8f
 
 
Posts: 1433
Joined: Fri Dec 29, 2017 4:15 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Manjaro Linux
Location: Siberia (UTC+7)

Re: Level and screen projections (now with resize handling)

Post by m8f »

Will there be a git repository for libeye? One may want to submodule it.

Return to “Script Library”