Jump to content


v71

Member Since 04 Dec 2007
Offline Last Active Yesterday, 10:52 PM
-----

Posts I've Made

In Topic: Rendering coinciding line segments

16 May 2013 - 09:53 PM

I'd scan your wireframe database for coincident lines and then, removing one of the offending line.
Note that this kind of problems are infested with numerical precision, normally you'd use an epsilon to discriminate between near collisions.
I have a function in c++ detecting if two lines are intersecting, separated, or coincident, if you need it let me know.

In Topic: start a game making group?

16 May 2013 - 09:39 PM

I do support skeletal , tomorrow will post a screenshot of a robotic arm made of different primitives , linked togheter the skeletal hierarchy , the code for matrix tranformations is computed with a stack based breadth first travering algorithm ( non recursive )

In Topic: start a game making group?

15 May 2013 - 08:26 PM

i am finishing mine, right now ,i am about to finish the logic part, totally separated from the rendering, i am focusing on a description language, capable of configuring game entities , kind of a simple scripting language , but executed to configure the game world at startup.

In Topic: Super Kart Racing for iOS and Android

30 April 2013 - 07:59 PM

Congratulations , keep up the good job

In Topic: Vector2 class design

22 April 2013 - 10:38 AM

Here is something by which , hopefully , you will get inspiration from



#include <assert.h>
#include <math.h>

template <class T>
struct CVec2
{

  CVec2() { v[0]=0.0f; v[1]=0.0f; }

  CVec2(const T& x, const T& y)
  {
	v[0]=x; v[1]=y;
  }

  CVec2( T *xy )
  {
     // be carefull no range check
     v[0]=xy[0];   v[1]=xy[1];
  }

__forceinline CVec2<T>& operator=(const CVec2<T>& CVec)
{
   if ( &CVec==this )
  return *this;
v[0]=CVec.v[0];
v[1]=CVec.v[1];
return *this;
}

__forceinline T& operator[](int i)  
  {
	//assert((i>=0)&&(i<2)); // uncomment this for range check
	return v[i];
  }

  __forceinline CVec2<T>& operator*=(const T s)
  {
	v[0] *= s;
	v[1] *= s;
	return *this;
  }

  __forceinline CVec2<T>& operator*=( const CVec2<T> & s)
  {
	v[0] *= s[0];
	v[1] *= s[1];
	return *this;
  }

  __forceinline CVec2<T>& operator/=(const T s)
  {
	v[0] /= s;
	v[1] /= s;
	return *this;
  }

  __forceinline CVec2<T>& operator+=(const CVec2<T>& that)
  {
	v[0] += that.v[0];
	v[1] += that.v[1];
	return *this;
  }

__forceinline CVec2<T>& operator-=(const CVec2<T>& that)
  {
	v[0] -= that.v[0];
	v[1] -= that.v[1];
	return *this;
  }

__forceinline bool operator< ( const CVec2<T>& a ) const
  {
const size_t Size = 2*sizeof(T);
return memcmp(v,a.v,Size) < 0;
  }

__forceinline bool operator== ( const CVec2<T>& a ) const
{
	const size_t Size = 2*sizeof(T);
	return memcmp( v,a.v,Size) == 0;
}

__forceinline bool operator<= (const CVec2<T>& a) const
{
	const size_t Size = 2*sizeof(T);
	return memcmp( v,a.v,Size) <= 0;
}

__forceinline bool operator> (const CVec2<T>& a) const
{
	const size_t Size = 2*sizeof(T);
	return memcmp( v,a.v,Size) > 0;
}

__forceinline bool operator>= (const CVec2<T>& a) const
{
	const size_t Size = 2*sizeof(T);
	return memcmp( v,a.v,Size) >= 0;
}

__forceinline bool operator!= (const CVec2<T>& a ) const
{
	const size_t Size = 2*sizeof(T);
	return memcmp( v,a.v,Size) != 0;
}

__forceinline void set(const T a, const T B)
  {
	v[0] = a;
	v[1] = b;
  }

__forceinline T length() const
  {
return sqrtf( v[0]*v[0]+v[1]*v[1] );
  }

__forceinline T squaredlength() const
  {
return ( v[0]*v[0]+v[1]*v[1] );
  }

__forceinline void normalize()
  {
T d=sqrt(v[0]*v[0]+v[1]*v[1]);
v[0]/=d;
v[1]/=d;
  }

  __forceinline void zero ()
  {
v[0] = (T)(0.0f);
v[1] = (T)(0.0f);
  }

  __forceinline void fabsf()
  {
v[0]=fabs(v[0]);
v[1]=fabs(v[1]);
  }

  __forceinline CVec2<T> inverse()
  {
return CVec<T>( -v[0], -v[1] );
  }

T v[2];

operator T* () const {return (T*) v;}

};

// external functions

template <class T>
__forceinline bool operator==(const CVec2<T>& a, const CVec2<T>& B)
{
  if ( a.v[0]!=b.v[0] ) return 0 ;
if ( a.v[1]!=b.v[1] ) return 0 ;
return 1;
}

template <class T>
__forceinline bool operator!=(const CVec2<T>& a, const CVec2<T>& B)
{
  return !(a== B);
}

template <class T>
__forceinline CVec2<T> operator*(const CVec2<T>& v, const T s)
{
  return CVec2<T>(v.v[0]*s, v.v[1]*s);
}

template <class T>
__forceinline CVec2<T> operator*(const T s, const CVec2<T>& v)
{
  return CVec2<T>( s*v.v[0], s*v.v[1] );
}

