Esempio n. 1
0
void LikertHCI::draw(int threadId, MinVR::AbstractCameraRef camera, MinVR::WindowRef window)
{
	_shader->use();
	MinVR::CameraOffAxis* offAxisCam = dynamic_cast<MinVR::CameraOffAxis*>(camera.get());

	_shader->setUniform("projection_mat", offAxisCam->getLastAppliedProjectionMatrix());
	_shader->setUniform("view_mat", offAxisCam->getLastAppliedViewMatrix());
	_shader->setUniform("model_mat", offAxisCamera->getLastAppliedModelMatrix());
	//_shader->setUniform("normal_matrix", (glm::dmat3(offAxisCamera->getLastAppliedModelMatrix())));
	
	_shader->setUniform("textureSampler",0);

    //question on the upper part of the screen
    glm::dvec3 normal(0.0, 1.0, 0.0);
    glm::dvec3 right(1.0, 0.0, 0.0);



    drawText(threadId, "QuestionText_", _questions, _questionSizes, _currentQuestion, offAxisCam, glm::dvec3(0.0, 0.0, -0.5), normal, right, _questionHeights[_currentQuestion]);

    glm::dvec3 start(offAxisCam->getBottomLeft().x + _padding + _individualSize/2.0, 0.0, 0.5);
    glm::dvec3 spacing(_individualSize, 0.0, 0.0);

	glm::ivec2 range = _answerRanges[_currentQuestion];
	int count = 0;
	for(int i=range.x; i <= range.y; i++) {
        drawText(threadId, "AnswerText_", _answers, _answerSizes, i, offAxisCam, start + (double)count * spacing, normal, right, _answerHeights[i]);
		count++;
    }
}
Esempio n. 2
0
void ExampleVrApp::drawGraphics(int threadId, MinVR::AbstractCameraRef camera,
		MinVR::WindowRef window) {
	GLenum err;
	while((err = glGetError()) != GL_NO_ERROR) {
		std::cout << "GLERROR: "<<err<<std::endl;
	}

	glBindBufferARB(GL_ARRAY_BUFFER_ARB, _vboId[threadId]);

    // enable vertex arrays
    glEnableClientState(GL_NORMAL_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);
    glEnableClientState(GL_VERTEX_ARRAY);

    // before draw, specify vertex and index arrays with their offsets
    glNormalPointer(GL_FLOAT, 0, (void*)(sizeof(GLfloat)*108));
    glColorPointer(3, GL_FLOAT, 0, (void*)((sizeof(GLfloat)*108)+(sizeof(GLfloat)*108)));
    glVertexPointer(3, GL_FLOAT, 0, 0);

	glm::dmat4 translate = glm::translate(glm::dmat4(1.0f), glm::dvec3(0.0f, 0.0f, -5.0f));
	glm::dvec2 rotAngles(-20.0, 45.0);
	glm::dmat4 rotate1 = glm::rotate(translate, rotAngles.y, glm::dvec3(0.0,1.0,0.0));
	camera->setObjectToWorldMatrix(glm::rotate(rotate1, rotAngles.x, glm::dvec3(1.0,0,0)));
	glDrawArrays(GL_TRIANGLES, 0, 36);

    glDisableClientState(GL_VERTEX_ARRAY);  // disable vertex arrays
    glDisableClientState(GL_COLOR_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);

    glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);

	/*
	camera->setObjectToWorldMatrix(glm::mat4(1.0));
	glBegin(GL_TRIANGLES);
	glColor3f(1.f, 0.f, 0.f);
	glVertex3f(-0.3f, -0.2f, -1.f);
	glColor3f(0.f, 1.0f, 0.f);
	glVertex3f(0.3f, -0.2f, -1.0f);
	glColor3f(0.f, 0.f, 1.f);
	glVertex3f(0.f, 0.3f, -1.f);
	glEnd();
	*/
}
// transMat really means a transform, given by ExperimentMgr
void Tetrahedron::draw(int threadId, MinVR::AbstractCameraRef camera, MinVR::WindowRef window, std::string textureName, glm::dmat4 transMat, std::string color1, std::string color2, std::string color3, std::string color4, std::string color5){
	
	const int numCylinderIndices = (int)(cylinderMesh->getFilledIndexByteSize()/sizeof(int));
	const int numSphereIndices = (int)(sphereMesh->getFilledIndexByteSize()/sizeof(int));

	tetraShader->use();
	tetraShader->setUniform("projection_mat", offAxisCamera->getLastAppliedProjectionMatrix());
	tetraShader->setUniform("view_mat", offAxisCamera->getLastAppliedViewMatrix());

	//glm::dvec3 eye_world = glm::dvec3(glm::column(glm::inverse(offAxisCamera->getLastAppliedViewMatrix()), 3));
	//tetraShader->setUniform("eye_world", eye_world);
	
	

	///////////////////////////////
	// Binding Textures			 //
	///////////////////////////////
	texMan->getTexture(threadId, textureName)->bind(6);
	texMan->getTexture(threadId, color1)->bind(7);
	texMan->getTexture(threadId, color2)->bind(8);
	texMan->getTexture(threadId, color3)->bind(9);
	texMan->getTexture(threadId, color4)->bind(10);
	texMan->getTexture(threadId, color5)->bind(11);

	tetraShader->setUniform("textureSampler", 6);

	////////////////////////
	// static tetrahedron //
	////////////////////////
	glBindVertexArray(cylinderMesh->getVAOID());
	//glm::dmat4 tetraPosition = glm::translate(glm::dmat4(1.0),glm::dvec3(0.0, 0.0, 0.0));
	camera->setObjectToWorldMatrix(glm::dmat4(1.0)); // center it at origin
	tetraShader->setUniform("model_mat", offAxisCamera->getLastAppliedModelMatrix());
	tetraShader->setUniform("textureSampler", 6);
	for(int c = 0; c < 6 ; c++) {
		//std::cout << "The indexes for drawing: " << c * GPUCylinderOffset << ", " << (c+1) * GPUCylinderOffset << std::endl;
		//std::cout << 0 << ", " << numCylinderIndices << std::endl;
		if (c > 3) {
			tetraShader->setUniform("textureSampler", 11);
		}
		glDrawArrays(GL_TRIANGLE_STRIP, c*GPUCylinderOffset, GPUCylinderOffset);
	}

	///////////////////////////////
	// transformable tetrahedron //
	///////////////////////////////
	camera->setObjectToWorldMatrix(cFrameMgr->getVirtualToRoomSpaceFrame());
	tetraShader->setUniform("model_mat", offAxisCamera->getLastAppliedModelMatrix()*transMat);
	tetraShader->setUniform("textureSampler", 6);
    for(int c = 0; c < numTetraEdges ; c++) {
		//std::cout << "The indexes for drawing: " << c * GPUCylinderOffset << ", " << (c+1) * GPUCylinderOffset << std::endl;
		//std::cout << 0 << ", " << numCylinderIndices << std::endl;
		if (c > 3) {
			tetraShader->setUniform("textureSampler", 11);
		}
		
		glDrawArrays(GL_TRIANGLE_STRIP, c*GPUCylinderOffset, GPUCylinderOffset);
	}

	///////////////////////////////////////////
	// Draw Alignment Guide Cylinders        // //animates with transformable tetrahedron
	///////////////////////////////////////////

	// these are variables needed for these cylinders and the spheres below
	glm::dmat4 sphereTransMat1 = glm::translate(glm::dmat4(1.0), pointA);
	glm::dmat4 sphereTransMat2 = glm::translate(glm::dmat4(1.0), pointB);
	glm::dmat4 sphereTransMat3 = glm::translate(glm::dmat4(1.0), pointC);
	glm::dmat4 sphereTransMat4 = glm::translate(glm::dmat4(1.0), pointD);

	//cylinder VBO is still bound.

	glm::dmat4 cylinderAlignX = glm::rotate(glm::dmat4(1.0), 0.0, glm::dvec3(1.0, 0.0, 0.0));
	glm::dmat4 cylinderAlignY = glm::rotate(glm::dmat4(1.0), 90.0, glm::dvec3(0.0, 1.0, 0.0));
	glm::dmat4 cylinderAlignZ = glm::rotate(glm::dmat4(1.0), 90.0, glm::dvec3(0.0, 0.0, 1.0));


	// change numSphereIndices 
	// cylinders for point A
	tetraShader->setUniform("textureSampler", 7);
    tetraShader->setUniform("model_mat", sphereTransMat1 * cylinderAlignX);
    glDrawArrays(GL_TRIANGLE_STRIP, 6*GPUCylinderOffset, GPUCylinderOffset); // x
    tetraShader->setUniform("model_mat", sphereTransMat1 * cylinderAlignY);
    glDrawArrays(GL_TRIANGLE_STRIP, 6*GPUCylinderOffset, GPUCylinderOffset); // y
    tetraShader->setUniform("model_mat", sphereTransMat1 * cylinderAlignZ);
    glDrawArrays(GL_TRIANGLE_STRIP, 6*GPUCylinderOffset, GPUCylinderOffset); // z

	// cylinders for point B
	tetraShader->setUniform("textureSampler", 8);
    tetraShader->setUniform("model_mat", sphereTransMat2 * cylinderAlignX);
     glDrawArrays(GL_TRIANGLE_STRIP, 6*GPUCylinderOffset, GPUCylinderOffset); // x
    tetraShader->setUniform("model_mat", sphereTransMat2 * cylinderAlignY);
     glDrawArrays(GL_TRIANGLE_STRIP, 6*GPUCylinderOffset, GPUCylinderOffset); // y
    tetraShader->setUniform("model_mat", sphereTransMat2 * cylinderAlignZ);
     glDrawArrays(GL_TRIANGLE_STRIP, 6*GPUCylinderOffset, GPUCylinderOffset); // z

	// cylinders for point C
	tetraShader->setUniform("textureSampler", 9);
    tetraShader->setUniform("model_mat", sphereTransMat3 * cylinderAlignX);
     glDrawArrays(GL_TRIANGLE_STRIP, 6*GPUCylinderOffset, GPUCylinderOffset); // x
    tetraShader->setUniform("model_mat", sphereTransMat3 * cylinderAlignY);
     glDrawArrays(GL_TRIANGLE_STRIP, 6*GPUCylinderOffset, GPUCylinderOffset); // y
    tetraShader->setUniform("model_mat", sphereTransMat3 * cylinderAlignZ);
     glDrawArrays(GL_TRIANGLE_STRIP, 6*GPUCylinderOffset, GPUCylinderOffset); // z

	// cylinders for point D
	tetraShader->setUniform("textureSampler", 10);
    tetraShader->setUniform("model_mat", sphereTransMat4 * cylinderAlignX);
     glDrawArrays(GL_TRIANGLE_STRIP, 6*GPUCylinderOffset, GPUCylinderOffset); // x
    tetraShader->setUniform("model_mat", sphereTransMat4 * cylinderAlignY);
     glDrawArrays(GL_TRIANGLE_STRIP, 6*GPUCylinderOffset, GPUCylinderOffset); // y
    tetraShader->setUniform("model_mat", sphereTransMat4 * cylinderAlignZ);
     glDrawArrays(GL_TRIANGLE_STRIP, 6*GPUCylinderOffset, GPUCylinderOffset); // z

	///////////////////////////////////////////
	// Draw Static      Tetrahedron spheres  //
	///////////////////////////////////////////
	glBindVertexArray(sphereMesh->getVAOID());

	tetraShader->setUniform("textureSampler", 7);
	tetraShader->setUniform("model_mat", sphereTransMat1);
	glDrawArrays(GL_TRIANGLE_STRIP, 0, numSphereIndices);

	tetraShader->setUniform("textureSampler", 8);
	tetraShader->setUniform("model_mat", sphereTransMat2);
	glDrawArrays(GL_TRIANGLE_STRIP, 0, numSphereIndices);

	
	tetraShader->setUniform("textureSampler", 9);
	tetraShader->setUniform("model_mat", sphereTransMat3);
	glDrawArrays(GL_TRIANGLE_STRIP, 0, numSphereIndices);

	
	tetraShader->setUniform("textureSampler", 10);
	tetraShader->setUniform("model_mat", sphereTransMat4);
	glDrawArrays(GL_TRIANGLE_STRIP, 0, numSphereIndices);

	///////////////////////////////////////////
	// Draw Transformed Tetrahedron spheres  //
	///////////////////////////////////////////
	tetraShader->setUniform("textureSampler", 7);
	tetraShader->setUniform("model_mat", offAxisCamera->getLastAppliedModelMatrix() * transMat * sphereTransMat1);
	glDrawArrays(GL_TRIANGLE_STRIP, 0, numSphereIndices);

	
	tetraShader->setUniform("textureSampler", 8);
	tetraShader->setUniform("model_mat", offAxisCamera->getLastAppliedModelMatrix()* transMat * sphereTransMat2);
	glDrawArrays(GL_TRIANGLE_STRIP, 0, numSphereIndices);

	
	tetraShader->setUniform("textureSampler", 9);
	tetraShader->setUniform("model_mat", offAxisCamera->getLastAppliedModelMatrix()* transMat * sphereTransMat3);
	glDrawArrays(GL_TRIANGLE_STRIP, 0, numSphereIndices);

	
	tetraShader->setUniform("textureSampler", 10);
	tetraShader->setUniform("model_mat", offAxisCamera->getLastAppliedModelMatrix()* transMat * sphereTransMat4);
	glDrawArrays(GL_TRIANGLE_STRIP, 0, numSphereIndices);

	
	
	// 4 spheres
	//for (int t = 0; t < 4; t++) {
	//	glm::dmat4 sphereTransMat1 = glm::translate(glm::dmat4(1.0), pointA);
	//	//tetraShader->setUniform("model_mat", offAxisCamera->getLastAppliedModelMatrix()*sphereTransMat1);
	//	glDrawArrays(GL_TRIANGLES, 0, numSphereIndices);
	//} 
}
Esempio n. 4
0
void Feedback::draw(int threadId, MinVR::AbstractCameraRef camera, MinVR::WindowRef window) {

    //turn on blending
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    shader->use();
    shader->setUniform("projection_mat", offAxisCamera->getLastAppliedProjectionMatrix());
    shader->setUniform("view_mat", offAxisCamera->getLastAppliedViewMatrix());

    const int numQuadIndices = (int)(quadMesh->getFilledIndexByteSize()/sizeof(int));
    const int numTouchIndices = (int)(touchMesh->getFilledIndexByteSize()/sizeof(int));
    const int numBetweenIndices = (int)(touchMesh->getFilledIndexByteSize()/sizeof(int));

    // if we are in some mode, displayText should be fine
    // displayText is modified through HCIs
    if (displayText != "") {


        //std::cout << "Display Text: " << displayText << std::endl;
        texMan->getTexture(threadId, displayText)->bind(1);
        shader->setUniform("textureSampler", 1);

        glm::dvec4 quadTranslate(0.0, 0.0, 0.0, 1.0);

        // draw text here, remember to mess with the shader with the alpha value
        glm::dmat4 quadAtCorner = glm::dmat4(1.0);
        quadAtCorner[3] = quadTranslate;
        camera->setObjectToWorldMatrix(quadAtCorner);
        shader->setUniform("model_mat", offAxisCamera->getLastAppliedModelMatrix());
        glBindVertexArray(quadMesh->getVAOID());
        glDrawArrays(GL_TRIANGLE_STRIP, 0, numQuadIndices);


    }

    if (displayText == "between") {

        texMan->getTexture(threadId, displayText)->bind(1);
        shader->setUniform("textureSampler", 1);

        glm::dvec4 quadTranslate(0.0, 1.0, 0.0, 1.0);

        // draw text here, remember to mess with the shader with the alpha value
        glm::dmat4 quadAtCorner = glm::dmat4(1.0);
        quadAtCorner[3] = quadTranslate;
        camera->setObjectToWorldMatrix(quadAtCorner);
        shader->setUniform("model_mat", offAxisCamera->getLastAppliedModelMatrix());
        glBindVertexArray(betweenMesh->getVAOID());
        glDrawArrays(GL_TRIANGLE_STRIP, 0, numBetweenIndices);

    }

    if (displayPractice) {
        texMan->getTexture(threadId, "practice")->bind(1);
        shader->setUniform("textureSampler", 1);

        glm::dvec4 quadTranslate(2.5, 0.0, 0.0, 1.0);

        // draw text here, remember to mess with the shader with the alpha value
        glm::dmat4 quadAtCorner = glm::dmat4(1.0);
        quadAtCorner[3] = quadTranslate;
        camera->setObjectToWorldMatrix(quadAtCorner);
        shader->setUniform("model_mat", offAxisCamera->getLastAppliedModelMatrix());
        glBindVertexArray(quadMesh->getVAOID());
        glDrawArrays(GL_TRIANGLE_STRIP, 0, numQuadIndices);
    }


    // draw the touch texture
    // somehow need the room position of the touch
    glBindVertexArray(touchMesh->getVAOID());
    texMan->getTexture(threadId, "touch2")->bind(2);
    shader->setUniform("textureSampler", 2);

    std::map<int, TouchDataRef>::iterator it;
    glm::dvec3 roomCoord;

    for(it = registeredTouchData.begin(); it != registeredTouchData.end(); ++it) {

        TouchDataRef event = it->second;
        roomCoord = event->getCurrRoomPos();

        // new matrix for each triangle
        camera->setObjectToWorldMatrix(glm::translate(glm::dmat4(1.0f), roomCoord));
        shader->setUniform("model_mat", offAxisCamera->getLastAppliedModelMatrix());

        // draw quad
        glDrawArrays(GL_TRIANGLE_STRIP, 0, numTouchIndices);
    }

    // draw center of rotation point for XZRotMode, if there is one.
    // logic controlled by the HCI

    // uses same VBO as touch
    if (centOfRot.x != DBL_MAX) {
        texMan->getTexture(threadId, "centOfRot")->bind(3);
        shader->setUniform("textureSampler", 3);
        camera->setObjectToWorldMatrix(glm::translate(glm::dmat4(1.0f), centOfRot));
        shader->setUniform("model_mat", offAxisCamera->getLastAppliedModelMatrix());

        // draw quad
        glDrawArrays(GL_TRIANGLE_STRIP, 0, numTouchIndices);
    }

    // turn off blending
    glBlendFunc(GL_ONE, GL_ZERO);
    glDisable(GL_BLEND);

}