Example #1
0
void matmultvec4f(const float * matrix, const vec4f& v, vec4f& ssv)
{
	ssv.x() = matrix[0] * v.peekx() + matrix[4] * v.peeky() +  matrix[8] * v.peekz() + matrix[12] * v.peekw();
	ssv.y() = matrix[1] * v.peekx() + matrix[5] * v.peeky() +  matrix[9] * v.peekz() + matrix[13] * v.peekw();
	ssv.z() = matrix[2] * v.peekx() + matrix[6] * v.peeky() + matrix[10] * v.peekz() + matrix[14] * v.peekw();
	ssv.w() = matrix[3] * v.peekx() + matrix[7] * v.peeky() + matrix[11] * v.peekz() + matrix[15] * v.peekw();
}
Example #2
0
// 4D
vec4f operator+(const vec4f& v1, const vec4f &v2)
{
	return vec4f(v1.peekx()+v2.peekx(),
                 v1.peeky()+v2.peeky(),
                 v1.peekz()+v2.peekz(),
				 v1.peekw()+v2.peekw());
}
Example #3
0
// misc math
bool baryCentricTriangle(vec2f p, vec4f v1, vec4f v2, vec4f v3, float &u, float &v, float &r)
{
	float x1mx3 = v1.x() - v3.x();
	float x2mx3 = v2.x() - v3.x();
	float y1my3 = v1.y() - v3.y();
	float y2my3 = v2.y() - v3.y();

	float det = (x1mx3 * y2my3) - (y1my3*x2mx3);

	float pxmx3 = p.x() - v3.x();
	float pymy3 = p.y() - v3.y();

	if(det == 0.0 || det == -0.0) return false;

	u = (y2my3*pxmx3 + x2mx3*-1*pymy3)/det;
	v = (y1my3*-1*pxmx3 + x1mx3*pymy3)/det;
	r = 1-u-v;

	if (u > 1.0f || v > 1.0f || r > 1.0f) return false;
	if (u < 0.0f || v < 0.0f || r < 0.0f) return false;

	return true;
}
Example #4
0
 void Shader::setUniform(const std::string &name, const vec4f v, bool warn) {
     glUniform4f(uniform(name, warn), v.x(), v.y(), v.z(), v.w());
 }
Example #5
0
static void computetarget() {
  const float w = float(sys::scrw), h = float(sys::scrh);
  const vec4f nc(w/2,h/2,1.f,1.f);
  const vec4f world = game::invmvpmat * nc;
  game::setworldpos(world.xyz()/world.w);
}
Example #6
0
float dot(const vec4f& v1, const vec4f& v2){
    return ((v1.peekx()*v2.peekx())+
            (v1.peeky()*v2.peeky())+
            (v1.peekz()*v2.peekz()));
}
Example #7
0
vec4f operator*(const vec4f& v1, const float& k){
    return vec4f(v1.peekx()*k,
                 v1.peeky()*k,
                 v1.peekz()*k,
				 v1.peekw()*k);
}