81 lines
1.9 KiB
C
81 lines
1.9 KiB
C
// Copyright (C) 2011 Valeriano Alfonso Rodriguez (Kableado)
|
|
|
|
#ifndef _UTIL_H_
|
|
#define _UTIL_H_
|
|
|
|
|
|
/////////////////////////////
|
|
// SolveQuadratic
|
|
//
|
|
// Solves a Quadratic equation using a, b and c coeficients.
|
|
int SolveQuadratic(float a,float b,float c,float *Rmin,float *Rmax);
|
|
|
|
|
|
////////////////////////////////////////////////
|
|
// vec2 //
|
|
//////////
|
|
// A 2D vector.
|
|
typedef float vec2[2];
|
|
#define vec2_set(v,x,y) (v)[0]=(x);(v)[1]=(y);
|
|
#define vec2_copy(v1,v2) (v1)[0]=(v2)[0];(v1)[1]=(v2)[1];
|
|
#define vec2_plus(v,v1,v2) (v)[0]=(v1)[0]+(v2)[0];(v)[1]=(v1)[1]+(v2)[1];
|
|
#define vec2_minus(v,v1,v2) (v)[0]=(v1)[0]-(v2)[0];(v)[1]=(v1)[1]-(v2)[1];
|
|
#define vec2_scale(v,v1,s) (v)[0]=(v1)[0]*(s);(v)[1]=(v1)[1]*(s);
|
|
#define vec2_dot(v1,v2) ((v1)[0]*(v2)[0]+(v1)[1]*(v2)[1])
|
|
#define vec2_len(v) sqrtf((v)[0]*(v)[0]+(v)[1]*(v)[1])
|
|
#define vec2_perp(v,n) (v)[0]=-(n)[1];(v)[1]=(n)[0];
|
|
#define vec2_scaleadd(v,v1,v2,s) (v)[0]=(v2)[0]*(s)+(v1)[0];(v)[1]=(v2)[1]*(s)+(v1)[1];
|
|
float vec2_norm(vec2 v);
|
|
#define vec2_interpol(v,v1,v2,f) \
|
|
(v)[0]=(v1)[0]-f*((v1)[0]-(v2)[0]);\
|
|
(v)[1]=(v1)[1]-f*((v1)[1]-(v2)[1]);
|
|
|
|
|
|
/////////////////////////////
|
|
// Intersec_RayUnitCircle
|
|
//
|
|
// Intersection between a ray and a Unit Circle.
|
|
int Intersec_RayUnitCircle(vec2 orig,vec2 vel,vec2 center,float *t);
|
|
|
|
|
|
/////////////////////////////
|
|
// Intersect_CircleCircle
|
|
//
|
|
// Colision point of a circle against another circle.
|
|
int Colision_CircleCircle(
|
|
vec2 cir1,float ra,vec2 vel,
|
|
vec2 cb,float rb,
|
|
float *t,vec2 n);
|
|
|
|
|
|
/////////////////////////////
|
|
// Intersect_RayEdge
|
|
//
|
|
// Intersection between a ray and a edge.
|
|
int Intersect_RayEdge(
|
|
vec2 pos,vec2 vel,
|
|
vec2 norm,vec2 edgePos,float len,
|
|
float *t);
|
|
|
|
|
|
/////////////////////////////
|
|
// absmod
|
|
//
|
|
int absmod(int v,int d);
|
|
float fabsmod(float v,int d);
|
|
|
|
|
|
/////////////////////////////
|
|
// IsBigEndian
|
|
//
|
|
int IsBigEndian();
|
|
|
|
|
|
/////////////////////////////
|
|
// EndsWith
|
|
//
|
|
int EndsWith(char *str, char *suffix);
|
|
|
|
|
|
#endif
|