I SUCK!

The Partridge Family were neither partridges nor a family. Discuss.
User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

I SUCK!

Post by LuX » April 28th, 2012, 3:45 pm

...at maths.

Trying to make a "cone of vision" or more like a "triangle of recoil" to give a go at a zombie apocalypse shooting game. 2d viewed from top down.

But I cant figure out the maths to draw the cone. Vectors could make things a lot easier I guess, but I have no idea how to use them on the DrawLine command.

Basically I have a median, that is 200 long and can be controlled, one end is at the player and the other is where you aim. The two visible lines are at 20' deg angle from the median on each side, and by my calculations about 213 long.

So the known points are AimFromX, Y (character location), AimToX, Y (Other end of the median 200 pixels from AimFrom).

X1, Y1 and X2, Y2 are the other points on the visible triangle, and the ones I need to know.

Here are some images I made, if it wasn't clear enough...
Attachments
ImageTwo.png
(26.13 KiB) Downloaded 498 times
ImageOne.png
(18.5 KiB) Downloaded 498 times
ʕ •ᴥ•ʔ

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: I SUCK!

Post by chili » April 28th, 2012, 3:56 pm

Need some more info. First of all, are you trying to draw a triangle (all straight lines) or a sector of a circle (two straight lines plus arc)? Is it solid or vector?

Also, instead of AimFrom and AimTo, you should probably define your 'cone' using AimFrom (x,y) and AimDirection (angle in radians). Is there any good reason why you defined it using two sets of ordered pairs?
Chili

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: I SUCK!

Post by LuX » April 28th, 2012, 4:02 pm

Well... Essentially you would move the character (AimFrom) using w,a,s,d and the direction you aim (AimTo) using arrows. Those are the basic things.

Now, the important parts I want visible are the red lines. The green arc forming the sector was supposed to be an "optional" thing if it wouldn't make things a lot harder.

Essentially I need to know the X1, Y1, X2, Y2, so that they are on the normal of the median at roughly 37 pixels in this case. Basically this value would increase depending on the weapons or the time it's being shot.

And to be honest, I have nerver used radians...
ʕ •ᴥ•ʔ

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: I SUCK!

Post by chili » April 28th, 2012, 4:06 pm

So the distance of 200 is variable then depending on the target cursor selected by the arrow keys. Is this correct?
Chili

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: I SUCK!

Post by LuX » April 28th, 2012, 4:54 pm

Not sure what you mean by that... The AimFrom and AimTo points are at 200 distance, per se, but the important variable is the distance between AimTo and X1,Y1 or X2,Y2, basically the angle between them as displayed above.

The cone, or triangle starts off at a small angle, but increases once you shoot.

But the 200 length was just an example, which depends on the weapon type as well as the angle.

Basically in-game the shot will fly at a random direction between the cones lines, which will become larger each shot. The aiming happens at a 360 deg around the player, so I guess it would be easier to calculate it based on angle in radians or degrees, as you mentioned.

Here's a new image because I have mad paint skills.

http://maps.forum.nu/temp/gm_bearing.html This here should explain *about* what I'm looking after. Thought the angle should be smaller...

Edited image, that was really huge...
Attachments
Uusi.png
Uusi.png (14.38 KiB) Viewed 5099 times
ʕ •ᴥ•ʔ

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: I SUCK!

Post by LuX » April 28th, 2012, 10:57 pm

Alright... After some thinking I -think- I finally have something:
Where AimFromX, Y is player location, X1, Y1, X2, Y2 are the ending points of the cone on a circle and AimDeg is the degree it aims from the x axis and AimRad is the length:

Code: Select all

X1 = AimFromX + AimRad * cos(AimDeg);
Y1 = AimFromY + AimRad * sin(AimDeg);
On my calculator it works, but in c++ I get an error, so I guess there is some better way to write this to c++?

Obviously I have to make a separate AimDeg for X2 and Y2, but that's not important now...

Edit: The Y1 value seems to be way high, I can barely remember something about sin() having two values and that most programs return the higher number?
hemm... hemm...

Edit2: Or radians? Hate those guys.
ʕ •ᴥ•ʔ

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: I SUCK!

Post by chili » April 29th, 2012, 3:47 am

angles.gif
(41.74 KiB) Downloaded 475 times
Chili

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: I SUCK!

Post by LuX » April 29th, 2012, 10:44 am

Haha. I have acutally no idea what you are trying to say... I know I can be a little confusing, I wasn't even sure how I wanted it to be... Anyways. I noticed the error was in my code; I had

Code: Select all

gfx.DrawLine(AimFromX, AimFromY, X1, Y2, 0, 100, 255);
Which messed all up as I hadn't defined Y2, It was always a random point some were in infinity.

Ended up doing it like this, and it works, like I originally had planned.

Code: Select all

	X1 = (AimFromX + AimRad * cos(AimDeg));
	Y1 = (AimFromY + AimRad * sin(AimDeg));

	X2 = (AimFromX + AimRad * cos(AimDeg2));
	Y2 = (AimFromY + AimRad * sin(AimDeg2));

	gfx.DrawLine(AimFromX, AimFromY, X2, Y2, 0, 100, 255);
	gfx.DrawLine(AimFromX, AimFromY, X1, Y1, 0, 100, 255);
	gfx.DrawCircle(AimFromX, AimFromY, AimRad, 255, 255, 255);
Here's the just the debug, no need for whole solution...

Controls: W,A,S,D move, Arrows left and right to look around.
Last edited by LuX on April 29th, 2012, 6:24 pm, edited 1 time in total.
ʕ •ᴥ•ʔ

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: I SUCK!

Post by chili » April 29th, 2012, 11:17 am

You said you were making a zombie game. This looks a lot like PacMan to me. :lol:

Anyways, glad you got it all sorted out bro! ;)
Chili

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: I SUCK!

Post by LuX » April 29th, 2012, 11:19 am

Here's Test 2: Press space and the vision will increase slightly; release and it will rapidly decrease :)

Edit: Chili... its only a test...
ʕ •ᴥ•ʔ

Post Reply