[ODE] New release version, ode-to-other library bridge

Ivan Bolcina ivan.bolcina at volja.net
Fri Jul 11 06:30:02 2003


This is a multi-part message in MIME format.

------=_NextPart_000_0021_01C34796.8651F350
Content-Type: multipart/alternative;
	boundary="----=_NextPart_001_0022_01C34796.8651F350"


------=_NextPart_001_0022_01C34796.8651F350
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi, guys.

There have been a lot of changes since version .35. Can someone =
summarize what was done about collision and faststep? What is faststep? =
When will we se another version. Do we have mesh-to-mesh collision.

Also I suggest that we make maybe a subtree with library-to-library =
conversions (say ode to directx,opcode to directx).
I am posting my code here, I am using it for ode-to-directx and to =
opcode.

bye,ivan
------=_NextPart_001_0022_01C34796.8651F350
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1170" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi, guys.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>There have been a lot of changes since =
version .35.=20
Can someone summarize what was done about collision and faststep? What =
is=20
faststep? When will we se another version. Do we have mesh-to-mesh=20
collision.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Also I suggest that we make maybe a =
subtree with=20
library-to-library conversions (say ode to directx,opcode to=20
directx).</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I am posting my code here, I am using =
it for=20
ode-to-directx and to opcode.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV>bye,ivan</DIV></BODY></HTML>

------=_NextPart_001_0022_01C34796.8651F350--

------=_NextPart_000_0021_01C34796.8651F350
Content-Type: text/plain;
	name="SPMath.h"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="SPMath.h"

#ifndef _H_MATHSP
#define _H_MATHSP
#include <math.h>
#include <stdlib.h>
#include <D3D9.h>
#include <D3DX9.h>
#pragma warning( disable : 4005 ) //disable macro redefinition warning
#pragma warning( disable : 4312 ) //some opcode casting warning
#include <ode/ode.h>
#include <opcode.h>
using namespace Opcode;

namespace IB
{
	namespace Math
	{

		inline float rndx( float low, float high) { return low + ( high - low =
) * ( (float)rand() ) / RAND_MAX;}
		inline float rndx(){return rndx(-1.0f,1.0f);}
		inline DWORD FtoDW( float f ) { return *((DWORD*)&f); }
		void ToRadarCoord(D3DXMATRIX RadarInv,D3DXMATRIX target,float =
*xout,float *yout,float *pos,bool norm);
		void ToRadarCoordAngle(D3DXMATRIX RadarInv,D3DXVECTOR3 target,float =
*xout,float *yout);
		D3DXVECTOR3 AimTo(D3DXVECTOR3 position,D3DXVECTOR3 offset,D3DXVECTOR3 =
move,D3DXVECTOR3 targetpos,D3DXVECTOR3 targetmove,float bulletspeed);
		Matrix4x4 convertMatrix(const D3DXMATRIX in);
		D3DXVECTOR3 convertVector(const dReal *in);
		D3DXQUATERNION convertQuaternion(const dReal *in);
		void dBodyAngAccelFromTorqu(const dBodyID body, dReal* ang_accel, =
const dReal* torque);
		inline float Sign(float x)
		{
			if (x<0) return -1;
			if (x>0) return 1;
			return 0;
		}
		inline float Limit(float in,float min,float max)
		{
			if (in<min) in=3Dmin;
			if (in>max) in=3Dmax;
			return in;
		}
		inline D3DXVECTOR3 Multiply4v(D3DXVECTOR3 v1,D3DXVECTOR3 x,D3DXVECTOR3 =
y,D3DXVECTOR3 z)
		{
			return x*v1.x+y*v1.y+z*v1.z;
		}
		inline void convertVector(D3DXVECTOR3 in,dVector3 out)
		{
			out[0]=3Din.x;
			out[1]=3Din.y;
			out[2]=3Din.z;
			out[3]=3D0;
		}

	}
}
using namespace IB::Math;
#endif 
------=_NextPart_000_0021_01C34796.8651F350
Content-Type: text/plain;
	name="SPMath.cpp"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="SPMath.cpp"

#include "SPMath.h"
//#include "mmgr.h"


