360 degrees shooting, how to.

Started by
5 comments, last by TheAdmiral 16 years, 4 months ago
Hello this is my first post here. Greetings to the whole community! I'm trying to shoot a laser ray from a certain x,y location to any direction. The mouse should tell the direction the ray should follow (its the aim), the ray should have a certain size and speed (only one ray can travel at the time). I'm using C# and GDI+ to complish this, I really never used Vectors in motion, this will be the first time so I'm totally lost on how to do all this. I can't even get started because can't find nothing on the web to fit my needs or skills... Thanks in advance for any possible help. Fernando Pereira
"Sometimes you may think you're alone but that's not true, where ever you go, Death is always near and always watching you." By me January 2007
Advertisement
Well I see around 60 views but no answers. If my post was confused or non-understandable, please, do let me know about it. I will glad reformulate it.

Thanks

[Edited by - EFileTahi-A on November 29, 2007 10:02:45 AM]
"Sometimes you may think you're alone but that's not true, where ever you go, Death is always near and always watching you." By me January 2007
Short answer (pseudocode):
// To create the laser:Laser laser;laser.position.set(x,y); // (x,y) is where the laser startslaser.direction = normalize(mouse.position - laser.position);// To move the laser (speed is the speed of the laser in units per second,// and deltaTime is the number of seconds since the last update):laser.position += laser.direction * speed * deltaTime;// To render the laser (how to do this is up to you - here I'm rendering// backwards from the end of the laser, in which case you'd probably want// to start the laser a little bit 'forward' from the initial (x,y)// position):render_line_segment(    laser.position, laser.position - laser.direction * laser.length);
This presupposes a familiarity with vectors and vector math, so if the above doesn't make a lot of sense right off, you may need to read up on this topic a bit first.
Thanks for the post jyk! :)

Are you familiarized with c#?

In order to get the traveling direction I will need to acquire the mouse's x,y location and the x,y of the shot's departure location right?. So is the following correct?:

int iMouseX = Mouse.X;
int iMouseY = Mouse.Y;

int iSourceX = 400;
int iSourceY = 300;

int iDirectionX = iMouseX - iSourceX;
int iDirectionY = iMouseY - iSourceY;


Anyways, I will try to recreate my function once I get home based on what you described.

PS: You know where can I read more about this topic?

Thanks again!
"Sometimes you may think you're alone but that's not true, where ever you go, Death is always near and always watching you." By me January 2007
You could try <a href="http://chortle.ccsu.edu/VectorLessons/vectorIndex.html>this link or just search for "vector math" in google, you'll find plenty of tutorials for it.
Well, I think I will need a tutorial to do this... Or a full working example (that would be awesome).

Does anyone know about any website capable of describing what I intend to do?

Thank you.
"Sometimes you may think you're alone but that's not true, where ever you go, Death is always near and always watching you." By me January 2007
SiS-Shadowman did, but the cat got his tongue [rolleyes].
Quote:Original post by SiS-Shadowman
You could try this link or just search for "vector math" in google, you'll find plenty of tutorials for it.
Ring3 Circus - Diary of a programmer, journal of a hacker.

This topic is closed to new replies.

Advertisement