コード例 #1
0
ファイル: matrix.cpp プロジェクト: emileb/XashXT
void matrix4x4::Identity( void )
{
	mat[0] = Vector4D( 1, 0, 0, 0 );
	mat[1] = Vector4D( 0, 1, 0, 0 );
	mat[2] = Vector4D( 0, 0, 1, 0 );
	mat[3] = Vector4D( 0, 0, 0, 1 );
}
コード例 #2
0
ファイル: Light.cpp プロジェクト: radusezciuc/school_projects
// functie care plaseaza efectivl umina in scena
void Light::Render()
{
	// atenuari standard
	glLightf(GL_LIGHT0 + id,GL_CONSTANT_ATTENUATION,1);
	glLightf(GL_LIGHT0 + id,GL_LINEAR_ATTENUATION,0.2f);

	// culoarea luminii 
	glLightfv(GL_LIGHT0 + id, GL_DIFFUSE, Vector4D(diffuse.x, diffuse.y, diffuse.z, diffuse.a).Array());
	// culoarea ambientala 
	glLightfv(GL_LIGHT0 + id, GL_AMBIENT, ambient.Array());
	// culoarea speculara
	glLightfv(GL_LIGHT0 + id, GL_SPECULAR, specular.Array());
	// pozitia luminii
	glLightfv(GL_LIGHT0 + id, GL_POSITION, Vector4D(translation.x,translation.y,translation.z,1).Array());

	// daca este de tip spot , setam parametrii de spot ( se vor folosi valori default )
	if(LightType == IlluminationType::Spot)
	{
		// directia spotului va fi in jos
		glLightfv(GL_LIGHT0 + id , GL_SPOT_DIRECTION, (Vector3D(-1.0,0.0,0.0)).Array());      
		// deschidere de 45 de grade
		glLightf(GL_LIGHT0 + id , GL_SPOT_CUTOFF, 45.0);
		glLightf(GL_LIGHT0 + id , GL_SPOT_EXPONENT, 2);
	}

	// activam lumina
	glEnable(GL_LIGHT0 + id);
}
コード例 #3
0
ファイル: Box.cpp プロジェクト: avinashdamodhare/Avni
	void Box::Init()
	{
		m_MeshData = (char*)malloc(sizeof(Avni_Vertex_pos_diffuse)*4);
		Avni_Vertex_pos_diffuse* mesh = (Avni_Vertex_pos_diffuse*)(m_MeshData);

		Avni_Vertex_pos_diffuse vert[4];
		vert[0].vertex		= Vector4D(-1.0f, 1.0f, 0.0f,1.0f);
		vert[1].vertex		= Vector4D( 1.0f, 1.0f, 0.0f,1.0f);
		vert[2].vertex		= Vector4D( 1.0f,-1.0f, 0.0f,1.0f);
		vert[3].vertex		= Vector4D(-1.0f,-1.0f, 0.0f,1.0f);

		vert[0].diffuseColor = Vector3D(1.0f,0.0f,0.0f);
		vert[1].diffuseColor = Vector3D(0.0f,1.0f,0.0f);
		vert[2].diffuseColor = Vector3D(0.0f,0.0f,1.0f);
		vert[3].diffuseColor = Vector3D(1.0f,0.0f,1.0f);
		
		u32 indices[] =
		{
			0, 1, 3,
			3, 1, 2,
		};

        m_Mesh      = SINGLETONMANAGER->GetRenderer()->CreateMesh(VERTEXTYPE_POS_DIFFUSE, 4, vert,indices, 6);
        m_Material  = SINGLETONMANAGER->GetMaterialManager()->GetMaterial(MATERIALNAME_BASIC);
	}
