Level and screen projections (now with resize handling)

Post your example zscripts/ACS scripts/etc here.

Level and screen projections (now with resize handling)

Postby KeksDose » Fri May 03, 2019 8:54 am

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 allExpand view
// 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.)

Feel free to post suggestions, questions about usage, or issues you encountered.
Last edited by KeksDose on Sun May 19, 2019 5:04 pm, edited 1 time in total.
User avatar
KeksDose
zscript must burn
 
Joined: 05 Jul 2007
Location: Pastry kitchen, Hell

Re: Level and screen projections (+ free aiming)

Postby m8f » Fri May 03, 2019 9:13 am

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
m8f
 
 
 
Joined: 29 Dec 2017
Discord: m8f#0629
Github ID: mmaulwurff

Re: Level and screen projections (+ free aiming)

Postby Nash » Fri May 03, 2019 10:13 am

Siiiiiiiick, thanks for this!

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

User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes
Operating System: Windows 10/8.1/8 64-bit
Graphics Processor: nVidia with Vulkan support

Re: Level and screen projections (+ free aiming)

Postby KeksDose » Fri May 03, 2019 3:24 pm

@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
KeksDose
zscript must burn
 
Joined: 05 Jul 2007
Location: Pastry kitchen, Hell

Re: Level and screen projections (+ free aiming)

Postby DabbingSquidward » Sat May 04, 2019 1:15 am

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
DabbingSquidward
 
Joined: 08 Nov 2017
Location: Germany

Re: Level and screen projections (+ free aiming)

Postby KeksDose » Sat May 04, 2019 2:39 pm

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
KeksDose
zscript must burn
 
Joined: 05 Jul 2007
Location: Pastry kitchen, Hell

Re: Level and screen projections (+ free aiming)

Postby Nash » Sat May 04, 2019 6:52 pm

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
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes
Operating System: Windows 10/8.1/8 64-bit
Graphics Processor: nVidia with Vulkan support

Re: Level and screen projections (+ free aiming)

Postby Gutawer » Sun May 05, 2019 1:55 am

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
Gutawer
User Accounts Assistant
 
Joined: 16 Apr 2016
Discord: Gutawer#3431

Re: Level and screen projections (+ free aiming)

Postby KeksDose » Sun May 05, 2019 2:50 pm

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
KeksDose
zscript must burn
 
Joined: 05 Jul 2007
Location: Pastry kitchen, Hell

Re: Level and screen projections (+ free aiming)

Postby kodi » Mon May 06, 2019 12:16 pm

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
kodi
Proscrastinator
 
 
 
Joined: 06 May 2013

Re: Level and screen projections (+ free aiming)

Postby Nash » Thu May 09, 2019 11:29 am

Another suggestion: option to enable distance scaling with projected image. Probably would be easier done if the projections were drawn using Shape2D...
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes
Operating System: Windows 10/8.1/8 64-bit
Graphics Processor: nVidia with Vulkan support

Re: Level and screen projections (+ free aiming)

Postby KeksDose » Sat May 11, 2019 6:11 am

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
KeksDose
zscript must burn
 
Joined: 05 Jul 2007
Location: Pastry kitchen, Hell

Re: Level and screen projections (+ free aiming)

Postby kodi » Sun May 12, 2019 9:24 am

You said you were going to release it, so I just waited patiently. Had much else to work on too!
User avatar
kodi
Proscrastinator
 
 
 
Joined: 06 May 2013

Re: Level and screen projections (+ free aiming)

Postby KeksDose » Sun May 19, 2019 5:04 pm

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 allExpand view
// 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
KeksDose
zscript must burn
 
Joined: 05 Jul 2007
Location: Pastry kitchen, Hell

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

Postby m8f » Mon May 20, 2019 10:17 am

Will there be a git repository for libeye? One may want to submodule it.
User avatar
m8f
 
 
 
Joined: 29 Dec 2017
Discord: m8f#0629
Github ID: mmaulwurff


Return to Script Library

Who is online

Users browsing this forum: No registered users and 1 guest