Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
3 registered members (AndrewAMD, The_Judge, Grant), 898 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Panel to face the mouse cursor #257415
03/23/09 10:19
03/23/09 10:19
Joined: Mar 2009
Posts: 5
W
Wafff Offline OP
Newbie
Wafff  Offline OP
Newbie
W

Joined: Mar 2009
Posts: 5
I'm attempting to create a simple 2D game, with a panel in the center of the screen to act as a "gun". Is there anyway of having the panel rotate to follow the mouse as it's moved around the screen?

I've tried searching but all that yields is "vec_to_angle", which is where my code currently stands and does not appear to work. Code currently looks like this: (in a function)

VECTOR temp;

while(1)
{
vec_set(temp,mouse_pos);
vec_sub(temp,gun_pan);
vec_to_angle(gun_pan.angle,temp);

wait(1);
}

Thanks for any help you can offer.

Re: Panel to face the mouse cursor [Re: Wafff] #257417
03/23/09 10:22
03/23/09 10:22
Joined: Jul 2008
Posts: 894
T
TechMuc Offline
User
TechMuc  Offline
User
T

Joined: Jul 2008
Posts: 894
it's not possible to rotate panels. use view entities instead

Last edited by TechMuc; 03/23/09 10:22.
Re: Panel to face the mouse cursor [Re: TechMuc] #257430
03/23/09 10:46
03/23/09 10:46
Joined: Apr 2006
Posts: 624
DEEP 13
badapple Offline
User
badapple  Offline
User

Joined: Apr 2006
Posts: 624
DEEP 13
from the online manual.....


PANEL* pan;

// rotate a panel about its center
function pan_rotate(p)
{
pan = p; // set the panel pointer from the function parameter
pan.center_x = pan.size_x * 0.5; // set the rotation center at the panel center
pan.center_y = pan.size_y * 0.5;
while (pan.angle < 360) // one full rotation
{
pan.angle += 10*time_step;
wait(1);
pan = p; // local variables are preserved during wait(), global pointers aren't
}
pan.angle = 0;
}



this is not meant to solve his problem just to show panel rotation is possible now

Re: Panel to face the mouse cursor [Re: badapple] #257437
03/23/09 11:15
03/23/09 11:15
Joined: Mar 2009
Posts: 5
W
Wafff Offline OP
Newbie
Wafff  Offline OP
Newbie
W

Joined: Mar 2009
Posts: 5
Yeah I'm able to rotate the panels using pan.angle, just having difficulty having it point to the mouse cursor.

Re: Panel to face the mouse cursor [Re: Wafff] #257461
03/23/09 12:59
03/23/09 12:59
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
close but no cigar, try this instead.
Code:
VECTOR temp;
gun_pan.center_x = gun_pan.size_x * 0.5;
gun_pan.center_y = gun_pan.size_y * 0.5;
while(1)		
{
   vec_set(temp, gun_pan.pos_x);	
   vec_add(temp, gun_pan.center_x);
   vec_sub(temp, mouse_cursor.x);
   vec_to_angle(temp,temp);
   gun_pan.angle = 90-temp.x;
   wait(1);
}



"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Panel to face the mouse cursor [Re: EvilSOB] #257462
03/23/09 13:02
03/23/09 13:02
Joined: Mar 2009
Posts: 5
W
Wafff Offline OP
Newbie
Wafff  Offline OP
Newbie
W

Joined: Mar 2009
Posts: 5
That worked perfectly, thanks alot!

Re: Panel to face the mouse cursor [Re: Wafff] #257464
03/23/09 13:05
03/23/09 13:05
Joined: Jul 2008
Posts: 894
T
TechMuc Offline
User
TechMuc  Offline
User
T

Joined: Jul 2008
Posts: 894
oO Sorry man, didn't new anything of panel.angle... i could have sworn, that i havn't missed any new feature the last 2 years..

Last edited by TechMuc; 03/23/09 13:06.
Re: Panel to face the mouse cursor [Re: Wafff] #257465
03/23/09 13:05
03/23/09 13:05
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
anytime.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Panel to face the mouse cursor [Re: EvilSOB] #257612
03/24/09 10:09
03/24/09 10:09
Joined: Mar 2009
Posts: 5
W
Wafff Offline OP
Newbie
Wafff  Offline OP
Newbie
W

Joined: Mar 2009
Posts: 5
Just got one final problem with this - I've been trying for hours now to make a "missle" created on this point move in the direction the gun was facing (i.e. if the gun is facing right, the missile goes right, if it's facing north-east, missile goes north-east, etc.) - So far the most I've been able to do is get the missile to be created facing the right direction, but moving is another story.

Is this possible using panels? Or would I have to go 2.5d and use an entity and c-move? Thanks again for the help.

Re: Panel to face the mouse cursor [Re: Wafff] #257620
03/24/09 11:51
03/24/09 11:51
Joined: Mar 2009
Posts: 112
Germany
K
KDuke Offline
Member
KDuke  Offline
Member
K

Joined: Mar 2009
Posts: 112
Germany
You can move the panel in the right direction by simply doing the following:
Code:
VECTOR temp;
VECTOR paneldirection;
gun_pan.center_x = gun_pan.size_x * 0.5;
gun_pan.center_y = gun_pan.size_y * 0.5;
while(1)		
{
   vec_set(temp, gun_pan.pos_x);	
   vec_add(temp, gun_pan.center_x);
   vec_sub(temp, mouse_cursor.x);
   //Here is the code I added into EvilSOB's
   vec_normalize(temp, 1);
   vec_set(paneldirection, temp);
   //
   vec_to_angle(temp,temp);
   gun_pan.angle = 90-temp.x;
   wait(1);
}

function moveMyPanel()
{
   while(isMoving)
   {
      panelToMove.pos_x += speedOfMovement*paneldirection.x*time_step;
      panelToMove.pos_y += speedOfMovement*paneldirection.y*time_step;
      wait(1);
   }
}


Last edited by KDuke; 03/24/09 11:55.

Using A7 Free
Click and join the 3dgs irc community!
Room: #3dgs
Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1