コード例 #4
0
ファイル: a4.cpp プロジェクト: 0ctobyte/raytracer
Matrix4x4 a4_get_unproject_matrix(int width, int height, double fov, double d, Point3D eye, Vector3D view, Vector3D up)
{
  double fov_r = fov * M_PI / 180.0;
  double h = 2.0*d*tan(fov_r / 2.0); // height of projection plane based field of view and distance to the plane
  
  // First translate the pixel so that it is centered at the origin in the projection plane (origin is in the middle of the screen)
  Matrix4x4 viewport_translate = Matrix4x4().translate(-(double)width / 2.0, -(double)height / 2.0, d);

  // Then scale it to the projection plane such that aspect ratio is maintained and we have a right handed coordinate system
  Matrix4x4 viewport_scale = Matrix4x4().scale(-h / (double)height, -h / (double)height, 1.0);

  // Calculate the basis for the view coordinate system
  view.normalize();
  up.normalize();
  Vector3D u = up.cross(view);
  u.normalize();
  Vector3D v = view.cross(u);
  v.normalize();

  // Create the view rotation and translation matrix
  Matrix4x4 view_rotate = Matrix4x4(Vector4D(u, 0.0), Vector4D(v, 0.0), Vector4D(view, 0.0), Vector4D(0.0, 0.0, 0.0, 1.0)).transpose();
  Matrix4x4 view_translate = Matrix4x4().translate(Vector3D(eye));

  // Now multiply these together to form the pixel to 3D point transformation matrix
  Matrix4x4 unproject = view_translate * view_rotate * viewport_scale * viewport_translate;

  return unproject;
}
コード例 #5
0
ファイル: scene.cpp プロジェクト: t2munika/raytracer
void SceneNode::scale(const Vector3D& amount)
{
  Matrix4x4 t = Matrix4x4(
    Vector4D(amount[0], 0.0, 0.0, 0.0),
    Vector4D(0.0, amount[1], 0.0, 0.0),
    Vector4D(0.0, 0.0, amount[2], 0.0),
    Vector4D(0.0, 0.0, 0.0, 1.0)
  );
  set_transform(m_trans * t);
}
コード例 #6
0
int COpenGLGrassRenderer::Sorter::compareElements( SGPVertex_GRASS_Cluster first, SGPVertex_GRASS_Cluster second ) noexcept
{
	float firstDistance = -(m_pRD->getOpenGLCamera()->m_CameraPos - Vector4D(first.vPosition[0], first.vPosition[1], first.vPosition[2])).GetLengthSquared();
	float secondDistance = -(m_pRD->getOpenGLCamera()->m_CameraPos - Vector4D(second.vPosition[0], second.vPosition[1], second.vPosition[2])).GetLengthSquared();
	if( firstDistance < secondDistance )
		return -1;
	if( firstDistance > secondDistance )
		return 1;
	return 0;
}
コード例 #7
0
ファイル: scene.cpp プロジェクト: t2munika/raytracer
void SceneNode::translate(const Vector3D& amount)
{
  Matrix4x4 t = Matrix4x4(
    Vector4D(1.0, 0.0, 0.0, amount[0]),
    Vector4D(0.0, 1.0, 0.0, amount[1]),
    Vector4D(0.0, 0.0, 1.0, amount[2]),
    Vector4D(0.0, 0.0, 0.0, 1.0)
  );
  set_transform(m_trans * t);
}
コード例 #8
0
ファイル: Matrix4D.cpp プロジェクト: psarahdactyl/CGpractice
    Matrix4D::Matrix4D( float m00, float m10, float m20, float m30,
	  float m01, float m11, float m21, float m31,
	  float m02, float m12, float m22, float m32,
	  float m03, float m13, float m23, float m33 ) 
	{
	    m[0] = Vector4D( m00, m10, m20, m30 );
	    m[1] = Vector4D( m01, m11, m21, m31 );
	    m[2] = Vector4D( m02, m12, m22, m32 );
	    m[3] = Vector4D( m03, m13, m23, m33 );
	}
