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 Classic Chat / How to start or do a laser beam project.. ;)

Author
Message
Sharp1959
8
Years of Service
User Offline
Joined: 26th Nov 2015
Location: U.S.A.
Posted: 8th Nov 2016 05:07 Edited at: 8th Nov 2016 05:12
Hello everyone!

I looked at some old posts, but only found some really old DBPro ideas..on this I was looking
for AppGameKit 2 ideas ...

I would like to have a laser beam that I can set or point to a object (mirror)
and bounce off...but being really new to AppGameKit 2 I don't know where to start
I've spent several hours reading the different commands and docs and
even look at several example projects...but this idea just ...keeps
escaping me... ;(

The picture below is from a Corona SDK demo (example)

A picture is worth a ..well you know..

Many Thanks for any input
*AGK (Non-Steam) V2.0.21 * iMac (21.5-inch, Mid 2011) - Intel 2.5 GHz i5 Quad Core - 16 GB Ram - OS X - 10.11.6) El Capitan *

Attachments

Login to view attachments
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 8th Nov 2016 06:53
its not agk but you can convert


single reflection in agk

AGK (Steam) V2.0.21 : Windows 10 Pro 64 Bit : AMD (16.6) Radeon R7 265 : Mac mini OS Sierra (10.12)

Attachments

Login to view attachments
Sharp1959
8
Years of Service
User Offline
Joined: 26th Nov 2015
Location: U.S.A.
Posted: 8th Nov 2016 07:50
Thanks @Markus...bbbbbut...not quite what I was looking for (Good stuff tho!)
I have seen that Monkey code before and it's good but it
don't convert to AppGameKit 2 very well ...the commands for that
type of usage is just not there...in AGK...wish it were that easy..

I did happen to locate a thread by Phaelax over here
that was pretty darn cool... !!

https://forum.thegamecreators.com/thread/216169

Thats really close to what I'm looking for...

I wonder if Phaelax will chime in... ?

Maybe shed some light on the laser stump...

Thanks
*AGK (Non-Steam) V2.0.21 * iMac (21.5-inch, Mid 2011) - Intel 2.5 GHz i5 Quad Core - 16 GB Ram - OS X - 10.11.6) El Capitan *
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 8th Nov 2016 09:16
ok, below this monkey code was a single reflection in agk, you saw?
AGK (Steam) V2.0.21 : Windows 10 Pro 64 Bit : AMD (16.6) Radeon R7 265 : Mac mini OS Sierra (10.12)
damothegreat
User Banned
Posted: 8th Nov 2016 16:43
Ill have a go at this one, cause I been thinking of doing a laser game too in the future

Come back to you soon with some code

Damo
Using Tier 1 AppGameKit V2
Started coding with AMOS
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 8th Nov 2016 19:36
Someone looking for me?

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
damothegreat
User Banned
Posted: 8th Nov 2016 20:48
Ill provide my thoughts on a little psedo coding of the idea

1. A laser potentially requires a start and an end - so at least have a type [array] using "x","y","endx","endy"
best to be an array type - so that we can add laser joints onto each other when we add a mirror


do

2. Draw the laser line from its x,y,endx,endy

3. Add a mirror rectangle on the mouse pointer via the getpointerx and getpointery commands

4. Check collisions with mouse pointer (mirror) and the laser line created at point 2

5.a if collides with the line (laser), then decrease / increase the laser to its strength length from the starting point to the mouse position
and add the end cords to the mouse position and create a new laser beam with the starting position of the previous lasers endx,endy points

5 b if not collided with the mirror (mouse) then reset its back length back to its original positions.

6. Get some geometry figures set out according to the angle of the rectangle mirror - use of SIN and COS will do this trick

7. If right mouse button is pressed, then rotates the mirror's angle and calculate using step 6

8 If the left mouse button is pressed, then add the mirror to the screen at the getpointerx, getpointery locations and calculiate the
lasers new end points according to the maths that we identify in step 6

loop

Laser using array TYPE x,y,endx,endy - array cause we could have multiple of them via step 5a


Damo





