Beispiel #1
0
void Fighter::calculate(Vertex<float>  dest)
{
	// destination
        Vertex<float>  a = m_xAxis;
        Vertex<float>  b = dest - m_position;
        b.normalize();

        // cross product a x b
        Vertex<float>  axis = a.cross(b);
	
        //  a * b
        float numerator = a * b;

        // |a|
        float normA = sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]);

        // |b|
        float normB = sqrt(b[0] * b[0] + b[1] * b[1] + b[2] * b[2]);

        // |a| * |b|
        float denominator = normA * normB;

        //acos in Degree
        float angle = (acos(numerator/denominator));

	// Against the 'NaN's!
	if ((angle == angle) && (axis[0] == axis[0]) && (axis[1] == axis[1]) && (axis[2] == axis[2]))
	{
		rotate(axis, angle + PI);
	}
}
Beispiel #2
0
RayTraceState* getState(ColorGroup* pixels, Scene* scene)
{
    float ratio = (float)X_PIXELS / (float)Y_PIXELS;

    float zoom = DEFAULT_ZOOM;

    RayTraceParameters* params = new RayTraceParameters(zoom * ratio, 
		zoom, PLANE_DISTANCE, PLANE_ANGLE, X_PIXELS, Y_PIXELS, 
		DEFAULT_MAX_REFLECTIONS);

	float p = CAMERA_DISTANCE;

    Vertex* camera = new Vertex( p, -p, -p);
    Vertex* zBasis = new Vertex(-1,  1,  1);
    Vertex* yBasis = new Vertex(-.5,-1, .5);
    Vertex* xBasis = new Vertex();

    zBasis->normalize();
    yBasis->normalize();
    zBasis->cross(*yBasis, *xBasis);

    float oneHalf __attribute__ ((aligned (16))) = 0.5;

    Vertex cornerV;
    Vertex* screenCorner = new Vertex();

    float screenWidth = zoom*ratio;
    float screenHeight = zoom;

    cornerV.x = oneHalf*(screenHeight*yBasis->x - screenWidth*xBasis->x);
    cornerV.y = oneHalf*(screenHeight*yBasis->y - screenWidth*xBasis->y);
    cornerV.z = oneHalf*(screenHeight*yBasis->z - screenWidth*xBasis->z);
	
	float dist __attribute__ ((aligned (16))) = sqrt(cornerV.x * cornerV.x + 
		cornerV.y * cornerV.y + cornerV.z * cornerV.z) / PLANE_ANGLE;

    screenCorner->x = camera->x + dist * zBasis->x + cornerV.x;
    screenCorner->y = camera->y + dist * zBasis->y + cornerV.y;
    screenCorner->z = camera->z + dist * zBasis->z + cornerV.z;

    RayTraceState* state = new RayTraceState(camera, yBasis, zBasis, 
		screenCorner, params, scene, pixels);

    return state;
}