void IB::Math::ToRadarCoord(D3DXMATRIX RadarInv,D3DXMATRIX target,float =
*xout,float *yout,float *pos,bool norm)
{
	D3DXMATRIX mtr=3Dtarget*RadarInv;
	float x=3Dmtr(3,0);
	float y=3Dmtr(3,1);
	float z=3Dmtr(3,2);
	float x1,y1;
	float kot=3Datan2f(y,x);
	float dist=3Dx*x+y*y;
	dist=3Dsqrtf(dist);
	float k2=3Datan2f(dist,z);
	k2*=3D0.5f;
	dist=3D(float)sinf(k2);
	x1=3D(float)cosf(kot);
	y1=3D-(float)sinf(kot);
	if (norm) {x1*=3Ddist;y1*=3Ddist;}
	if (pos!=3DNULL) *pos=3Ddist;
	if (yout!=3DNULL) *yout=3Dy1;
	if (xout!=3DNULL) *xout=3Dx1;
}

void IB::Math::ToRadarCoordAngle(D3DXMATRIX RadarInv,D3DXVECTOR3 =
target,float *xout,float *yout)
{
	D3DXVECTOR3 out;
	D3DXVec3TransformCoord(&out,&target,&RadarInv);
	float x=3Dout.x;
	float y=3Dout.y;
	float z=3Dout.z;
	float x1,y1;
	//float kot=3Datan2f(y,x);
	//float dist=3Dx*x+y*y;
	//dist=3Dsqrtf(dist);
	//float k2=3Datan2f(dist,z);
	//dist=3Dk2;
	x1=3Datan2f(x,z);
	y1=3Datan2f(-y,z);
	//if (norm) {x1*=3Ddist;y1*=3Ddist;}
	//if (pos!=3DNULL) *pos=3Ddist;
	if (yout!=3DNULL) *yout=3Dy1;
	if (xout!=3DNULL) *xout=3Dx1;

}


D3DXVECTOR3 IB::Math::AimTo(D3DXVECTOR3 position,D3DXVECTOR3 =
offset,D3DXVECTOR3 move,D3DXVECTOR3 targetpos,D3DXVECTOR3 =
targetmove,float bulletspeed)
{
	D3DXVECTOR3 Destination=3Dposition+targetmove*100.0f; //backup case
	D3DXVECTOR3 P0=3Dposition+offset;
	D3DXVECTOR3 P=3Dtargetpos-P0;
	D3DXVECTOR3 V=3Dtargetmove-move;
	float VV=3DD3DXVec3Dot(&V,&V);
	float MM=3Dbulletspeed*bulletspeed;
	float PV=3DD3DXVec3Dot(&P,&V);
	float PP=3DD3DXVec3Dot(&P,&P);
	float a=3DVV-MM;
	float b=3D2.0f*PV;
	float c=3DPP;
	float D1=3Db*b-4.0f*a*c;
	if (D1<0) return Destination;
	float D=3Dsqrtf(D1);
	float t1=3D(-b+D)/(2.0f*a);
	float t2=3D(-b-D)/(2.0f*a);
	float t=3D(t1>t2 ? t1 : t2);
	if (t<0) return Destination;
	Destination=3Dtargetpos+targetmove*t-offset;
	return Destination;
}

Matrix4x4 IB::Math::convertMatrix(const D3DXMATRIX in)
{
	Matrix4x4 out
	(
		in[0],in[1],in[2],in[3],
		in[4],in[5],in[6],in[7],
		in[8],in[9],in[10],in[11],
		in[12],in[13],in[14],in[15]
	);
	return out;
}

D3DXVECTOR3 IB::Math::convertVector(const dReal *in)
{
	D3DXVECTOR3 out;
	out.x=3D(float) in[0];
	out.y=3D(float) in[1];
	out.z=3D(float) in[2];
	return out;

}

D3DXQUATERNION IB::Math::convertQuaternion(const dReal *in)
{
	D3DXQUATERNION out;
	out.x=3D(float)in[1];
	out.y=3D(float)in[2];
	out.z=3D(float)in[3];
	out.w=3D(float)in[0];
	return out;
}


void IB::Math::dBodyAngAccelFromTorqu(const dBodyID body, dReal* =
ang_accel, const dReal* torque)
{
      dMass m;
      dMatrix3 invI;
      dBodyGetMass(body,&m);
      dInvertPDMatrix (m.I, invI, 3);
      dMULTIPLY1_331(ang_accel,invI, torque);
}

------=_NextPart_000_0021_01C34796.8651F350--