Ejemplo n.º 1
0
Vector4F Vector4F::Normalize()
{
	double mag = sqrt(x*x + y*y + z*z + w*w);
	if (mag < 1.e-8)
		return Vector4F(x*1.e-8, y*1.e-8, z*1.e-8, w*1.e-8);

	float mul = (float)(1.0/mag); 
	return Vector4F(x*mul, y*mul, z*mul, w*mul);
}
Ejemplo n.º 2
0
GLint gluProject( GLdouble objx, GLdouble objy, GLdouble objz, const F64 *model, const F64 * proj, const GLint * vp, F64 * winx, F64 * winy, F64 * winz )
{
    Vector4F v = Vector4F( objx, objy, objz, 1.0f );
    MatrixF pmat = MatrixF( false );
        for (int i=0; i<16; i++) { ((F32*)pmat)[i] = (float)proj[i]; }
    MatrixF mmat = MatrixF( false );
        for (int i=0; i<16; i++) { ((F32*)mmat)[i] = (float)model[i]; }
        
    //Luma: Projection fix
    mmat.transpose();
    pmat.transpose();
    (pmat.mul(mmat)).mul(v);
    
    //Luma: Projection fix
    if(v.w == 0.0f)
    {
        return GL_FALSE;
    }
    F32     invW = 1.0f / v.w;
    v.x *= invW;
    v.y *= invW;
    v.z *= invW;
        
    *winx = (GLfloat)vp[0] + (GLfloat)vp[2] * (v.x + 1.0f) * 0.5f;
    *winy = (GLfloat)vp[1] + (GLfloat)vp[3] * (v.y + 1.0f) * 0.5f;
    *winz = (v.z + 1.0f) * 0.5f;
    int glError;
    glError = TEST_FOR_OPENGL_ERRORS
    return GL_TRUE;
}
Ejemplo n.º 3
0
Vector4F operator*(Vector4F & v, Matrix4x4F & A)
{
	return Vector4F(
		v.x*A.m[0][0] + v.y*A.m[1][0] + v.z*A.m[2][0] + v.w*A.m[3][0],
		v.x*A.m[0][1] + v.y*A.m[1][1] + v.z*A.m[2][1] + v.w*A.m[3][1],
		v.x*A.m[0][2] + v.y*A.m[1][2] + v.z*A.m[2][2] + v.w*A.m[3][2],
		v.x*A.m[0][3] + v.y*A.m[1][3] + v.z*A.m[2][3] + v.w*A.m[3][3]);
}
Ejemplo n.º 4
0
Vector4F operator*(Matrix4x4F & A, Vector4F & v)
{
	return Vector4F(
		A.m[0][0]*v.x + A.m[0][1]*v.y + A.m[0][2]*v.z + A.m[0][3]*v.w,
		A.m[1][0]*v.x + A.m[1][1]*v.y + A.m[1][2]*v.z + A.m[1][3]*v.w,
		A.m[2][0]*v.x + A.m[2][1]*v.y + A.m[2][2]*v.z + A.m[2][3]*v.w,
		A.m[3][0]*v.x + A.m[3][1]*v.y + A.m[3][2]*v.z + A.m[3][3]*v.w);
}
Ejemplo n.º 5
0
Rekd2D::Core::Vector4F Rekd2D::Core::Shader::GetVec4(const std::string &location)
{
    std::map<std::string, unsigned int>::iterator it = m_Locations.find(location);
    int uniform;
    if (it == m_Locations.end())
    {
        uniform = glGetUniformLocation(m_Program, location.c_str());
        m_Locations.insert(std::pair<std::string, unsigned int>(location, uniform));
    }
    else
    {
        uniform = m_Locations[location];
    }
    float out[4];
    glGetUniformfv(m_Program, uniform, out);
    return Vector4F(out[0], out[1], out[2], out[3]);
}
Ejemplo n.º 6
0
GLint gluUnProject( GLdouble winx, GLdouble winy, GLdouble winz, const F64 *model, const F64 * proj, const GLint * vp, F64 * x, F64 * y, F64 * z )
{
    Vector4F v = Vector4F( 2.0f*(winx-vp[0])/vp[2] - 1.0f, 2.0f*(winy-vp[1])/vp[2] - 1.0f, 2.0f*vp[2] - 1.0f, 1.0f );
    MatrixF pmat = MatrixF( false );
    for (int i=0; i<16; i++) { ((F32*)pmat)[i] = (float)proj[i]; }
    MatrixF mmat = MatrixF( false );
    for (int i=0; i<16; i++) { ((F32*)mmat)[i] = (float)model[i]; }
    mmat = pmat.mul(mmat);

    mmat = mmat.inverse();
    mmat.mul( v );
    *x = v.x;
    *y = v.y;
    *z = v.z;
    int glError;
    glError = TEST_FOR_OPENGL_ERRORS
    return GL_TRUE;
}
Ejemplo n.º 7
0
//entry point for the window
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
	LPSTR lpCmdLine, int iCmdShow)
{

	//Bitmap * bmp = new Bitmap("C:\\Users\\Edwin\\Documents\\Visual Studio 2013\\Projects\\Homework\\Debug\\Temp.bmp");

	Level * levelOne = new Level("level1.csv");
	Level * floor = new Level("floor.csv");

	MainRenderer = new Renderer();

	MainRenderer->Init(hInstance, 512, 512);

	//load floor blocks.
	for (int y = 0; y < floor->GetHeight(); y++)
	{
		for (int x = 0; x < floor->GetWidth(); x++)
		{
			if (floor->GetBlock(x, y) == 0)
			{
				MainRenderer->AddToScene(new Block(Vector3F(x * 30, y * 30, 30), Block::BlockType::Floor));
			}
		}
	}

	//load floor wall blocks for level 1.
	for (int y = 0; y < levelOne->GetHeight(); y++)
	{
		for (int x = 0; x < levelOne->GetWidth(); x++)
		{
			if (levelOne->GetBlock(x, y) == 0)
			{
				MainRenderer->AddToScene(new Block(Vector3F(x * 30, y * 30, 0), Block::BlockType::Wall));
			}
		}
	}

	
	
	


	MainRenderer->SetBackBufferColor(Vector4F(0.0f, 0.5f, 1.0f, 1.0f));

	//MainRenderer->GetCamera()->SetPosition(Vector3F(-20.0f, -20.0f, -1000.0f));
	position = Vector3F(0, 0, 0.0f);
	MainRenderer->GetCamera()->SetPosition(position);
	rotation.X = 280.0f;

	//HACK this will make player view look a little higher thant it is.
	position.Z -= 10;

	//HACK place player origin far back enough they can see the level
	position.Y -= 200;

	rotation.Z += 160;

	//get clockspeed
	LARGE_INTEGER li;
	UpdateTimerClockFreq();

	INT64 lastDraw = GetTimerCurrentTime();
	INT64 lastUpdate = GetTimerCurrentTime();



	//while checking for window messages, such as quit/exit
	while (MainRenderer->Update())
	{
		//check if we should update
		if (((GetTimerCurrentTime() - lastUpdate) / coreFrequency) > (1000 / targetUPS))
		{
			Update();
			lastUpdate = GetTimerCurrentTime();
			UpdateTimerClockFreq();
		}

		//check if we should draw, lock at 59fps. this will reduce stutter to a degree but 60 fps would be best.
		if (((GetTimerCurrentTime() - lastDraw) / coreFrequency) > (900 / targetFPS))
		{
			MainRenderer->Draw();
			lastDraw = GetTimerCurrentTime();
			UpdateTimerClockFreq();
		}
	}

	//dispose of memory we no longer need.
	delete MainRenderer;

	return 0;
}
Ejemplo n.º 8
0
Vector4F operator - (float scalar, const Vector4F& rVector)
{
	scalar = scalar * rVector.w();
	return Vector4F(rVector.x() - scalar, rVector.y() - scalar, rVector.z() - scalar, rVector.w());
}
Ejemplo n.º 9
0
Vector4F operator - (const Vector4F& rVector)
{
	return Vector4F(-rVector.x(), -rVector.y(), -rVector.z(), rVector.w());
}