コード例 #9
0
void CustomObject3D::setDefault()
{
	// Default lighting
	diffuse = Vector4D(1,1,1,1);
	ambient = Vector4D(0,0,0,0);
	specular = Vector4D(1,1,1,1);
	color = Vector3D(1,1,1);
	scale = Vector3D(1.0,1.0,1.0);

	// Default, it's not wireframe
	Wireframe = false;
}
コード例 #10
0
ファイル: Satellite.cpp プロジェクト: evelinad/Space-Invaders
void Satellite::setParameters(GLuint size){

	explosion = NULL;
	ambient4f1= Vector4D(0.9, 0.4, 0.1, 1);
	diffuse4f1=Vector4D(0.9, 0.4, 0.1, 1);	
	specular4f1=Vector4D(0.9, 0.9, 0.9, 1.0);

	Vector4D emmision4f1(0, 0, 0, 1);
	static GLint shininess1 = 64;
	GLfloat ast_color [][5] = { {0.5, 0.2, 0.2, 2},
								{0.55, 0.55, 0.55, 2},
								{0.01, 0.3, 0.1, 2},
								{0.7, 0.4, 0.3, 2},
								{0.7, 0.3, 0.5, 2},
								{0, 0, 0.2, 2}
								};

	int pick = rand() % 6;
	//setare pozitie + culoare asteroid
	for(int i = 0; i < 4; i++)
		color[i] = ast_color[pick][i];

	box = size;
	posx =  rand() % box;
	posy = rand() % box;
	posz = rand() % box;

	Size = (rand() % 5+3)/2.0;
	time = 0;
	


	dx = (double) (rand() % RAND_MAX) / RAND_MAX * 2;
	int sign=rand()%2-1;
	dx*=sign;
	
 {
		dz = (double) (rand() % RAND_MAX) / RAND_MAX;
		
	
		dy = (double) (rand() % RAND_MAX) / RAND_MAX;
		sign=rand()%2-1;
	//	dy*=sign;
	
	}

	v0 = (double) (rand() % RAND_MAX) / RAND_MAX;
	//acc = (double) (rand() % RAND_MAX) / RAND_MAX;
	
	//v0 = 0;
	

}
コード例 #11
0
Vector4D    GlslProgram :: getUniformVector ( const char * name )
{
    float   values [4];

    int loc = glGetUniformLocationARB ( program, name );

    if ( loc < 0 )
        return Vector4D ( 0, 0, 0, 0 );

    glGetUniformfvARB ( program, loc, values );

    return Vector4D ( values [0], values [1], values [2], values [3] );
}
コード例 #12
0
Vector4D    GlslProgram :: getAttribute ( const char * name )
{
    int index = glGetAttribLocationARB ( program, name );

    if ( index < 0 )
        return Vector4D ( 0, 0, 0, 0 );

    float   buf [4];

    glGetVertexAttribfvARB ( index, GL_CURRENT_VERTEX_ATTRIB_ARB, buf );

    return Vector4D ( buf [0], buf [1], buf [2], buf [3] );
}
コード例 #13
0
ファイル: a2.cpp プロジェクト: tejkoorapati/graphics
void scale(Matrix4x4 &mat,double x,double y,double z)
{
    Matrix4x4 temp;
    Vector4D r1,r2,r3,r4;

    r1=Vector4D(x,0,0,0);
    r2=Vector4D(0,y,0,0);
    r3=Vector4D(0,0,z,0);
    r4=Vector4D(0,0,0,1);
    temp=Matrix4x4(r1,r2,r3,r4);
    mat=temp*mat;

}
コード例 #14
0
ファイル: a2.cpp プロジェクト: tejkoorapati/graphics
void translate(Matrix4x4 &mat,double x,double y,double z)
{
    Matrix4x4 temp;
    Vector4D r1,r2,r3,r4;

    r1=Vector4D(1,0,0,x);
    r2=Vector4D(0,1,0,y);
    r3=Vector4D(0,0,1,z);
    r4=Vector4D(0,0,0,1);
    temp=Matrix4x4(r1,r2,r3,r4);
    mat=mat*temp;

}
コード例 #15
0
ファイル: sonarmonitor.cpp プロジェクト: patnashev/vertigo
void SonarMonitor::draw()
{
    Point point = m_hud->project(m_point);
    int radius = (m_hud->project(m_point + Point(0, m_radius)) - point).y;
    float scale = static_cast<float>(radius)/m_scale;
    PointF center = PointF(point) - PointF(1.5f);
    RectF rect = RectF(center, SizeF(4, 4));
    Matrix m(1);
    m = glm::scale(m, Vector3D(1, -1, 0));
    m = glm::rotate(m, m_hud->scenario()->yaw(), Vector3D(0, 0, 1));
    m = glm::translate(m, -m_hud->scenario()->position());

    m_hud->fontGreen().draw("T", point + Point(-2, -radius));
    m_hud->fontGreen().draw(QString("%1M").arg(m_scale), Rect(point + Point(-100, radius - 8), SizeF(200, -1)), true, false);
    m_center.draw(rect);

    for (fight::NavPoint *navPoint : m_hud->scenario()->navPoints())
        if (navPoint->isEnabled())
        {
            Vector2D dir = Vector2D(m * Vector4D(navPoint->position(), 1));
            float distance = glm::length(dir);
            if (distance < m_scale)
            {
                rect.setPos(center - dir*scale);
                m_nav.draw(rect);
            }
        }

    for (const auto &entry : m_hud->scenario()->sonar())
    {
        Vector2D dir = Vector2D(m * Vector4D(entry.object->position(), 1));
        float distance = glm::length(dir);
        if (distance < m_scale)
        {
            rect.setPos(center - dir*scale);
            (entry.isFriend ? m_friend : m_enemy).draw(rect);
        }
    }

    fight::Target &target = m_hud->scenario()->target();
    if (target.isLocked())
    {
        Vector2D dir = Vector2D(m * Vector4D(target.position(), 1));
        float distance = glm::length(dir);
        if (distance < m_scale)
        {
            rect.setPos(center - dir*scale);
            m_target.draw(rect);
        }
    }
}
コード例 #16
0
// constructor care primeste ca parametru latura cubului
Cube::Cube() : Object3D()
{
	// valori default
	diffuse = Vector4D(1,1,1,1);
	ambient = Vector4D(0,0,0,0);
	specular = Vector4D(1,1,1,1);
	color = Vector3D(1,1,1);
	scale = Vector3D(1.0,1.0,1.0);

	// default , nu este wireframe
	Wireframe = false;

	latura = 1.0;

}
コード例 #17
0
ファイル: Quad.cpp プロジェクト: JordanHeinrichs/RayTracer
Quad::Quad(const Point3D& point1,
    const Point3D& point2,
    const Point3D& point3,
    const Point3D& point4,
    const Material& material)
