Getting mouse position correctly with varible window size?

Discuss the ZGameEditor Visualizer plugin for FL-Studio.

Moderator: Moderators

Post Reply
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

Getting mouse position correctly with varible window size?

Post by jph_wacheski »

I need to have the mouse interact with stuff in the visualiser window for a grid editor,. I am using this to move my zge pointer and 'know' where it is;

Code: Select all

pointer.Translate.x=clamp(App.MousePosition.x*16,-8,7);
pointer.Translate.y=clamp(App.MousePosition.y*16,-8,7);
However with the window being resizeable and with varying aspect means the desktop pointer does not line up with the zge one. Is there some way to easily get the actual mouse position to line up?
We have these app.ViewportRatio , app.ViewportWidth, app.ViewportHeight,. however I have not found any solid relationship to do some transformation that sticks it. This makes building interface elements in the 3d window sorta tough,. .
iterationGAMES.com
StevenM
Posts: 149
Joined: Thu Jan 20, 2011 10:03 am

Post by StevenM »

Very Cool project by the way - I tried your preset, it seemed to work fine. Did you figure this out?

I was working on a LED board app - it's slow and buggy - I am not going to continue to finish it. Maybe you can have a look and tell me where I went wrong. There are Draw Line and circle algorithms in there - you might find this useful for bitpad. I was going create preset animations for it - linked to midi and the spectral band. I was also looking for a way to blend overlapping pixels - stumped.
Attachments
LEDBoard.jpg
LEDBoard.jpg (148.36 KiB) Viewed 19774 times
LED.zgeproj
(11.83 KiB) Downloaded 1064 times
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

Post by jph_wacheski »

No, I still have not worked out a way to deal with the resizeble-screen/ mouse-position issue,. I just created a nice pointer in the 3d view and the user can just ignore the os pointer,. sorta distracting but it is workable.

I always find it interesting to look at other peoples code,. I have not done anything with arrays of models like that,. didn't even know they could be use like that!

Anyway, you have to create 2048 (64*32) models with that setup,. and that is probably a lot more overhead that what I have in the BitPadZ script, where I just read the array in a loop in the draw event of just one model and change the color when drawing the points. So what I store is the colors directly in the array. To mix the colors you could then just add, subtract, etc. when drawing to the array.

try this in your update;

Code: Select all

for(int ii = 0; ii<32; ii++){    //clear board
 for(int i = 0; i<64; i++) {
  LED[i,ii].Material1.Color.R=0;
  LED[i,ii].Material1.Color.G=0;
  LED[i,ii].Material1.Color.B=0;
  LED[0,0].Material1.Color.A=.5;
 }
}

 if (anim<31) anim+=1; else anim=0;
    //redraw stuff
LedPoint(32+sin(anim*.2)*8,31-anim,1,0,1); //purp
LedLine(0,anim,63,15,1,0,0); //red
LedLine(anim*2,31,32,0,0,0,1);  //blu
LedCircle(16+anim,16+sin(anim*.2)*8,5,0,1,0);    //green

Reminds me of a LED pinball type display,. kinda fun ;)
iterationGAMES.com
StevenM
Posts: 149
Joined: Thu Jan 20, 2011 10:03 am

Post by StevenM »

That is awesome. thanks so much! You pretty much solved every problem I was having with that code example. I would have never thought that. I was really over thinking about how to animate things. I might give this project another shot.

Edit: By the way, try this:

Code: Select all

anim=anim+1;
LedPoint(32+sin(anim*.2)*8,31-anim,1,0,1); //purp
LedLine(0,anim,63,15,1,0,0); //red
LedLine(anim*2,31,32,0,0,0,1);  //blu
LedCircle(16+anim,16+sin(anim*.2)*8,5,0,1,0); 
I have the values wrapping in the functions so you'll see something interesting :)

I'm going to see if I can read pixel data from a pair of 32x32 bitmaps and plot them.
User avatar
Kjell
Posts: 1910
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

@jph

Always forget about this ( secret ) forum :) I'm pretty sure I posted several examples over the years, but can only find one at the moment ..

viewtopic.php?p=4065#4065

However, if you're only doing 2D, you can discard the tan() by using a FOV of 90 ( tan(90/2/360*PI*2) = 1 ) & planar offset altogether, at which point you only have to multiply the homogeneous coordinates with the camera distance ( and the X axis with the ratio ). Doesn't get any easier then that .. attached is a example.

K
Attachments
Cursor.zgeproj
(530 Bytes) Downloaded 1000 times
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

Post by jph_wacheski »

Ahh,. Now I get it, thanks a bunch!

I knew it was a simple transform using those values I just did not include FOV and that is crucial. It is working well now, cheers.
Attachments
32. BitPadZ.zip
the ZgeViz script,. .
(9.5 KiB) Downloaded 904 times
iterationGAMES.com
Post Reply