Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Game Programming > Maths Angle problem


Reply
 
Thread Tools Display Modes
  #1  
Old 11-15-2003, 05:46 AM
Mathijsken's Avatar
Mathijsken Mathijsken is offline
Contributor
 
Join Date: May 2003
Location: Oostkamp - Belgium
Posts: 730
Default Maths Angle problem


Okay i've written this code for a game, to get an angle out of two coordinates (or a vector if you like that more). The problem is that somehow, this function only returns 1 or 0. This simply can't be correct. When uncomment the last line, i do get the angle in my debug window.
Anyone has an idea why?

here's my code:

Code:
Const pi As Long = 3.14159265358979 Public Const Rad As Long = pi / 180 Public Const Deg As Long = 180 / pi Public Function GetAngle(Origin As Coordinate, Co2 As Coordinate, Optional InDegr As Boolean = False) As Long Dim Upper As Long, Lower As Long Upper = (Origin.Y - Co2.Y) Lower = (Origin.X - Co2.X) If Not Lower = 0 Then If InDegr = True Then GetAngle = Atn(Upper / Lower) * Deg Else GetAngle = Atn(Upper / Lower) End If Else If Upper > 0 Then If InDegr = True Then GetAngle = 90 Else GetAngle = pi / 2 End If Else If InDegr = True Then GetAngle = 270 Else GetAngle = (3 * pi) / 2 End If End If End If 'Debug.Print Atn(Upper / Lower) End Function

thanx a lot for any help

mathijsken

Last edited by Mathijsken; 11-15-2003 at 07:28 AM. Reason: Little mistake in the "if upper > 0"-part, still isn't working anyways
Reply With Quote
  #2  
Old 11-15-2003, 07:46 AM
Mathijsken's Avatar
Mathijsken Mathijsken is offline
Contributor
 
Join Date: May 2003
Location: Oostkamp - Belgium
Posts: 730
Default

Okay, found the bug, i was using a long data type to store the radians in, but since long types are big integers, they can't store decimal values. Simply replaced the long with a single and broplem solved.

(Why am i always finding the answers to my own questions?)

mathijsken
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple (?) Maths Problem brett_s Game Programming 3 11-07-2003 10:12 PM
(new angle) MsChart y axis exponential problem ipalalan General 0 10-14-2003 11:41 PM
Maths problem gizmoh General 2 09-05-2003 06:08 AM
Maths problem Paulhatzar General 7 12-07-2002 06:09 AM

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
 
 
-->