Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Studio Chat / creating a custom gui library and question that may or may not be doable

Author
Message
Dark Raven
9
Years of Service
User Offline
Joined: 27th Jul 2014
Location: United States
Posted: 19th Sep 2022 04:19 Edited at: 19th Sep 2022 04:19
I'm currently experimenting with creating a gui library in tier 1. Its in early early early development (hobby work). What I have is coming along quite well. But in my experimentation I come across something that may or may not be doable but either way I'm having trouble with calculations. Math isn't at my greatest.





So what I'm trying to do is create a viewport in a window. What it basically is is a rendered image placed in a sprite updating each frame. I'm able to get it to work visually as you can see in the video. I'm able move around with keyboard and also move the window with it moving with it and collapsing window and all. But the part that I'm trying to see if it is possible is mouse usage in the window and this is where my problems rises.

So basically what I'm trying to do is convert the mouse position within this sprite to a coordinate within the display so that I can then get a position within the 3d world which is being rendered to an image and then I can raycast to the object can be selected. But I'm having a problem with taking the mouse position within the sprite so it can be translated into the actual hidden 3d view. The video is the closest I've gotten as you can see when I click on the wall it changes to red tone and then goes back to normal. But it is also turning red when I click else where in the sprite so the calculations are completely wrong.

If any one has any ideas on how to get the mouse point within the sprite to translate over to the 3d scene would be great as this would be a cool feature. But if not then I may have to scrap it and move on.

Thanks.
Mike
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 19th Sep 2022 14:39
Couldn't you just do local_X = MouseX() - Window_X
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda
Pixel-Perfect Collision

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 19th Sep 2022 17:29
I think you will get the 3d coordinates with Get3DVector?FromScreen.
In this case it is important when you do it.
If you want to have the position in the sprite rendering. You have to get the coordinates before you put the rendering back on your screen.
Then you can calculate mouse position as Phaelax suggests.
The calculation itself needs the screen size/ratio and the FOV. This is usually different when rendering to an image.
But if you want to get the position afterwards when the 'normal' render state is established. You have to calculate the position differently.
screen_Size/image_size * (mouse_position-screen_position) I think this could be correct. (but would not bet on it)

By the way.
I find it quite good what you have achieved so far with your GUI.
Does this also go in the direction of 'immediate mode'?
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)

Donations are always welcome.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 19th Sep 2022 18:57 Edited at: 19th Sep 2022 18:57
where locx and locy are the raw mouse locations
and canvasize your working window and windowsize the resolution
dx=locX*canvasSize/windowSize:dy=locY*canvasSize/windowSize

that works with scaled windows at any location on screen but not sure if that will help in this situation

Should work
PK
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 19th Sep 2022 23:48 Edited at: 19th Sep 2022 23:51
This is a function i use;
tPoint is
type tPoint
float x
float y
float z
endtype

If you want the position within the sprite then use
GetSpritePixelFromX(sprite, GetPointerX())
GetSpritePixelFromY(sprite, GetPointerY())

Login to post a reply

Server time is: 2024-04-14 15:45:31
Your offset time is: 2024-04-14 15:45:31