Esempio n. 1
0
void CParametricSurface::Vertex(Vec2 domain)
{
    Vec3 p0, p1, p2, p3;
    Vec3 normal;
    float u = domain.x;
    float v = domain.y;
	
    Eval(domain, p0);
    Vec2 z1(u + du/2, v);
    Eval(z1, p1);
    Vec2 z2(u + du/2 + du, v);
    Eval(z2, p3);
	
    if (flipped) {
        Vec2 z3(u + du/2, v - dv);
        Eval(z3, p2);
    } else {
        Vec2 z4(u + du/2, v + dv);
        Eval(z4, p2);
    }
	
    const float epsilon = 0.00001f;
	
    Vec3 tangent = p3 - p1;
    Vec3 binormal = p2 - p1;
    MatrixVec3CrossProduct(normal, tangent, binormal);
    if (normal.length() < epsilon)
        normal = p0;
    normal.normalize();
	if (tangent.length() < epsilon)
		MatrixVec3CrossProduct(tangent, binormal, normal);
	tangent.normalize();
	binormal.normalize();
	binormal = binormal * -1.0f;
	 
	/*
    if (CustomAttributeLocation() != -1)
        glVertexAttrib1f(CustomAttributeLocation(), CustomAttributeValue(domain));
	 */
	
    //glNormal(normal);
    //glTexCoord(domain);
    //glVertex(p0);
	int vertexIndex = totalVertex * 14;
	vertexBuffer[vertexIndex++] = p0.x;
	vertexBuffer[vertexIndex++] = p0.y;
	vertexBuffer[vertexIndex++] = p0.z;
	vertexBuffer[vertexIndex++] = domain.x;
	vertexBuffer[vertexIndex++] = domain.y;
	vertexBuffer[vertexIndex++] = normal.x;
	vertexBuffer[vertexIndex++] = normal.y;
	vertexBuffer[vertexIndex++] = normal.z;
	vertexBuffer[vertexIndex++] = tangent.x;
	vertexBuffer[vertexIndex++] = tangent.y;
	vertexBuffer[vertexIndex++] = tangent.z;
	vertexBuffer[vertexIndex++] = binormal.x;
	vertexBuffer[vertexIndex++] = binormal.y;
	vertexBuffer[vertexIndex++] = binormal.z;
}
Esempio n. 2
0
void SimpleCamera::strafe(const float_t steps)
{
	Vec3 sideDir;
	MatrixVec3CrossProduct(sideDir, _direction, _up);
	_position += (sideDir * _maxForwardVelocity * steps);
	_hasChangedParameters = true;
}
Esempio n. 3
0
void MatrixLookAtRH(
	MATRIX			&mOut,
	const VECTOR3	&vEye,
	const VECTOR3	&vAt,
	const VECTOR3	&vUp)
{
	VECTOR3 f, vUpActual, s, u;
	MATRIX	t;

	f.x = vAt.x - vEye.x;
	f.y = vAt.y - vEye.y;
	f.z = vAt.z - vEye.z;

	MatrixVec3Normalize(f, f);
	MatrixVec3Normalize(vUpActual, vUp);
	MatrixVec3CrossProduct(s, f, vUpActual);
	MatrixVec3CrossProduct(u, s, f);

	mOut.f[ 0] = s.x;
	mOut.f[ 1] = u.x;
	mOut.f[ 2] = -f.x;
	mOut.f[ 3] = 0;

	mOut.f[ 4] = s.y;
	mOut.f[ 5] = u.y;
	mOut.f[ 6] = -f.y;
	mOut.f[ 7] = 0;

	mOut.f[ 8] = s.z;
	mOut.f[ 9] = u.z;
	mOut.f[10] = -f.z;
	mOut.f[11] = 0;

	mOut.f[12] = 0;
	mOut.f[13] = 0;
	mOut.f[14] = 0;
	mOut.f[15] = 1;

	MatrixTranslation(t, -vEye.x, -vEye.y, -vEye.z);
	MatrixMultiply(mOut, t, mOut);
}