I have linked to -lm, and included the following:
Code: Select all
#include <math.h>
#include <dc/fmath.h>
#include <dc/matrix.h>
#include <dc/matrix3d.h>
Code: Select all
void DCE_glVectorRotate( vector4f vector, vector4f origin, float angle, int plane1, int plane2 )
{
float r[2];
r[0] = (origin[plane1] + ((vector[plane1] - origin[plane1]) * cos(angle)) - ((vector[plane2] - origin[plane2]) * sin(angle)));
r[1] = (origin[plane2] + ((vector[plane1] - origin[plane1]) * sin(angle)) + ((vector[plane2] - origin[plane2]) * cos(angle)));
vector[plane1]=r[0];
vector[plane2]=r[1];
}
#define RANGLE 1.0f // Rotation Angle
#define RSD 360.0f/RANGLE // Rotated Side
#define RADIAN 0.0174532925 // Convert Degrees to Radians
// Radius is determined by the distance between p and c ( point and center )
// With RANGLE set to 15, this will draw an object with 24 sides ( faster )
// Decrease RANGLE down to 1.0f to draw an object with 360 sides ( slower )
void DCE_glRenderCylinder( vector4f p, vector4f c, vector4f rot, vector4f pos,
vector4f campos, vector4f camrot,
GLuint *txr, float u, float v, float height, float scale )
{
int i;
float ust=0, uend, utx = u/RSD;
matrix4f s;
for( i=0; i< RSD; i++ )
{
s[0][x]=p[x]; s[0][y]=p[y]; s[0][z]=p[z];
p[y]+=height; c[y]+=height;
s[1][x]=p[x]; s[1][y]=p[y]; s[1][z]=p[z];
DCE_glVectorRotate( p, c, RADIAN*RANGLE, x, z );
s[2][x]=p[x]; s[2][y]=p[y]; s[2][z]=p[z];
p[y]-=height; c[y]-=height;
s[3][x]=p[x]; s[3][y]=p[y]; s[3][z]=p[z];
uend = ust + utx;
DCE_glRender4fvuuvScale( &s, rot, pos, txr,
campos, camrot, ust, uend, v, scale );
ust += utx;
}
}
Anyway, this works fine ( texture disabled for clarity of error in rotation )
However, when I try to optimize this routine using the kos dc fast math operations, it is not correct.
The object is continually spinning, and we can see the final point does not reach the original point:
Code: Select all
void DCE_glVectorRotate( vector4f vector, vector4f origin, float angle, int plane1, int plane2 )
{
float r[2];
r[0] = (origin[plane1] + ((vector[plane1] - origin[plane1]) * fcos(angle)) - ((vector[plane2] - origin[plane2]) * fsin(angle)));
r[1] = (origin[plane2] + ((vector[plane1] - origin[plane1]) * fsin(angle)) + ((vector[plane2] - origin[plane2]) * fcos(angle)));
vector[plane1]=r[0];
vector[plane2]=r[1];
}