Beispiel #1
0
// Computes COS(f), f is a fixed point number in radians.
//  0 <= f <= PI/2
scalar FPCos(scalar f)
{
        int sign = 1;
        if ((f > PI_OVER_2) && (f <= PI))
        {
                f = PI - f;
                sign = -1;
        }
        else if ((f > PI_OVER_2) && (f <= (PI + PI_OVER_2)))
        {
                f = f - PI;
                sign = -1;
        }
        else if (f > (PI + PI_OVER_2))
        {
                f = (PI<<1)-f;
        }

        int sqr = FPMul(f,f);
        int result = CK1;
        result = FPMul(result, sqr);
        result -= CK2;
        result = FPMul(result, sqr);
        result += (1<<16);
        return result * sign;
}
Beispiel #2
0
scalar Vector::dot(const Vector &b) const
{
    return (scalar)(
               FPMul(x,b.x)+
               FPMul(y,b.y)+
               FPMul(z,b.z));
}
Beispiel #3
0
Vector Vector::operator*(class Vector &b) const
{
    return Vector(
               FPMul(x,b.x),
               FPMul(y,b.y),
               FPMul(z,b.z));
}
Beispiel #4
0
scalar FPSin(scalar f)
{
        // If in range -pi/4 to pi/4: nothing needs to be done.
        // otherwise, we need to get f into that range and account for
        // sign change.

        int sign = 1;
        if ((f > PI_OVER_2) && (f <= PI)) 
        {
                f = PI - f;
        } else if ((f > PI) && (f <= (PI + PI_OVER_2)))
        {
                f = f - PI;
                sign = -1;
        } else if (f > (PI + PI_OVER_2))
        {
                f = (PI<<1)-f;
                sign = -1;
        }

        int sqr = FPMul(f,f);
        int result = SK1;
        result = FPMul(result, sqr);
        result -= SK2;
        result = FPMul(result, sqr);
        result += (1<<16);
        result = FPMul(result, f);
        return sign * result;
}
Beispiel #5
0
	__forceinline SampleType InterpolateSample()
	{
		SampleType rv;
		u32 fp=step.fp;
		rv=FPMul(s0,(s32)(1024-fp),10);
		rv+=FPMul(s1,(s32)(fp),10);

		return rv;
	}
Beispiel #6
0
// Computes Tan(f), f is a fixed point number in radians.
// 0 <= f <= PI/4
scalar FPTan(scalar f)
{
        int sqr = FPMul(f,f);
        int result = TK1;
        result = FPMul(result, sqr);
        result += TK2;
        result = FPMul(result, sqr);
        result += (1<<16);
        result = FPMul(result, f);
        return result;
}
Beispiel #7
0
// Compute ArcCos(f), 0 <= f <= 1
scalar FPArcCos(scalar f)
{
        int fRoot = FPSqrt((1<<16)-f);
        int result = AS1;
        result = FPMul(result, f);
        result += AS2;
        result = FPMul(result, f);
        result -= AS3;
        result = FPMul(result, f);
        result += AS4;
        result = FPMul(fRoot,result);
        return result;
}
Beispiel #8
0
// Compute ArcSin(f), 0 <= f <= 1
scalar FPArcSin(scalar f)
{
        int fRoot = FPSqrt((1<<16)-f);
        int result = AS1;
        result = FPMul(result, f);
        result += AS2;
        result = FPMul(result, f);
        result -= AS3;
        result = FPMul(result, f);
        result += AS4;
        result = PI_OVER_2 - (FPMul(fRoot,result));
        return result;
}
Beispiel #9
0
	__forceinline bool Step(SampleType& oLeft, SampleType& oRight, SampleType& oDsp)
	{
		if (!enabled)
		{
			oLeft=oRight=oDsp=0;
			return false;
		}
		else
		{
			SampleType sample=InterpolateSample();

			//Volume & Mixer processing
			//All attenuations are added together then applied and mixed :)
			
			//offset is up to 511
			//*Att is up to 511
			//logtable handles up to 1024, anything >=255 is mute

			u32 ofsatt=lfo.alfo+(AEG.GetValue()>>2);
			
			s32* logtable=ofsatt+tl_lut;

			oLeft=FPMul(sample,logtable[VolMix.DLAtt],15);
			oRight=FPMul(sample,logtable[VolMix.DRAtt],15);
			oDsp=FPMul(sample,logtable[VolMix.DSPAtt],15);

			clip_verify(((s16)oLeft)==oLeft);
			clip_verify(((s16)oRight)==oRight);
			clip_verify(((s16)oDsp)==oDsp);
			clip_verify(sample*oLeft>=0);
			clip_verify(sample*oRight>=0);
			clip_verify(sample*oDsp>=0);

			StepAEG(this);
			StepFEG(this);
			StepStream(this);
			lfo.Step(this);
			return true;
		}
	}