template <class T>
__forceinline CVec2<T> operator*(const CVec2<T>& v, const CVec2<T>& s)
{
  return CVec2<T>(s.v[0]*v.v[0], s.v[1]*v.v[1]);
}

template <class T>
__forceinline CVec2<T> operator/(const CVec2<T>& v, const T s)
{
  return CVec2<T>(v.v[0]/s, v.v[1]/s);
}

template <class T>
__forceinline CVec2<T> operator/( const T  s ,const CVec2<T>& v)
{
return CVec2<T>(s/v.v[0],  s/v.v[1]);
}

template <class T>
__forceinline CVec2<T> operator/(const CVec2<T>& v, const CVec2<T>& s)
{
return CVec2<T>(v.v[0]/s.v[0],  v.v[1]/s.v[1]);
}

template <class T>
__forceinline CVec2<T> operator+(const CVec2<T>& a, const CVec2<T>& B)
{
  return CVec2<T>(a.v[0]+b.v[0], a.v[1]+b.v[1]);
}

template <class T>
__forceinline CVec2<T> operator-(const CVec2<T>& a, const CVec2<T>& B)
{
  return CVec2<T>(a.v[0]-b.v[0],a.v[1]-b.v[1]);
}

template <class T>
__forceinline CVec2<T> operator-(const CVec2<T>& v)
{
  return CVec2<T>(-v.v[0], -v.v[1]);
}

// dot product

template <class T>
__forceinline T dot(const CVec2<T>& a, const CVec2<T>& B)
{
  return ( a.v[0]*b.v[0] +  a.v[1]*b.v[1] );
}

template <class T>
__forceinline CVec2<T> orthogonal( const CVec2<T>& a  )
{
// note that also a.v[1],-a.v[0] is orthogonal
return CVec2<T>( -a.v[1] ,a.v[0] );
}

// cross product

template <class T>
__forceinline CVec2<T> cross( const CVec2<T>& a , const CVec2<T>& b )
{
return CVec2<T>( a.v[0]*b.v[1] ,- a.v[1]*b.v[0] );
}

// gets absolute value vector

template <class T >
__forceinline CVec2<T> fabs( const CVec2<T> &v )
{
return CVec2<T>( fabsf(v.v[0]),fabsf(v.v[1]) );
}

// linear interpolation

template <class T>
__forceinline CVec2<T> lerp( const CVec2<T>&a , const CVec2<T>&b ,T t)
{
return CVec2<T>( a+ t*b );
}

// Calculates the projection of 'p' onto 'q'.

template <class T>
__forceinline CVec2<T> project( const CVec2<T> &p, const CVec2<T> &q)
{
T magnitudesqr=( q.v[0]*q.v[0]+q.v[1]*q.v[1] );
T num= (p.v[0]*q.v[0] +  p.v[1]*q.v[1] ) / magnitudesqr ;
return num * q ;
}

// Calculates the components of 'p' perpendicular to 'q'.

template <class T>
__forceinline CVec2<T> perpendicular(const CVec2<T> &p, const CVec2<T> &q )
{
T magnitudesqr=( q.v[0]*q.v[0]+q.v[1]*q.v[1] );
T num= (p.v[0]*q.v[0] +  p.v[1]*q.v[1] ) / magnitudesqr ;
return p - num * q;
}

// orthogonalization

template < class T>
__forceinline CVec2<T> orthogonalize( const CVec2<T> &v1, CVec2<T> &v2)
{
// Performs Gram-Schmidt Orthogonalization on the 2 basis vectors to
// turn them into orthonormal basis vectors.
	v2 = v2 - project(v2, v1);
	v2.normalize();
return v2;
}

// vector reflection

template < class T>
__forceinline CVec2<T> reflect(const CVec2<T> &v1, const CVec2<T> &v2 )
{
	// Calculates reflection vector from entering ray direction 'i'
	// and surface normal 'n'.
	return v1 - 2.0f * project(v1, v2);
}

// not that this 'cross' product gives the perpendicular
// vector to vector'v' contained in the same plane
// the 'cross' term is loosely applied here

template < class T >
__forceinline CVec2<T> cross( const CVec2<T> &v )
{
return CVec2<T>( v.v[1],-v.v[0] );
}

// normalize a vector

template < class T >
__forceinline CVec2<T> normalize( const CVec2<T> &v )
{
T denum=sqrt( v[0]*v[0]+v[1]*v[1] );
return CVec2<T>( v[0]/denum,v[1]/denum );
}

///////////////////////////////////////////////////////////
// function to be used when sorting elements

template < class T >
struct CVec2IsGreater
{
   bool operator()(const CVec2<T> &a, const CVec2<T> & B)
   {
	  //compare a and b and return either true or false.
	  return (a[0]*a[0]+a[1]*a[1]) > (b[0]*b[0]+b[1]*b[1]);
   }
};

//////////////////////////////////////////////
// define some types
// if you plan to use the vertex aray as source of floating point
// computation for example, in a 2d or 3d application,  be carfeull
// to avoid numeric truncation

typedef CVec2<float>		  CVec2f;
typedef CVec2<double>		 CVec2d;
typedef CVec2<signed int>	 CVec2i; // using this numeric format may cause truncation
typedef CVec2<signed short>   CVec2s; // using this numeric format may cause truncation
typedef CVec2<signed char>	CVec2b; // using this numeric format may cause truncation
typedef CVec2<unsigned char>  CVec2ub; // using this numeric format may cause truncation
typedef CVec2<unsigned int>   CVec2ui; // using this numeric format may cause truncation