예제 #1
0
//-----------------------------------------------------------------------------------
void TheGame::RenderCoolStuff() const
{
    Matrix4x4 view = Renderer::instance->GetView();
    Matrix4x4 proj = Renderer::instance->GetProjection();
    Matrix4x4 translation;
    Matrix4x4 rotation;
    Matrix4x4 model;

    m_currentMaterial->m_shaderProgram->SetVec3Uniform("gCameraPosition", m_camera->m_position);

    Matrix4x4::MatrixMakeTranslation(&translation, Vector3(0.0f, sin((float)GetCurrentTimeSeconds()) * spinFactor, 3.0f));
    Matrix4x4::MatrixMakeRotationAroundY(&rotation, (float)GetCurrentTimeSeconds() * spinFactor);
    Matrix4x4::MatrixMultiply(&model, &rotation, &translation);

    if ((g_loadedMotion || g_loadedMotions) && g_loadedSkeleton)
    {
        int NUM_BONES = 200;
        for (unsigned int i = 0; i < g_loadedSkeleton->m_jointArray.size(); ++i)
        {
            Matrix4x4 world = g_loadedSkeleton->GetWorldBoneToModelOutOfLocal(i); //g_loadedSkeleton->m_jointArray.at(i).m_boneToModelSpace; 
            Matrix4x4 inverseWorld = g_loadedSkeleton->m_jointArray.at(i).m_modelToBoneSpace; //g_loadedSkeleton->GetWorldModelToBoneOutOfLocal(i);
            Matrix4x4 mat = Matrix4x4::IDENTITY;
            Matrix4x4::MatrixMultiply(&mat, &inverseWorld, &world);
            m_testMaterial->SetMatrix4x4Uniform(Stringf("gBoneMatrices[%i]", i).c_str(), mat, NUM_BONES);
        }
    }

    m_currentMaterial->SetMatrices(model, view, proj);
    GL_CHECK_ERROR();
    loadedMesh->m_material = m_currentMaterial;
    loadedMesh->Render();
}
예제 #2
0
//-----------------------------------------------------------------------------------------------
void Update()
{
	static double s_timeLastFrameStarted = GetCurrentTimeSeconds();
	double timeNow = GetCurrentTimeSeconds();
	float deltaSeconds = (float)( timeNow - s_timeLastFrameStarted );
	s_timeLastFrameStarted = timeNow;

	TheGame::instance->Update( deltaSeconds );
}
예제 #3
0
//-----------------------------------------------------------------------------------------------
void WaitUntilNextFrameTime()
{
	double timeNow = GetCurrentTimeSeconds();
	static double targetTime = timeNow;
	while( timeNow < targetTime )
	{
		timeNow = GetCurrentTimeSeconds();
	}
	targetTime = timeNow + FRAME_TIME_SECONDS;
}
예제 #4
0
//-----------------------------------------------------------------------------------------------
double WaitUntilNextFrameThenGiveFrameTime()
{
	static double targetTime = 0.0;
	double timeNow = GetCurrentTimeSeconds();

	while( timeNow < targetTime )
	{
		timeNow = GetCurrentTimeSeconds();
	}
	targetTime = timeNow + LOCKED_FRAME_RATE_SECONDS;

	return LOCKED_FRAME_RATE_SECONDS;
}
예제 #5
0
void Chunk::update()
{
	if(m_timeSinceLastUpdate <= 0)
	{
		grassUpdate();
		pumpkinGenerate();
	}
	else
		m_timeSinceLastUpdate -= GetCurrentTimeSeconds();
}
예제 #6
0
//-----------------------------------------------------------------------------------
void TheGame::Update(float deltaTime)
{
    DebugRenderer::instance->Update(deltaTime);
    if (InputSystem::instance->WasKeyJustPressed(InputSystem::ExtraKeys::TILDE))
    {
        Console::instance->ActivateConsole();
    }

    if (Console::instance->IsActive())
    {
        return; //Don't do anything involving input updates.
    }

    UpdateCamera(deltaTime);
    for (int i = 0; i < 16; i++)
    {
        m_lightPositions[i] = Vector3(sinf(static_cast<float>(GetCurrentTimeSeconds() + i)) * 5.0f, cosf(static_cast<float>(GetCurrentTimeSeconds() + i) / 2.0f) * 3.0f, 0.5f);
        m_lights[i].SetPosition(m_lightPositions[i]);
        m_currentMaterial->m_shaderProgram->SetVec3Uniform(Stringf("gLightPosition[%i]", i).c_str(), m_lightPositions[i], 16);
    }
    
    if (InputSystem::instance->WasKeyJustPressed('O'))
    {
        m_renderAxisLines = !m_renderAxisLines;
    }
    if (InputSystem::instance->WasKeyJustPressed('1'))
    {
        MeshBuilder builder;
        MeshBuilder::PlaneData* data = new MeshBuilder::PlaneData(Vector3::ZERO, Vector3::RIGHT, Vector3::UP);
        builder.BuildPatch(-5.0f, 5.0f, 50, -5.0f, 5.0f, 50,
            [](const void* userData, float x, float y)
        {
            MeshBuilder::PlaneData const *plane = (MeshBuilder::PlaneData const*)userData;
            Vector3 position = plane->initialPosition
                + (plane->right * x)
                + (plane->up * y);
            return position;
        }
        , data);
        builder.CopyToMesh(loadedMesh->m_mesh, &Vertex_SkinnedPCTN::Copy, sizeof(Vertex_SkinnedPCTN), &Vertex_SkinnedPCTN::BindMeshToVAO);
        spinFactor = 0.0f;
    }
    if (InputSystem::instance->WasKeyJustPressed('2'))
    {
        MeshBuilder builder;
        MeshBuilder::PlaneData* data = new MeshBuilder::PlaneData(Vector3::ZERO, Vector3::RIGHT, Vector3::UP);
        builder.BuildPatch(-5.0f, 5.0f, 50, -5.0f, 5.0f, 50,
            [](const void* userData, float x, float y)
            {
                MeshBuilder::PlaneData const *plane = (MeshBuilder::PlaneData const*)userData;
                Vector3 position = plane->initialPosition
                    + (plane->right * x)
                    + (plane->up * y);
                position.z = sin(x + y);
                return position;
            }
        , data);
        builder.CopyToMesh(loadedMesh->m_mesh, &Vertex_SkinnedPCTN::Copy, sizeof(Vertex_SkinnedPCTN), &Vertex_SkinnedPCTN::BindMeshToVAO);
        spinFactor = 0.0f;
    }
    if (InputSystem::instance->WasKeyJustPressed('3'))
    {
        MeshBuilder builder;
        MeshBuilder::PlaneData* data = new MeshBuilder::PlaneData(Vector3::ZERO, Vector3::RIGHT, Vector3::UP);
        builder.BuildPatch(-5.0f, 5.0f, 50, -5.0f, 5.0f, 50,
            [](const void* userData, float x, float y)
        {
            MeshBuilder::PlaneData const *plane = (MeshBuilder::PlaneData const*)userData;
            Vector3 position = plane->initialPosition
                + (plane->right * x)
                + (plane->up * y);
            position.z = .05f * -cos(((float)GetCurrentTimeSeconds() * 4.0f) + (Vector2(x, y).CalculateMagnitude() * 100.0f));
            return position;
        }
        , data);
        builder.CopyToMesh(loadedMesh->m_mesh, &Vertex_SkinnedPCTN::Copy, sizeof(Vertex_SkinnedPCTN), &Vertex_SkinnedPCTN::BindMeshToVAO);
        spinFactor = 0.0f;
    }
    if (InputSystem::instance->WasKeyJustPressed('4'))
    {
        FbxListScene("Data/FBX/SampleBox.fbx");
    }
    if (InputSystem::instance->WasKeyJustPressed('5'))
    {
        Console::instance->RunCommand("fbxLoad Data/FBX/unitychan.fbx");
    }
    if (InputSystem::instance->WasKeyJustPressed('6'))
    {
        Console::instance->RunCommand("fbxLoad Data/FBX/samplebox.fbx");
    }
    if (InputSystem::instance->WasKeyJustPressed('7'))
    {
        Console::instance->RunCommand("saveMesh saveFile.picomesh");
    }
    if (InputSystem::instance->WasKeyJustPressed('8'))
    {
        Console::instance->RunCommand("loadMesh saveFile.picomesh");
    }
    if (g_loadedMesh != nullptr)
    {
        loadedMesh->m_mesh = g_loadedMesh;
    }
    if (InputSystem::instance->WasKeyJustPressed('B'))
    {
        m_currentMaterial = m_testMaterial;
    }
    else if (InputSystem::instance->WasKeyJustPressed('N'))
    {
        m_currentMaterial = m_normalDebugMaterial;
    }
    else if (InputSystem::instance->WasKeyJustPressed('U'))
    {
        m_currentMaterial = m_uvDebugMaterial;
    }
    if(InputSystem::instance->WasKeyJustPressed('K'))
    {
        m_showSkeleton = !m_showSkeleton;
    }
    if (InputSystem::instance->WasKeyJustPressed('I') && g_loadedMotion != nullptr)
    {
        g_loadedMotion->m_playbackMode = AnimationMotion::CLAMP;
    }
    else if (InputSystem::instance->WasKeyJustPressed('L') && g_loadedMotion != nullptr)
    {
        g_loadedMotion->m_playbackMode = AnimationMotion::LOOP;
    }
    else if (InputSystem::instance->WasKeyJustPressed('P') && g_loadedMotion != nullptr)
    {
        g_loadedMotion->m_playbackMode = AnimationMotion::PING_PONG;
    }
    else if (InputSystem::instance->WasKeyJustPressed('O') && g_loadedMotion != nullptr)
    {
        g_loadedMotion->m_playbackMode = AnimationMotion::PAUSED;
    }

    quadForFBO->m_material->SetFloatUniform("gTime", (float)GetCurrentTimeSeconds());
}
예제 #7
0
//-----------------------------------------------------------------------------------
void TheGame::Render() const
{
    ENSURE_NO_MATRIX_STACK_SIDE_EFFECTS(Renderer::instance->m_viewStack);
    ENSURE_NO_MATRIX_STACK_SIDE_EFFECTS(Renderer::instance->m_projStack);
    Begin3DPerspective();
    RenderCoolStuff();
    RenderAxisLines();
    if (g_loadedSkeleton && m_showSkeleton)
    {
        if (g_loadedMotion)
        {
            BoneMask TotalMask = BoneMask(g_loadedSkeleton->GetJointCount());
            TotalMask.SetAllBonesTo(1.0f);
            g_loadedMotion->ApplyMotionToSkeleton(g_loadedSkeleton, (float)GetCurrentTimeSeconds(), TotalMask);
            if (g_loadedSkeleton->m_joints)
            {
                delete g_loadedSkeleton->m_joints->m_mesh;
                delete g_loadedSkeleton->m_joints->m_material;
                delete g_loadedSkeleton->m_joints;
                g_loadedSkeleton->m_joints = nullptr;
            }
            if (g_loadedSkeleton->m_bones)
            {
                delete g_loadedSkeleton->m_bones->m_mesh;
                delete g_loadedSkeleton->m_bones->m_material;
                delete g_loadedSkeleton->m_bones;
                g_loadedSkeleton->m_bones = nullptr;
            }
        }
        else if (g_loadedMotions)
        {
            BoneMask upperHalfMask = BoneMask(g_loadedSkeleton->GetJointCount());
            upperHalfMask.SetAllBonesTo(1.0f);
            for (int i = 0; i < 9; ++i)
            {
                upperHalfMask.boneMasks[i] = 0.0f;
            }
            BoneMask lowerHalfMask = BoneMask(g_loadedSkeleton->GetJointCount());
            lowerHalfMask.SetAllBonesTo(0.0f);
            for (int i = 0; i < 9; ++i)
            {
                lowerHalfMask.boneMasks[i] = 1.0f;
            }
            g_loadedMotions->at(0)->ApplyMotionToSkeleton(g_loadedSkeleton, (float)GetCurrentTimeSeconds(), upperHalfMask);
            g_loadedMotions->at(1)->ApplyMotionToSkeleton(g_loadedSkeleton, (float)GetCurrentTimeSeconds(), lowerHalfMask);
            if (g_loadedSkeleton->m_joints)
            {
                delete g_loadedSkeleton->m_joints->m_mesh;
                delete g_loadedSkeleton->m_joints->m_material;
                delete g_loadedSkeleton->m_joints;
                g_loadedSkeleton->m_joints = nullptr;
            }
            if (g_loadedSkeleton->m_bones)
            {
                delete g_loadedSkeleton->m_bones->m_mesh;
                delete g_loadedSkeleton->m_bones->m_material;
                delete g_loadedSkeleton->m_bones;
                g_loadedSkeleton->m_bones = nullptr;
            }
        }
        g_loadedSkeleton->Render();
    }
    End3DPerspective();
    Console::instance->Render();
}
	TouchPoint( int sysTouchID, float touchX, float touchY, TouchType touchType = TOUCH_None )
		: type( touchType )
		, systemTouchID( sysTouchID )
		, location( touchX, touchY )
		, startTime( GetCurrentTimeSeconds() )
	{ }