picoe / Eto.Veldrid

Veldrid control for Eto.Forms
MIT License
15 stars 6 forks source link

Request for help, if possible #3

Closed philstopford closed 5 years ago

philstopford commented 5 years ago

I forked this to try and get an etoViewport clone working (grid, etc.). Veldrid is confusing me slightly (I don't get multiple lines drawn, although the buffer seems to contain them). I wondered whether you might be able to spot my error in the forked repo. No urgency, and no obligation - just a request for hand-holding, if possible :)

ItEndsWithTens commented 5 years ago

I think I've got the problem sorted out! See philstopford/Eto.Veldrid#1 for the changes.

philstopford commented 5 years ago

Looks better - thank you. I'm having some issues with the EventHandlers, though. They fire, but the viewport doesn't update position or zoom. Still digging.

philstopford commented 5 years ago

Still trying to understand what I'm failing to understand :) - the EventHandlers fire, and the values appear to update, but the view never scrolls or zooms; I'm not sure what's causing this.

I'm also not able to capture key events at all, it seems.

ItEndsWithTens commented 5 years ago

Sorry, I hadn't had a chance to look at this yet; I'll get in there and poke around!

philstopford commented 5 years ago

Oh, I didn't mean to demand at all - abject apologies if it came across that way. I'm just registering my lack of progress :D

ItEndsWithTens commented 5 years ago

For what it's worth, this seems to be related to my use of Matrix4x4.CreateOrthographic instead of Matrix4x4.CreateOrthographicOffCenter, in the Draw method when setting the view matrix. I am admittedly inexperienced in graphics development, and to be totally honest I fail to grasp why the former stays locked in one place even though the vertex coordinates it's meant to render are changing.

In any event, the OffCenter version of CreateOrthographic allows specifying a left, right, bottom, and top; hacking in a few test fields that I change in the zoomIn and zoomOut methods shows it does in fact work for zooming, at least.

I believe left, right, bottom, and top should correspond to ovpSettings.minX, maxX, maxY, and minY, respectively (don't forget Vulkan coordinates increase from the top of the screen to the bottom). Currently those ovpSettings fields seem to always be 0, but if we can sort out why that's happening I think they'd do the trick.

philstopford commented 5 years ago

The min/max X/Y values are used in the zoom extents methodology, to fit the bounding box for the polylist and/or linelist to the view. As such, those values are zero until the extents are calculated.

ItEndsWithTens commented 5 years ago

Got it, makes sense. I figured out what I was doing, I do believe, and have opened philstopford/Eto.Veldrid#2 with my proposed changes.

philstopford commented 5 years ago

Cheers - to confirm, are you able to use WASD keys to navigate the view in your implementation, and/or pan/zoom the view with the mouse (left-click, drag, mouse wheel)? For me, I was not seeing the key handler fire for key events.

ItEndsWithTens commented 5 years ago

Ah, damn it, sorry, I knew I forgot something; I can pan with LMB+drag and zoom with the mouse wheel, in the same directions as etoViewport did, but I neglected to check the key events you mentioned. I'll look into that next.

ItEndsWithTens commented 5 years ago

This seems to be that the VeldridSurface control isn't getting focus, and since you attach/detach your event handlers on GotFocus/LostFocus they never get connected; if I add a call to Surface.Focus() at some point, for example after the form has been shown, the WASD navigation works. I don't know how to get this to work by focusing the surface on click, though; I've implemented VeldridSurface as what's called a "themed control" in Eto, specifically one based on the Panel class, and I don't know if those are configurable to focus when a user clicks them. This is my first custom platform control in Eto, actually, so I suspect my design isn't the most robust.

In the longer term I do want to figure out how I can make VeldridSurface work like any other Eto control in terms of focusing. In the meantime, if you just call the surface's Focus method at a time that's convenient for you, it should let keyboard input work, at least for testing purposes.

An alternative might be to attach the event handlers elsewhere, maybe just call addKeyHandler in the VeldridDriver constructor and not worry about repeatedly attaching/detaching the handler? I don't know if your design is amenable to that sort of change, so take that with a grain of salt, just something to think about.

philstopford commented 5 years ago

Sounds like it might be worth my asking Curtis. The etoViewport UI was pretty much put together by him and works with the keyboard. I'll see if he might be able to take a look and suggest options :)

philstopford commented 5 years ago

Curtis replied : https://github.com/picoe/Eto/issues/1419#issuecomment-497013618

philstopford commented 5 years ago

Another stupid question, after quite some time bashing my head off the desk : how would I draw multiple polygons into the view? I've pushed some adjustments to my fork, but so far, I'm unable to get the two test polygon line boundaries to draw.

ItEndsWithTens commented 5 years ago

I haven't figured out a solution, but it looks like the indices being stored in 'lineIndices' are incorrect; as is I see lineIndices contains index 10 twice. If I brute force it to instead contain 0 and 10, however, I get a line drawn on screen. I think it's related to the loop inside the drawLines method that uses 'counter' and 'previouscounter', though I can't offhand say how to modify the loop to store the proper values in lineIndices.

philstopford commented 5 years ago

Closing this - I think it's obsolete now.