예제 #1
0
파일: Spring.cpp 프로젝트: etcwilde/Springs
AngularSpring::AngularSpring() :
        mPaused(false),
        mLength(5.1f),
        mDampen(0.01f),
        mK(0.1f),
        mMass(1.1f),
        mRest(0.f, glm::radians(-20.f)),
        mVelocity(0.f),
        mPosition(0.f, glm::radians(45.f))
{
        USING_ATLAS_GL_NS;
        USING_ATLAS_CORE_NS;
        USING_ATLAS_MATH_NS;

        // Create Vertex Array object
        glGenVertexArrays(1, &mVao);
        glBindVertexArray(mVao);

        // Create Vertex buffer object
        glGenBuffers(1, &mVbo);
        glBindBuffer(GL_ARRAY_BUFFER, mVbo);

        const std::array<glm::vec3, 2> points
        {
                glm::vec3(0.f),
                glm::vec3(mLength, mPosition)
        };

        glBufferData(GL_ARRAY_BUFFER, 2 * sizeof(Vector), points.data(), GL_DYNAMIC_DRAW);

        // Create Shaders
        const std::string shader_dir = generated::ShaderPaths::getShaderDirectory();
        // The Angular vertex shader converts from spherical to Cartesian
        // coordinates
        std::vector<ShaderInfo> shaders
        {
                {GL_VERTEX_SHADER, shader_dir + "angular.vs.glsl"},
                {GL_FRAGMENT_SHADER, shader_dir + "grid.fs.glsl"}
        };

        mShaders.push_back(ShaderPointer(new Shader));
        mShaders[0]->compileShaders(shaders);
        mShaders[0]->linkShaders();

        // Uniform variables
        GLuint varID;
        varID = mShaders[0]->getUniformVariable("MVP");
        mUniforms.insert(UniformKey("MVP", varID));
        varID = mShaders[0]->getUniformVariable("color");
        mUniforms.insert(UniformKey("color", varID));

        // Set attribute pointer -- Position Vectors
        glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
        glEnableVertexAttribArray(0);
        glBindVertexArray(0); // Disconnect
        mShaders[0]->disableShaders();
}
예제 #2
0
파일: Spring.cpp 프로젝트: etcwilde/Springs
Spring::Spring() :
        mPoints({atlas::math::Vector(0, 10, 0), atlas::math::Vector(0, 6, 0)}),
        mVelocity({atlas::math::Vector(0.f), atlas::math::Vector(0.f)}),
        mForce({atlas::math::Vector(0.f), atlas::math::Vector(0.f)}),
        mMass({10.f, 10.f}),
        mLength(4.f),
        mDampen(0.15f),
        mK(4.f),
        mPaused(false)
{
        USING_ATLAS_GL_NS;
        USING_ATLAS_CORE_NS;
        USING_ATLAS_MATH_NS;

        // Create Vao
        glGenVertexArrays(1, &mVao);
        glBindVertexArray(mVao); // Use this vertex array object
        glGenBuffers(1, &mVbo);
        glBindBuffer(GL_ARRAY_BUFFER, mVbo); // Use this vertex buffer object
        glBufferData(GL_ARRAY_BUFFER, sizeof(Vector) * 2, mPoints.data(), GL_DYNAMIC_DRAW);

        // Create Shader Programs
        const std::string shader_dir = generated::ShaderPaths::getShaderDirectory();
        std::vector<ShaderInfo> shaders
        {
                { GL_VERTEX_SHADER, shader_dir + "grid.vs.glsl"},
                { GL_FRAGMENT_SHADER, shader_dir + "grid.fs.glsl"}
        };

        mShaders.push_back(ShaderPointer(new Shader));
        mShaders[0]->compileShaders(shaders);
        mShaders[0]->linkShaders();

        // Get uniform variables
        GLuint varID;
        varID = mShaders[0]->getUniformVariable("MVP");
        mUniforms.insert(UniformKey("MVP", varID));
        varID = mShaders[0]->getUniformVariable("color");
        mUniforms.insert(UniformKey("color", varID));

        // Set the attribute pointer
        glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
        glEnableVertexAttribArray(0);

        glBindVertexArray(0); // Disconnect the vertex array object
        mShaders[0]->disableShaders();
}
예제 #3
0
SplineManager::SplineManager(GLuint framesPerSpline_) :
	framesPerSpline(framesPerSpline_),
	mResolution(500),
	mCurrentFrame(0),
	mShowControlPoints(false),
	mShowCage(false),
	mShowSplinePoints(false),
	mShowSpline(false),
	mIsInterpolationDone(false),
	currentSpline(0)
{
	//Bezier
	mBasisMatrix = Matrix4(
		1.0f, 0.0f, 0.0f, 0.0f,
		-3.0f, 3.0f, 0.0f, 0.0f,
		3.0f, -6.0f, 3.0f, 0.0f,
		-1.0f, 3.0f, -3.0f, 1.0f);
	addSplines();

	float scale = 1.0f / mResolution;
	for (GLuint i = 0; i < mSplines.size(); ++i) {
		for (GLuint res = 0; res < mResolution + 1; ++res) {
			allSplinePoints.push_back(mSplines[i].evaluateSpline(scale * res));
			allSplinePoints.push_back(mSplines[i].getColour());
		}
		mSplines[i].generateArcLengthTable();
	}

	glGenBuffers(1, &mControlBuffer);
	glBindBuffer(GL_ARRAY_BUFFER, mControlBuffer);
	glBufferData(GL_ARRAY_BUFFER, sizeof(Point) * allControlPoints.size(), allControlPoints.data(), GL_STATIC_DRAW);

	glGenBuffers(1, &mSplineBuffer);
	glBindBuffer(GL_ARRAY_BUFFER, mSplineBuffer);
	glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec3) * allSplinePoints.size(), allSplinePoints.data(), GL_STATIC_DRAW);

	setUpVAOs();

	std::string shaderDir = generated::ShaderPaths::getShaderDirectory();
	std::vector<ShaderInfo> shaders
	{
		{ GL_VERTEX_SHADER, shaderDir + "spline.vs.glsl" },
		{ GL_FRAGMENT_SHADER, shaderDir + "spline.fs.glsl" }
	};

	mShaders.push_back(ShaderPointer(new Shader));
	mShaders[0]->compileShaders(shaders);
	mShaders[0]->linkShaders();

	GLuint var;
	var = mShaders[0]->getUniformVariable("uMVP");
	mUniforms.insert(UniformKey("uMVP", var));

	mShaders[0]->disableShaders();
}
예제 #4
0
파일: Grid.cpp 프로젝트: etcwilde/Springs
Grid::Grid() :
        mVertexCount(100)
{
        USING_ATLAS_GL_NS;
        USING_ATLAS_MATH_NS;

        mModel = Matrix4(1.f);
        glGenVertexArrays(1, &mVao);
        glBindVertexArray(mVao);
        glGenBuffers(1, &mVbo);
        glBindBuffer(GL_ARRAY_BUFFER, mVbo);
        Vector4* vertices = new Vector4[mVertexCount];
        size_t n = mVertexCount / 4;
        for(size_t i = 0; i < n; ++i)
        {
                vertices[4 * i]         = Vector4(-12.f + i, 0.f, -12.f    , 1.f);
                vertices[4 * i + 1]     = Vector4(-12.f + i, 0.f,  12.f    , 1.f);
                vertices[4 * i + 2]     = Vector4(-12.f    , 0.f, -12.f + i, 1.f);
                vertices[4 * i + 3]     = Vector4( 12.f    , 0.f, -12.f + i, 1.f);
        }
        glBufferData(GL_ARRAY_BUFFER, sizeof(Vector4) * mVertexCount, vertices, GL_STATIC_DRAW);
        const std::string ShaderDir = generated::ShaderPaths::getShaderDirectory();
        std::vector<ShaderInfo> shaders {
                { GL_VERTEX_SHADER, ShaderDir + "grid.vs.glsl"},
                { GL_FRAGMENT_SHADER, ShaderDir + "grid.fs.glsl"}
        };

        mShaders.push_back(ShaderPointer(new Shader));
        mShaders[0]->compileShaders(shaders);
        mShaders[0]->linkShaders();

        GLuint varID;
        varID = mShaders[0]->getUniformVariable("MVP");
        mUniforms.insert(UniformKey("MVP", varID));
        varID = mShaders[0]->getUniformVariable("color");
        mUniforms.insert(UniformKey("color", varID));
        glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
        glEnableVertexAttribArray(0);
        glBindVertexArray(0);
        mShaders[0]->disableShaders();
        delete[] vertices;
}
예제 #5
0
CannonBall::CannonBall() :
    mRefBall(1.0f),
    mModelBall(1.0f),
    mRefPosition(6, 1, 0),
    mModelVelocity(0),
    mModelPosition(-6, 1, 0),
    mModelOldPosition(-6, 1, 0),
    mForce(0, 0, 2),
    mMass(1.0f),
    mIntegrator(Integrator::VERLET)
{
    USING_ATLAS_MATH_NS;
    USING_ATLAS_GL_NS;

    // Set up the initial positions of the balls.
    mRefMatrix = glm::translate(Matrix4(1.0f), mRefPosition);
    mModel = glm::translate(Matrix4(1.0f), mModelPosition);

    std::string shaderDir = generated::ShaderPaths::getShaderDirectory();

    std::vector<ShaderInfo> shaders
    {
        { GL_VERTEX_SHADER, shaderDir + "ball.vs.glsl" },
        { GL_FRAGMENT_SHADER, shaderDir + "ball.fs.glsl" }
    };

    mShaders.push_back(ShaderPointer(new Shader));
    mShaders[0]->compileShaders(shaders);
    mShaders[0]->linkShaders();

    mUniforms.insert(UniformKey("mvpMat", 
        mShaders[0]->getUniformVariable("mvpMat")));

    mRefBall.createBuffers();
    mModelBall.createBuffers();

    mShaders[0]->disableShaders();
}