: tri1_(point1, point2, point4, material)
, tri2_(point2, point3, point4, material)
{
    // Verify that it is on the
    if (tri1_.normal(Vector4D()) != tri2_.normal(Vector4D()))
    {
        std::cout << "All points of quad must be in the same plane." << std::endl;
        std::exit(-1);
    }
}
コード例 #18
0
ファイル: Vector4DMath.cpp プロジェクト: JSandrew4/FastGdk
		Vector4D CatmullRom(const Vector4D &a, const Vector4D &b,
			const Vector4D &c, const Vector4D &d, Float t) {
			return Vector4D(Math::CatmullRom(a.mX, b.mX, c.mX, d.mX, t),
				Math::CatmullRom(a.mY, b.mY, c.mY, d.mY, t),
				Math::CatmullRom(a.mZ, b.mZ, c.mZ, d.mZ, t),
				Math::CatmullRom(a.mW, b.mW, c.mW, d.mW, t));
		}
コード例 #19
0
ファイル: Matrix4D.cpp プロジェクト: psarahdactyl/CGpractice
    Vector4D Matrix4D::operator * ( const Vector4D& v ) const 
    { 
		return Vector4D( m[0][0]*v.x + m[0][1]*v.y + m[0][2]*v.z + m[0][3]*v.w,
		     m[1][0]*v.x + m[1][1]*v.y + m[1][2]*v.z + m[1][3]*v.w,
		     m[2][0]*v.x + m[2][1]*v.y + m[2][2]*v.z + m[2][3]*v.w,
		     m[3][0]*v.x + m[3][1]*v.y + m[3][2]*v.z + m[3][3]*v.w );
    }