Beispiel #10
0
Vector Vector::cross(const class Vector &b) const
{
    return Vector(
               FPMul(y,b.z) - FPMul(b.y,z),
               FPMul(z,b.x) - FPMul(b.z,x),
               FPMul(x,b.y) - FPMul(b.x,y));
}
Beispiel #11
0
// Computes ArcTan(f), f is a fixed point number
// |f| <= 1
//
// For the inverse tangent calls, all approximations are valid for |t| <= 1.
// To compute ATAN(t) for t > 1, use ATAN(t) = PI/2 - ATAN(1/t).  For t < -1,
// use ATAN(t) = -PI/2 - ATAN(1/t).
scalar FPArcTan(scalar f)
{
        int sqr = FPMul(f,f);
        int result = 1365;
        result = FPMul(result, sqr);
        result -= 5579;
        result = FPMul(result, sqr);
        result += 11805;
        result = FPMul(result, sqr);
        result -= 21646;
        result = FPMul(result, sqr);
        result += 65527;
        result = FPMul(result,f);
        return result;
}
Beispiel #12
0
                object->addFaceVertex(3);
                object->endFace();
                                
                object->endMesh();
#endif          
                font = framework->loadImage(framework->findResource("font.png"), &screen->format);
		bitmapFont = new BitmapFont(font);
		car = new Car(world);
        }

        void setupView()
        {
#if 0	
                scalar angle = (t>>2) % (2*PI);
		int r = 2;
                scalar x = 0*FPMul(FPSin(angle), FPInt(8)) + FPInt(0);
                scalar z = FPMul(FPCos(angle), FPInt(8)) + FPInt(0);
                scalar y = 0*FPMul(FPCos(angle)+(FP_ONE>>1), FPInt(2)) + FPInt(3)>>3;
//                scalar y = FPInt(3)>>4;
                
//              printf("%d, %d, %d\n", t, framework->getTickCount()/10, framework->getTicksPerSecond());

                view->rasterizer->setTexture(texture);

                view->camera.target = Vector(FPInt(0),FPInt(0),FPInt(0));
//                view->camera.origin = Vector(x,FPInt(3)>>4,z);
                view->camera.origin = Vector(x,y,z);

                view->camera.target = Vector(x+FPInt(0),FPInt(0),z+FPInt(1));
                view->camera.origin = Vector(x,y,z);
		
Beispiel #13
0
Vector Vector::operator*=(const scalar s)
{
    x=FPMul(x,s); y=FPMul(y,s); z=FPMul(z,s);
    return *this;
}
Beispiel #14
0
scalar Vector::lengthSquared() const
{
    return (FPMul(x,x) + FPMul(y,y) + FPMul(z,z));
}
Beispiel #15
0
scalar Vector::length() const
{
    return (scalar)FPSqrt(FPMul(x,x) + FPMul(y,y) + FPMul(z,z));
}
Beispiel #16
0
Vector Vector::operator*(const scalar f) const
{
    return Vector(FPMul(x,f), FPMul(y,f), FPMul(z,f));
}