Making a shell/bullet Spawn at the tip of the cannon
Making a shell/bullet Spawn at the tip of the cannon
Making a shell/bullet Spawn at the tip of the cannon
Making a shell/bullet Spawn at the tip of the cannon
Making a shell/bullet Spawn at the tip of the cannon
Making a shell/bullet Spawn at the tip of the cannon Making a shell/bullet Spawn at the tip of the cannon Making a shell/bullet Spawn at the tip of the cannon Making a shell/bullet Spawn at the tip of the cannon Making a shell/bullet Spawn at the tip of the cannon Making a shell/bullet Spawn at the tip of the cannon Making a shell/bullet Spawn at the tip of the cannon Making a shell/bullet Spawn at the tip of the cannon
Making a shell/bullet Spawn at the tip of the cannon Making a shell/bullet Spawn at the tip of the cannon
Making a shell/bullet Spawn at the tip of the cannon
Go Back  Xtreme Visual Basic Talk > > > Making a shell/bullet Spawn at the tip of the cannon


Reply
 
Thread Tools Display Modes
  #1  
Old 11-11-2011, 01:10 AM
masterpreenx masterpreenx is offline
Newcomer
 
Join Date: Sep 2010
Location: Davao City Philippines
Posts: 24
Default Making a shell/bullet Spawn at the tip of the cannon


I am having a very hard difficulty finding out how to do this.
Here is a scenario

When a tank cannon shoots, what I want is make the shell come out on the tip of its cannon. The same thing when the cannon is facing on a different angle.

I only know the rotation thing but not these trigonometric function I am looking for.

Glad if somebody would help =D.
Reply With Quote
  #2  
Old 11-11-2011, 11:20 AM
passel's Avatar
passelMaking a shell/bullet Spawn at the tip of the cannon passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,026
Default

It would be the Sin and Cos of the Angle * the magnitude of the radius for each Axis.
Make sure the Angle is passed to the functions in Radians
It would be along the lines of:

Degree2Radians = Math.Pi / 180.0
Radius = 20
Angle = 50 * Degree2Radians '50 degrees
RX = Math.Sin(Angle) * Radius
RY = Math.Cos(Angle) * Radius

You may need to experiment with the above to match your idea of where 0 degrees is (is it pointing straight up, like a map or compass, or straight to the right, like in mathematic text and graphs), and the direction of rotation (the compass angle rotate clockwise, while math graphs, typically rotate counter clockwise).

The Sin and Cos functions return the same "Sine" wave over a range of values, but the Cosine "wave" leads the Sine wave by 90 degrees (90 degree phase shift).
If you plot Sine and Cosine values, one on the X and the other on the Y, over a range of 360 degrees you get a circle. Since the function returns values between -1 and 1 you can simply multiply by a radius value to make the circle as big as you want.

The Cos of 0 degrees is 1.
The Sin of 0 degrees is 0.

The Cos of 90 degrees is 0
The Sin of 90 degrees is 1

The Cos of 180 degrees is -1
The Sin of 180 degrees is 0

The Cos of 270 degrees is 0
The Sin of 270 degrees is -1

So, if you us the Default windows orientation , where the Y axis increases as you move down the screen, then, the example code above would have 0 degrees pointing down and as the angle changed the rotation of the line would be counter clockwise.
So, if you want 0 degrees to be up and rotate clockwise, simply negate the Y value.
RX = Math.Sin(Angle) * Radius
RY = (-Math.Cos(Angle)) * Radius

If you want 0 degrees to be off to the Right, then switch Sin and Cos.
RX = Math.Cos(Angle) * Radius
RY = Math.Sin(Angle) * Radius
This will rotate clockwise, so it you want counterclockwise, negate the Y again.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #3  
Old 11-16-2011, 05:05 AM
masterpreenx masterpreenx is offline
Newcomer
 
Join Date: Sep 2010
Location: Davao City Philippines
Posts: 24
Default

thanks for the help =) .

what I made is add the results of RX and RY to the origin of the cannon and it did show on the position I wanted but what I observed it works only ( or im just mistaken ) on cannon that are barrels is placed on the middle just like the modern tanks today. I having a problem on a SpaceCrafts cannon which is placed on the side because sometimes it works sometimes its not, some angles work ( I mean the shell comes out on the barrels tip ) and some angles dont ( It spawn on a wrong angle were the cannon is not facing at) or just some of my calculation is wrong

i did what exactly you solve.
and this is how apply the calculations

theta = (math.pi * angle) / 180
RX = math.cos(theta) * radius
RY = math.sin(theta) * radius
shell(i).location = new point(tank(i).cannon.origin.x + RX,tank(i).cannon.origin.y + RY)

"My game trying to create is a shooter game that objects can fully turn 360 degrees and also applies some trigonometric and physics calculations"
Reply With Quote
  #4  
Old 11-16-2011, 03:07 PM
passel's Avatar
passelMaking a shell/bullet Spawn at the tip of the cannon passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,026
Default

RX and RY are "Relative" to some center of rotation.
So, if .cannon.origin refers to the center of rotation for the cannon, then it should work regardless of where the cannon is located. If .cannon.origin refers to something else, i.e. the upper left corner of where a bitmap of the cannon image should be drawn, then it will be off, and you will have to add some offset to the origin to get to the center of rotation.
You could for testing simply loop over the range of 360 degrees and plot the circle that should represent the end of your cannon travel and see if it agrees with what you see when you rotate the cannon through its range.

I can't say much else, since I don't know how you are doing your rotations, and what your coordinate system is for a given situation. Since GDI+ supports drawing transformations through the use of the graphics matrix there are so many possible ways you could be handling your rotations, I wouldn't hazard a guess.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Making a shell/bullet Spawn at the tip of the cannon
Making a shell/bullet Spawn at the tip of the cannon
Making a shell/bullet Spawn at the tip of the cannon Making a shell/bullet Spawn at the tip of the cannon
Making a shell/bullet Spawn at the tip of the cannon
Making a shell/bullet Spawn at the tip of the cannon
Making a shell/bullet Spawn at the tip of the cannon Making a shell/bullet Spawn at the tip of the cannon Making a shell/bullet Spawn at the tip of the cannon Making a shell/bullet Spawn at the tip of the cannon Making a shell/bullet Spawn at the tip of the cannon Making a shell/bullet Spawn at the tip of the cannon Making a shell/bullet Spawn at the tip of the cannon
Making a shell/bullet Spawn at the tip of the cannon
Making a shell/bullet Spawn at the tip of the cannon
 
Making a shell/bullet Spawn at the tip of the cannon
Making a shell/bullet Spawn at the tip of the cannon
 
-->