void Matrix3::fromHeadPitchRoll(float headDegrees, float pitchDegrees, float rollDegrees) { // Constructs a rotation matrix based on a Euler Transform. // We use the popular NASA standard airplane convention of // heading-pitch-roll (i.e., RzRxRy). headDegrees = Math::degreesToRadians(headDegrees); pitchDegrees = Math::degreesToRadians(pitchDegrees); rollDegrees = Math::degreesToRadians(rollDegrees); float cosH = vfpu_cosf(headDegrees); float cosP = vfpu_cosf(pitchDegrees); float cosR = vfpu_cosf(rollDegrees); float sinH = vfpu_sinf(headDegrees); float sinP = vfpu_sinf(pitchDegrees); float sinR = vfpu_sinf(rollDegrees); mtx[0][0] = cosR * cosH - sinR * sinP * sinH; mtx[0][1] = sinR * cosH + cosR * sinP * sinH; mtx[0][2] = -cosP * sinH; mtx[1][0] = -sinR * cosP; mtx[1][1] = cosR * cosP; mtx[1][2] = sinP; mtx[2][0] = cosR * sinH + sinR * sinP * cosH; mtx[2][1] = sinR * sinH - cosR * sinP * cosH; mtx[2][2] = cosP * cosH; }
void Matrix3::rotate(const Vector3 &axis, float degrees) { // Creates a rotation matrix about the specified axis. // The axis must be a unit vector. The angle must be in degrees. // // Let u = axis of rotation = (x, y, z) // // | x^2(1 - c) + c xy(1 - c) + zs xz(1 - c) - ys | // Ru(angle) = | yx(1 - c) - zs y^2(1 - c) + c yz(1 - c) + xs | // | zx(1 - c) - ys zy(1 - c) - xs z^2(1 - c) + c | // // where, // c = cos(angle) // s = sin(angle) degrees = Math::degreesToRadians(degrees); float x = axis.x; float y = axis.y; float z = axis.z; float c = vfpu_cosf(degrees); float s = vfpu_sinf(degrees); mtx[0][0] = (x * x) * (1.0f - c) + c; mtx[0][1] = (x * y) * (1.0f - c) + (z * s); mtx[0][2] = (x * z) * (1.0f - c) - (y * s); mtx[1][0] = (y * x) * (1.0f - c) - (z * s); mtx[1][1] = (y * y) * (1.0f - c) + c; mtx[1][2] = (y * z) * (1.0f - c) + (x * s); mtx[2][0] = (z * x) * (1.0f - c) + (y * s); mtx[2][1] = (z * y) * (1.0f - c) - (x * s); mtx[2][2] = (z * z) * (1.0f - c) + c; }
//************************************************************************************* // //************************************************************************************* void CColourPulser::Update( u32 elapsed_ms ) { mTimeCounter = (mTimeCounter + elapsed_ms) % mCyclePeriod; f32 cycle_fraction( f32(mTimeCounter) / f32(mCyclePeriod) ); f32 sin_val( vfpu_cosf( cycle_fraction * 2.0f * PI ) ); // In range -1..+1 f32 factor( ( sin_val + 1.0f ) / 2.0f ); // In range 0..1 mCurrentColour = mDimColour.Interpolate( mBrightColour, factor ); }
void SkyLight::UpdateLightSource(float sun_angle) { float r = 670.0f; float shift = 325; //float textureScale = 1.0f / stepScale; int i = 0; skyVertices[i].x = vfpu_sinf((sun_angle/180)*PI)*r;// * stepScale; skyVertices[i].y = vfpu_cosf(((sun_angle)/180)*PI)*-r;// * stepScale; skyVertices[i].z = -250;// * stepScale; skyVertices[i].u = 0.f;// * textureScale; skyVertices[i].v = 0.f;// * textureScale; i++; // (x, y - 1, z) skyVertices[i].x = vfpu_sinf(((sun_angle-45)/180)*PI)*r;// * stepScale; skyVertices[i].y = vfpu_cosf(((sun_angle-45)/180)*PI)*-r;// * stepScale; skyVertices[i].z = -250;// * stepScale; skyVertices[i].u = 0.f;// * textureScale; skyVertices[i].v = 1.f;// * textureScale; i++; // (x + 1, y, z) skyVertices[i].x = vfpu_sinf((sun_angle/180)*PI)*r;// * stepScale; skyVertices[i].y = vfpu_cosf((sun_angle/180)*PI)*-r;// * stepScale; skyVertices[i].z = 250;// * stepScale; skyVertices[i].u = 1.f;// * textureScale; skyVertices[i].v = 0.f;// * textureScale; i++; // (x + 1, y - 1, z) skyVertices[i].x = vfpu_sinf(((sun_angle-45)/180)*PI)*r;// * stepScale; skyVertices[i].y = vfpu_cosf(((sun_angle-45)/180)*PI)*-r;// * stepScale; skyVertices[i].z = 250;// * stepScale; skyVertices[i].u = 1.f;// * textureScale; skyVertices[i].v = 1.f;// * textureScale; sceKernelDcacheWritebackInvalidateRange(skyVertices,4 * sizeof(CraftPSPVertex)); }