Exemple #1
0
bool BBox::Overlap( const vec3f& p ) const
{
    bool x = (pMax.x() >= p.x()) && (pMin.x() <= p.x());
    bool y = (pMax.y() >= p.y()) && (pMin.y() <= p.y());
    bool z = (pMax.z() >= p.z()) && (pMin.z() <= p.z());
    return (x && y && z);
}
void GLVBO::DrawQuad( int type, const vec3f &p1, const vec3f &p2, const vec3f &p3, const vec3f &p4)
{
    GLfloat verts[] = {
        p1.x(), p1.y(), p1.z(),
        p2.x(), p2.y(), p2.z(),
        p3.x(), p3.y(), p3.z(),
        p4.x(), p4.y(), p4.z()
    };
    glVertexPointer(3, GL_FLOAT, 0, verts);
    glEnableClientState(GL_VERTEX_ARRAY);
    glDrawArrays(type, 0, 4);
    glDisableClientState(GL_VERTEX_ARRAY);
}
Exemple #3
0
color texture2D(vec3f coords, texture t){
	int x = coords.x() * t.width;
	int y = t.height-(coords.y() * t.height);
	if(t.bytesperpixel == 4){
		return t.data[y*t.height + x];
	}
	uint8_t* data = (uint8_t*)t.data;
	
	int col= (int)(data[t.bytesperpixel*(y*t.height + x)]);
	
	return gammaCorrect((color){static_cast<uint8_t>(col>>24),static_cast<uint8_t>((col>>16) &255),static_cast<uint8_t>((col>>8)&255),255});
Exemple #4
0
void clamp(vec3f & v, float min, float max)
{
	if(v.peekx() > max) v.x() = max;
	if(v.peekx() < min) v.x() = min;

	if(v.peeky() > max) v.y() = max;
	if(v.peeky() < min) v.y() = min;

	if(v.peekz() > max) v.z() = max;
	if(v.peekz() < min) v.z() = min;
}
Exemple #5
0
void clamp(vec3f & v, float vmin, float vmax)
{
    if(v.peekx() > vmax) v.x() = vmax;
    if(v.peekx() < vmin) v.x() = vmin;

    if(v.peeky() > vmax) v.y() = vmax;
    if(v.peeky() < vmin) v.y() = vmin;

    if(v.peekz() > vmax) v.z() = vmax;
    if(v.peekz() < vmin) v.z() = vmin;
}
Exemple #6
0
bool baryCentricTriangle(vec2f p, vec3f v1, vec3f v2, vec3f 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;
}
Exemple #7
0
vec2f Grid::coordsToMapPos(vec3f coords) {
	GLfloat width = d_cellWidth * d_rows;
	GLfloat height = d_cellHeight * d_cols;
	
	GLfloat x = floor(coords.x() / width);
	GLfloat y = floor(coords.z() / height);
	
	// Clamp the values into the bounds
	if (x > d_rows) {
		x = d_rows;
	} else if (x < 0) {
		x = 0;
	}
	
	if (y > d_cols) {
		y = d_cols;
	} else if (y < 0) {
		y = 0;
	}
	
	return vec2f(x, y);
}
Exemple #8
0
 void Shader::setUniform(const std::string &name, const vec3f v, bool warn) {
     glUniform3f(uniform(name, warn), v.x(), v.y(), v.z());
 }
Exemple #9
0
vec3i::vec3i( const vec3f &v )
{
    m_x = (int)v.x();
    m_y = (int)v.y();
    m_z = (int)v.z();
}
Exemple #10
0
bool BBox::Inside( const vec3f& pt) const
{
    return (pt.x() >= pMin.x() && pt.x() <= pMax.x() &&
            pt.y() >= pMin.y() && pt.y() <= pMax.y() &&
            pt.z() >= pMin.z() && pt.z() <= pMax.z());
}