コード例 #20
0
// functie override customDraw(), apelata din Draw()-ul din Object3D
void Plane::customDraw()
{
	glPushMatrix();

	// setari de material
	glMaterialfv(GL_FRONT,GL_DIFFUSE,(Vector4D(color.x ,color.y,color.z,1)).Array());
	glMaterialfv(GL_FRONT,GL_AMBIENT,(Vector4D(color.x*ambientColorIntensity, color.y*ambientColorIntensity, color.z*ambientColorIntensity,1)).Array());
	glMaterialfv(GL_FRONT,GL_SPECULAR,(Vector4D(0,0,0,0)).Array());


	float leftMargin,rightMargin;

	leftMargin = -size;
	rightMargin = size;

	float i,j;
	float factor = 0.1f;

	// mutare in coordonate
	glTranslatef(translation.x, translation.y, translation.z);
	// colorare corespunzatoare
	glColor3f(color.x, color.y, color.z);

	// desenare plan
	for( i = leftMargin ; i+(levelOfDetail*factor)<=rightMargin; i+=(levelOfDetail*factor))
		for(j=leftMargin;j+(levelOfDetail*factor)<=rightMargin; j+=(levelOfDetail*factor))
		{
			if( !Wireframe)
				glBegin(GL_QUADS);
			else
				glBegin(GL_LINE_LOOP);

			glNormal3f(0.0,1.0,0.0);
			glVertex3f(i ,  0, j);
			glVertex3f(i, 0, j+(levelOfDetail*factor));
			if(j+(levelOfDetail*factor) !=rightMargin)
				glVertex3f(i+(levelOfDetail*factor), 0, j+(levelOfDetail*factor));
			else
				glVertex3f(i+(levelOfDetail*factor), 0, rightMargin);

			glVertex3f(i+(levelOfDetail*factor),  0, j);

			glEnd();
		}

	glPopMatrix();
}
コード例 #21
0
ファイル: Vector4DMath.cpp プロジェクト: JSandrew4/FastGdk
		Vector4D Barycentric(const Vector4D &a,
			const Vector4D &b, const Vector4D &c, Float t1, Float t2)
		{
			return Vector4D(Math::Barycentric(a.mX, b.mX, c.mX, t1, t2),
				Math::Barycentric(a.mY, b.mY, c.mY, t1, t2),
				Math::Barycentric(a.mZ, b.mZ, c.mZ, t1, t2),
				Math::Barycentric(a.mW, b.mW, c.mW, t1, t2));
		}
コード例 #22
0
Vector4D    GlslProgram :: getAttribute ( int index )
{
    float   buf [4];

    glGetVertexAttribfvARB ( index, GL_CURRENT_VERTEX_ATTRIB_ARB, buf );

    return Vector4D ( buf [0], buf [1], buf [2], buf [3] );
}
コード例 #23
0
ファイル: Vector4DMath.cpp プロジェクト: JSandrew4/FastGdk
		Vector4D Decelerate(const Vector4D &a,
			const Vector4D &b, Float t)
		{
			return Vector4D(Math::Decelerate(a.mX, b.mX, t),
				Math::Decelerate(a.mY, b.mY, t),
				Math::Decelerate(a.mZ, b.mZ, t),
				Math::Decelerate(a.mW, b.mW, t));
		}
