Exemple #1
0
void GPU_MultMatrix(float* A)
{
    float* result = GPU_GetCurrentMatrix();
    if(result == NULL)
        return;
    GPU_MultiplyAndAssign(result, A);
}
Exemple #2
0
void GPU_Translate(float x, float y, float z)
{
    float* result = GPU_GetCurrentMatrix();
    if(result == NULL)
		return;

	{
#ifdef ROW_MAJOR
		float A[16];
		FILL_MATRIX_4x4(A,
				1, 0, 0, x,
				0, 1, 0, y,
				0, 0, 1, z,
				0, 0, 0, 1
			);
#else
		float A[16];
		FILL_MATRIX_4x4(A,
				1, 0, 0, 0,
				0, 1, 0, 0,
				0, 0, 1, 0,
				x, y, z, 1
			);
#endif

		GPU_MultiplyAndAssign(result, A);
	}
}
Exemple #3
0
void GPU_Frustum(float right, float left, float bottom, float top, float near, float far)
{
    float* result = GPU_GetCurrentMatrix();
    if(result == NULL)
		return;

	{
#ifdef ROW_MAJOR
		float A[16];
		FILL_MATRIX_4x4(A, 
				2 * near / (right - left), 0, 0, 0,
				0, 2 * near / (top - bottom), 0, 0,
				(right + left) / (right - left), (top + bottom) / (top - bottom), -(far + near) / (far - near), -1,
				0, 0, -(2 * far * near) / (far - near), 0
			);
#else
		float A[16];
		FILL_MATRIX_4x4(A,
				2 * near / (right - left), 0, (right + left) / (right - left), 0,
				0, 2 * near / (top - bottom), (top + bottom) / (top - bottom), 0,
				0, 0, -(far + near) / (far - near), -(2 * far * near) / (far - near),
				0, 0, -1, 0
			);
#endif

		GPU_MultiplyAndAssign(result, A);
	}
}
Exemple #4
0
void GPU_LoadIdentity(void)
{
    float* result = GPU_GetCurrentMatrix();
    if(result == NULL)
        return;
    GPU_MatrixIdentity(result);
}
Exemple #5
0
void GPU_Scale(float sx, float sy, float sz)
{
    float* result = GPU_GetCurrentMatrix();
    if(result == NULL)
		return;

	{
		float A[16] = { sx, 0, 0, 0,
			0, sy, 0, 0,
			0, 0, sz, 0,
			0, 0, 0, 1 };

		GPU_MultiplyAndAssign(result, A);
	}
}
Exemple #6
0
void GPU_Rotate(float degrees, float x, float y, float z)
{
	float p, radians, c, s, c_, zc_, yc_, xzc_, xyc_, yzc_, xs, ys, zs;
	float* result;

    p = 1/sqrtf(x*x + y*y + z*z);
    x *= p; y *= p; z *= p;
    radians = degrees * (M_PI/180);
    c = cosf(radians);
    s = sinf(radians);
    c_ = 1 - c;
    zc_ = z*c_;
    yc_ = y*c_;
    xzc_ = x*zc_;
    xyc_ = x*y*c_;
    yzc_ = y*zc_;
    xs = x*s;
    ys = y*s;
    zs = z*s;

    result = GPU_GetCurrentMatrix();
    if(result == NULL)
		return;

	{
#ifdef ROW_MAJOR
		float A[16];
		FILL_MATRIX_4x4(A,
				x*x*c_ + c,  xyc_ - zs,   xzc_ + ys, 0,
				xyc_ + zs,   y*yc_ + c,   yzc_ - xs, 0,
				xzc_ - ys,   yzc_ + xs,   z*zc_ + c, 0,
				0,           0,           0,         1
			);
#else
		float A[16];
		FILL_MATRIX_4x4(A,
				x*x*c_ + c, xyc_ + zs, xzc_ - ys, 0,
				xyc_ - zs, y*yc_ + c, yzc_ + xs, 0,
				xzc_ + ys, yzc_ - xs, z*zc_ + c, 0,
				0, 0, 0, 1
			);
#endif

		GPU_MultiplyAndAssign(result, A);
	}
}
Exemple #7
0
void GPU_Scale(float sx, float sy, float sz)
{
    float* result = GPU_GetCurrentMatrix();
    if(result == NULL)
		return;

	{
		float A[16];
		FILL_MATRIX_4x4(A,
				sx, 0, 0, 0,
				0, sy, 0, 0,
				0, 0, sz, 0,
				0, 0, 0, 1
			);

		GPU_MultiplyAndAssign(result, A);
	}
}
Exemple #8
0
void GPU_Ortho(float left, float right, float bottom, float top, float near, float far)
{
    float* result = GPU_GetCurrentMatrix();
    if(result == NULL)
		return;

	{
#ifdef ROW_MAJOR
		float A[16] = {2/(right - left), 0,  0, -(right + left)/(right - left),
			0, 2/(top - bottom), 0, -(top + bottom)/(top - bottom),
			0, 0, -2/(far - near), -(far + near)/(far - near),
			0, 0, 0, 1};
#else
		float A[16] = { 2 / (right - left), 0, 0, 0,
			0, 2 / (top - bottom), 0, 0,
			0, 0, -2 / (far - near), 0,
			-(right + left) / (right - left), -(top + bottom) / (top - bottom), -(far + near) / (far - near), 1 };
#endif

		GPU_MultiplyAndAssign(result, A);
	}
}