コード例 #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
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();
}
コード例 #3
0
ファイル: angularSpring.cpp プロジェクト: nhoughto5/csc578BA1
angularSpring::angularSpring():
	anchorPosition{ 0.0f, 0.0f, 0.0f }, //Where the spring is anchored to
	displacement{ 0.0f, 0.0f, 0.0f },
	stretch{ 0.02f }, //How far the nodes seperate
	springWidth{ 0.05f }, //How close the node get to the spring axis
	mVelocity(0.0f),
	k(5.00f), //Spring Constant
	mMass(0.01f),
	angleDegrees(180.0f),
	period(1.25f)
{
	USING_ATLAS_GL_NS; 
	USING_ATLAS_MATH_NS;
	glGenVertexArrays(1, &mVertexArrayObject);
	glBindVertexArray(mVertexArrayObject);
	
	//Create the shape data object
	mSpringMass = ObjectGenerator::makeAngularSpringMass(anchorPosition, springWidth, stretch, massWidth, massHeight, angleDegrees);
	//Store a local copy of the conneciton point between the end of the spring and the top of the mass
	connectionPoint = mSpringMass.getConnectionPoint(); 
	//Keep a local copy of the number of indices so the clean up function can be used
	//And the number of vertices is not lost
	numSpringIndices2 = mSpringMass.numIndices; 

	//Create the buffers for the vertices and color information 
	glGenBuffers(1, &mVertexBufferObject);
	glBindBuffer(GL_ARRAY_BUFFER, mVertexBufferObject);
	glBufferData(GL_ARRAY_BUFFER, mSpringMass.vertexBufferSize(), NULL, GL_DYNAMIC_DRAW);
	glEnableVertexAttribArray(0);
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, VERTEX_BYTE_SIZE, 0);
	glEnableVertexAttribArray(1);
	glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, VERTEX_BYTE_SIZE, (char*)(sizeof(float) * 3));

	//Generate the indices buffer and bind to the GL_ELEMENT_ARRAY_BUFFER binding point.
	glGenBuffers(1, &springIndexBufferID);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, springIndexBufferID);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, mSpringMass.indexBufferSize(), mSpringMass.indices, GL_DYNAMIC_DRAW);
	// Get the path where our shaders are stored.
	std::string shaderDir = generated::ShaderPaths::getShaderDirectory();

	// Now set up the information for our shaders.
	std::vector<ShaderInfo> shaders
	{
		ShaderInfo{ GL_VERTEX_SHADER, shaderDir + "angularSpring.vs.glsl" },
		ShaderInfo{ GL_FRAGMENT_SHADER, shaderDir + "angularSpring.fs.glsl" }
	};
	// Create a new shader and add it to our list.
	mShaders.push_back(ShaderPointer(new Shader));
	mShaders[0]->compileShaders(shaders);
	mShaders[0]->linkShaders();
	mShaders[0]->disableShaders();
	mSpringMass.cleanup(); //Prevent memory leakage
}
コード例 #4
0
ファイル: Structure.cpp プロジェクト: nhoughto5/csc578BA2
Structure::Structure() {
	USING_ATLAS_GL_NS;

	glGenVertexArrays(1, &mVao);
	glBindVertexArray(mVao);
	GLfloat height = 0.5f, width = 0.9f, verticalHeight = 0.1f;
	GLfloat vertices[6][2] = {
		//Horizontal bar
		{ -width, height },
		{ width, height},

		//Left Vertical
		{ -width, height + verticalHeight },
		{ -width, height - verticalHeight},

		//Right Vertical
		{ width, height + verticalHeight },
		{ width, height - verticalHeight },
	};

	glGenBuffers(1, &mBuffer);
	glBindBuffer(GL_ARRAY_BUFFER, mBuffer);
	glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

	// Get the path where our shaders are stored.
	std::string shaderDir = generated::ShaderPaths::getShaderDirectory();

	// Now set up the information for our shaders.
	std::vector<ShaderInfo> shaders
	{
		ShaderInfo{ GL_VERTEX_SHADER, shaderDir + "structure.vs.glsl" },
		ShaderInfo{ GL_FRAGMENT_SHADER, shaderDir + "structure.fs.glsl" }
	};

	// Create a new shader and add it to our list.
	mShaders.push_back(ShaderPointer(new Shader));

	// Compile the shaders.
	mShaders[0]->compileShaders(shaders);

	// And link them.
	mShaders[0]->linkShaders();

	glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, (void*)0);
	glEnableVertexAttribArray(0);

	// Disable at the end to avoid mixing shaders.
	mShaders[0]->disableShaders();

}
コード例 #5
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();
}
コード例 #6
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;
}
コード例 #7
0
ファイル: CannonBall.cpp プロジェクト: nhoughto5/csc578BA1
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();
}