コード例 #24
0
ファイル: Vector4DMath.cpp プロジェクト: JSandrew4/FastGdk
		Vector4D Clamp(const Vector4D &value,
			const Vector4D &min, const Vector4D &max)
		{
			return Vector4D(Math::WrapFloat(value.mX, min.mX, max.mX),
				Math::WrapFloat(value.mY, min.mY, max.mY),
				Math::WrapFloat(value.mZ, min.mZ, max.mZ),
				Math::WrapFloat(value.mW, min.mW, max.mW));
		}
コード例 #25
0
ファイル: Vector4DMath.cpp プロジェクト: JSandrew4/FastGdk
		Vector4D SmoothStep(const Vector4D &a,
			const Vector4D &b, Float t)
		{
			return Vector4D(Math::SmoothStep(a.mX, b.mX, t),
				Math::SmoothStep(a.mY, b.mY, t),
				Math::SmoothStep(a.mZ, b.mZ, t),
				Math::SmoothStep(a.mW, b.mW, t));
		}
コード例 #26
0
ファイル: ShaderManager.cpp プロジェクト: Easycker/rt-phm
	Vector4D ShaderManager :: GetUniformVector ( int location )
	{
		float values [SIZE4D];

		glGetUniformfv ( Program, location, values );

		return Vector4D ( values );
	}
コード例 #27
0
ファイル: ShaderManager.cpp プロジェクト: Easycker/rt-phm
	Vector4D ShaderManager :: GetAttributeVector ( int location )
	{
		float values [SIZE4D];

		glGetVertexAttribfv ( location, GL_CURRENT_VERTEX_ATTRIB, values );

		return Vector4D ( values );
	}
コード例 #28
0
ファイル: transformation.cpp プロジェクト: yxrkt/DigiPen
Vector4D Transformation::Transform(const Vector4D& V)
{
	return Vector4D(
	 curr[0][0]*V[0] + curr[0][1]*V[1] + curr[0][2]*V[2] + curr[0][3]*V[3],
	 curr[1][0]*V[0] + curr[1][1]*V[1] + curr[1][2]*V[2] + curr[1][3]*V[3],
	 curr[2][0]*V[0] + curr[2][1]*V[1] + curr[2][2]*V[2] + curr[2][3]*V[3],
	 curr[3][0]*V[0] + curr[3][1]*V[1] + curr[3][2]*V[2] + curr[3][3]*V[3]
	);
}
コード例 #29
0
ファイル: transformation.cpp プロジェクト: yxrkt/DigiPen
Vector4D Transformation::InverseTransform(Vector4D& V)
{
	return Vector4D(
	 inv[0][0]*V[0] + inv[0][1]*V[1] + inv[0][2]*V[2] + inv[0][3]*V[3],
	 inv[1][0]*V[0] + inv[1][1]*V[1] + inv[1][2]*V[2] + inv[1][3]*V[3],
	 inv[2][0]*V[0] + inv[2][1]*V[1] + inv[2][2]*V[2] + inv[2][3]*V[3],
	 inv[3][0]*V[0] + inv[3][1]*V[1] + inv[3][2]*V[2] + inv[3][3]*V[3]
	);
}
コード例 #30
0
ファイル: Light.cpp プロジェクト: radusezciuc/school_projects
// constructor fara parametri, mosteneste constructorul de Sfera din Object3D
// deoarece dorim ca lumina sa fie ilustrata printr-o sfera
Light::Light() : Object3D(GlutSphere)
{
	// valori default
	diffuse = Vector4D(4,4,4,1);
	ambient = Vector4D(0,0,0,0);
	specular = Vector4D(1,1,1,1);
	color = Vector3D(1,1,1);
	scale = Vector3D(0.2,0.2,0.2);

	// id-ul este unic, id-ul de baza incrementat
	id = baseId++;
	
	// sfera plasata in locul luminii nu este wireframe
	Wireframe = false;

	// default lumina este omnidirectionala
	LightType = IlluminationType::Ideal;
}