Using Tier 1 AppGameKit V2
Started coding with AMOS
Sharp1959
8
Years of Service
User Offline
Joined: 26th Nov 2015
Location: U.S.A.
Posted: 9th Nov 2016 08:55
Hi All,

Yes @Phaelax, I was wondering if you could shed a little light on
how you accomplished the effect here in this WIP you posted?

https://forum.thegamecreators.com/thread/216169

The effect is awesome, and was right down the the same alley I was
looking to do..

Any help or hints would be appreciated.

Respectfully
*AGK (Non-Steam) V2.0.21 * iMac (21.5-inch, Mid 2011) - Intel 2.5 GHz i5 Quad Core - 16 GB Ram - OS X - 10.11.6) El Capitan *
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 9th Nov 2016 19:16 Edited at: 9th Nov 2016 19:18
I'll try to find the code tonight when I get home. But here's an explanation.

1. The laser and mirror are just line segments.
2. Do an intersection test of the two lines.
3. Laser is represented by line segment AB, the mirror is CD.

n = [(D.x-C.x) * (A.y-C.y)] - [(D.y-C.y) * (A.x-C.x)]
d = [(D.y-C.y) * (B.x-A.x)] - [(D.x-C.x) * (B.y-A.y)]
t = n / d

t is the intersection time along AB when it intersection CD.

Because the equations work in regards to infinite lines rather than fixed segments, we must check the intersection time is between
0 and 1. If so, then the laser intersects the line representing the mirror. But to make sure it's within the boundaries of the
mirror, we must repeat the above equation but flip-flop the variables so the time index is in reference to CD instead. If that too
is within the 0 to 1 range then we know for sure the laser and mirror intersect.


4. Calculate the point of intersection, P.

P.x = A.x + (B.x - A.x)*t
P.y = A.y + (B.y - A.y)*t


5. Calculate the reflection vector for the laser.

I = normalize AB as a direction vector
N = normal of CD
R = reflection vector (direction of laser after hitting mirror)

R = 2N*(N · I) - I

To calculate the normal of the mirror, form CD into a direction vector then invert the components like so:

J = D-C
N.x = -J.y
N.y = J.x


6. Find some measurements.

Length of laser beam from A to B:
olength = sqrt((B.x-A.x)^2 + (B.y-A.y)^2)

Length of laser from source (A) to mirror (P):
mlength = oLength * t

Remainder of laser after reflection (P to ?)
rLength = oLength - mLength


7. Draw the laser
The first part of the laser goes from A (the source) to I*length (the point of impact on the mirror). If you're just drawing lines
you can simply just draw a line from A to P. But what about the reflection? That's why we calculated a length.
R is the normalized direction vector of the laser's relfection on the mirror. rLength is the length of that reflection. So your
reflection line goes from P to P + R*rLength.


8. What if I have multiple mirrors?

Multiple mirrors is simple to handle, but requires slightly more than just looping through each mirror. A mirror can cause the
laser to reflect back off another that it may have already hit. Therefore, you must loop through all mirrors repeatedly until a
certain condition is met. If you have an infinite length laser, then you want to stop checking for reflections after so many have
been hit. Otherwise, there's a risk for an infinite loop due to the reflections. Ever heard of an infinity mirror? Another
condition which should be considered for all scenarios is when the laser goes off screen. At that moment, stop checking, unless
your laser can reflect off the sides of your screen.
Loop through all your mirrors. You can't simply stop once an intersection is detected because the laser could go through multiple
mirrors. So check all of them and keep track of the intersection time (t) with the lowest value. That's the first mirror hit.
Perform the steps above. Draw the laser from A to P. The newly reflected laser is now P (A) to P+R*rLength (B). Every time a
reflection occurs, rLength will get smaller and smaller. If that length becomes less than 5px (or whatever limit you decide) then
stop your loop. If you are doing an infinite laser, then length can be whatever you want, just make sure it's long enough it can
reach any mirror.

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

Login to post a reply

Server time is: 2024-11-25 02:01:43
Your offset time is: 2024-11-25 02:01:43