473,508 Members | 2,128 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Require C++ Sweep Test code converted to C#?

Hello all..

Is there any easy way to convert C++ to C#? I've got an inaccurate collision
in my Air Hockey game and i've realised it's because i need to perform a
sweep-test to get the precise point at which two sphere's collide.

Code below and original website here:
http://www.gamasutra.com/features/19991018/Gomez_2.htm (you have to register
to view it though!)
Thanks in advance.

Brian

#include "vector.h"
template< class T >

inline void SWAP( T& a, T& b )
//swap the values of a and b

{
const T temp = a;
a = b;
b = temp;

}

// Return true if r1 and r2 are real
inline bool QuadraticFormula
(
const SCALAR a,
const SCALAR b,
const SCALAR c,
SCALAR& r1, //first
SCALAR& r2 //and second roots
)

{

const SCALAR q = b*b - 4*a*c;
if( q >= 0 )

{

const SCALAR sq = sqrt(q);
const SCALAR d = 1 / (2*a);
r1 = ( -b + sq ) * d;
r2 = ( -b - sq ) * d;
return true;//real roots
}

else

{

return false;//complex roots
}
}
const bool SphereSphereSweep
(
const SCALAR ra, //radius of sphere A
const VECTOR& A0, //previous position of sphere A
const VECTOR& A1, //current position of sphere A
const SCALAR rb, //radius of sphere B
const VECTOR& B0, //previous position of sphere B
const VECTOR& B1, //current position of sphere B
SCALAR& u0, //normalized time of first collision
SCALAR& u1 //normalized time of second collision

)

{
const VECTOR va = A1 - A0;
//vector from A0 to A1

const VECTOR vb = B1 - B0;
//vector from B0 to B1

const VECTOR AB = B0 - A0;
//vector from A0 to B0

const VECTOR vab = vb - va;
//relative velocity (in normalized time)

const SCALAR rab = ra + rb;

const SCALAR a = vab.dot(vab);
//u*u coefficient

const SCALAR b = 2*vab.dot(AB);
//u coefficient

const SCALAR c = AB.dot(AB) - rab*rab;
//constant term
//check if they're currently overlapping
if( AB.dot(AB) <= rab*rab )

{

u0 = 0;
u1 = 0;
return true;
}

//check if they hit each other
// during the frame
if( QuadraticFormula( a, b, c, u0, u1 ) )
{

if( u0 > u1 )
SWAP( u0, u1 );
return true;
}

return false;
}
Nov 17 '05 #1
0 1420

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
2178
by: Hallvard B Furuseth | last post by:
Now that the '-*- coding: <charset> -*-' feature has arrived, I'd like to see an addition: # -*- str7bit:True -*- After the source file has been converted to Unicode, cause a parse error if a...
4
3047
by: Edvard Majakari | last post by:
Hi, I just found py.test and converted a large unit test module to py.test format (which is actually almost-no-format-at-all, but I won't get there now). Having 348 test cases in the module and...
2
2209
by: YGUEL | last post by:
Hello, do you know a good program to test what sort of charachters encoding is used in a file. I use iconv but it only can translate from a charachter encoding to an other. The problem is that I...
15
3286
by: lawrence | last post by:
Is this the correct way to test for a method before I use it? createRange() is, I believe, an IE only method. function wrapSelectionInTag(selection, tag) { if (document.selection.createRange)...
2
2435
by: bissatch | last post by:
Hi, I am currently writing a simple PHP program that uses an XML file to output rows for a 'Whats New' page. Once written, I will only require updating the XML file and any pages that use the...
67
4389
by: Ike Naar | last post by:
Hi, Asking your advice on the following subject: Suppose I want to find out whether a given pointer (say, p) of type *T points to an element of a given array (say, a) of type T. A way to...
5
6634
by: Stefan Krah | last post by:
Hello, I am currently writing code where it is convenient to convert char to int . The conversion function relies on a character set with contiguous alphabets. int set_mesg(Key *key, char...
24
2826
by: Dave | last post by:
I understand that VS.NET is supposed to compile native Win32 apps that do not require the .Net runtime. If that's the case then there is something else from the VS200x package that is required. ...
1
1560
by: =?Utf-8?B?QW5uaWU=?= | last post by:
I'm using Vista Home...just updated my Spysweeper to 5.8. While running a sweep, it got stuck and wouldn't continue its process. I then canceled the sweep...now it's hanging during the...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7123
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7326
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5627
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3194
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1557
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.