• FEATURED
• FEATURED
• FEATURED
• FEATURED
• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Get coordinates for a rectangles edges

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

4 replies to this topic

### #1P0jahn  Members

Posted 09 January 2013 - 10:43 AM

I need to implement a laser unit to my game that fire a rotating(360 degree) laser. The laser target coordinate is where I am getting stuck at. Every frame, it need to update its target coordinates so the laser is spinning. So if I have a rectangle that is 800x600, first I get coordinate 1:0, then 2:0, and later 800:0, then 800:1, 800:2, later 800:600, then 799:600. I hope that was clear. I thought it was an easy task, I opened eclipse but got stuck pretty fast Searched on google but could not find anything.

### #2Ravnock  Members

Posted 09 January 2013 - 11:09 AM

I need to implement a laser unit to my game that fire a rotating(360 degree) laser. The laser target coordinate is where I am getting stuck at. Every frame, it need to update its target coordinates so the laser is spinning. So if I have a rectangle that is 800x600, first I get coordinate 1:0, then 2:0, and later 800:0, then 800:1, 800:2, later 800:600, then 799:600. I hope that was clear. I thought it was an easy task, I opened eclipse but got stuck pretty fast Searched on google but could not find anything.

The laser has to follow a path of targets, I would create a class "Follower" with a container with points to follow and a class CircuitFollower that updates the current point until the end and begins again, initialized with  this three points: (0,0) (800,0) (800,600)

The class perform an Action every frame and updates the current point every frame (usually to the next).

So if you have a class Enemy you should implement this class.

Class Follower

{

Queue pointsToFollow;

Action();

Update();

}

Class CircuitFollower

{

...

}

Maybe it's too generic for you, I don't know... but it's useful for more stuff

### #3P0jahn  Members

Posted 09 January 2013 - 12:56 PM

Actually, that is a fantastic idea and is well compatible with my game. Thanks!

### #4Kwizatz  Members

Posted 09 January 2013 - 04:51 PM

You may want to consider using polar coordinates or just store the angle of the ray to calculate the line.

If you just sweep the screen borders, the animation will seem to slow down and speed up because of the difference in ratio between width and height.

### #5Ravnock  Members

Posted 11 January 2013 - 05:34 AM

Actually, that is a fantastic idea and is well compatible with my game. Thanks!

You are welcome, it's nice to be useful!

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.