예제 #1
0
void MouseListener::handleEvent(const MinVR::EventRef& event,
		double synchronizedTime) {

	if (startsWith(event->getName(), "mouse_", 6))
	{
		if (event->getName() == "mouse_scroll")
		{
			handleClick(MouseButton::SCROLL, event->get2DData().y > 0, event->get2DData());
			return;
		}

		MinVR::WindowRef window = event->getWindow();
		glm::dvec2 res(window->getWidth(), window->getHeight());
		glm::dvec2 pos = event->get2DData() / res;

		if (event->getName() == "mouse_pointer")
		{
			handleMove(pos);
		}
		else
		{
			MouseButton button;
			if (stringCompare(event->getName(), "left", 10, 4))
			{
				button = LEFT;
			}
			else if (stringCompare(event->getName(), "middle", 10, 6))
			{
				button = MIDDLE;
			}
			else if (stringCompare(event->getName(), "right", 10, 5))
			{
				button = RIGHT;
			}

			if (stringCompare(event->getName(), "up", event->getName().size()-2, 2))
			{
				handleClick(button, false, pos);
			}
			else
			{
				handleClick(button, true, pos);
			}
		}
	}
}
예제 #2
0
void Feedback::initVBOB (int threadId, MinVR::WindowRef window, std::string textureStr, GPUMeshRef &mesh) {

    std::tr1::shared_ptr<Texture> texture = texMan->getTexture(threadId, textureStr);
    float texHeight = texture->getHeight();
    float texWidth = texture->getWidth();
    float windowHeight = window->getHeight();
    float windowWidth = window->getWidth();

    float texHeightScreen =  texHeight/windowHeight;
    float texWidthScreen = texWidth/windowWidth;

    glm::dvec3 quad = glm::abs(convertScreenToRoomCoordinates(glm::dvec2(texWidthScreen+0.5, texHeightScreen+0.5)));

    std::vector<int> quadIndices;
    std::vector<GPUMesh::Vertex> quadData;
    GPUMesh::Vertex quadVert;

    quadVert.position = glm::dvec3(-quad.x, 0.0, -quad.z);
    quadVert.normal = glm::dvec3(0.0, 1.0, 0.0);
    quadVert.texCoord0 = glm::dvec2(0.0, 1.0);
    quadData.push_back(quadVert);
    quadIndices.push_back(quadData.size()-1);

    quadVert.position = glm::dvec3(-quad.x, 0.0, quad.z);
    quadVert.texCoord0 = glm::dvec2(0.0, 0.0);
    quadData.push_back(quadVert);
    quadIndices.push_back(quadData.size()-1);

    quadVert.position = glm::dvec3(quad.x, 0.0, -quad.z);
    quadVert.texCoord0 = glm::dvec2(1.0, 1.0);
    quadData.push_back(quadVert);
    quadIndices.push_back(quadData.size()-1);


    quadVert.position = glm::dvec3(quad.x, 0.0, quad.z);
    quadVert.texCoord0 = glm::dvec2(1.0, 0.0);
    quadData.push_back(quadVert);
    quadIndices.push_back(quadData.size()-1);


    mesh.reset(new GPUMesh(GL_STATIC_DRAW, sizeof(GPUMesh::Vertex)*quadData.size(), sizeof(int)*quadIndices.size(),0,quadData,sizeof(int)*quadIndices.size(), &quadIndices[0]));



}
예제 #3
0
void LikertHCI::initializeText(int threadId, MinVR::WindowRef window)
{

	
	int fontNormal = FONS_INVALID;
	struct FONScontext* fs = nullptr;

	fs = glfonsCreate(512, 512, FONS_ZERO_TOPLEFT);
	if (fs == NULL) {
		BOOST_ASSERT_MSG(false, "Could not create stash.");
	}

	fontNormal = fonsAddFont(fs, "sans", MinVR::ConfigVal("RegularFontFile", "app/fonts/DroidSansMono.ttf", false).c_str());
	if (fontNormal == FONS_INVALID) {
		BOOST_ASSERT_MSG(false, "Could not add font normal.\n");
	}

	glUseProgram(0);
	glPushAttrib(GL_VIEWPORT_BIT | GL_ENABLE_BIT);

	GLuint textFBO;
	glGenFramebuffers(1, &textFBO);
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, textFBO);
	glDrawBuffer(GL_COLOR_ATTACHMENT0);

	std::map<std::string, std::string> dummyArgs;
	std::shared_ptr<GLSLProgram> shader(new GLSLProgram());
	shader->compileShader(MinVR::DataFileUtils::findDataFile("textRendering.vert").c_str(), GLSLShader::VERTEX, dummyArgs);
	shader->compileShader(MinVR::DataFileUtils::findDataFile("textRendering.frag").c_str(), GLSLShader::FRAGMENT, dummyArgs);
	shader->link();
	shader->use();

	glClearColor(1.0, 1.0, 1.0, 1.0);

	initializeText(threadId, fs, fontNormal, _maxNumLinesInQuestions, 20.0f, shader, 72.0f, _questions, "QuestionText_", _questionTextures, _questionSizes);

	initializeText(threadId, fs, fontNormal, _maxNumLinesInAnswers, 15.0f, shader, 35.0f, _answers, "AnswerText_", _answerTextures, _answerSizes);

	double windowHeight = window->getHeight();
	double windowWidth = window->getWidth();
	_padding = 0.05;
	double numAnswersPerQuestion = 7.0;
	_availableWidth = glm::length(offAxisCamera->getBottomRight() - offAxisCamera->getBottomLeft()) - (2*_padding);
	_individualSize = _availableWidth/ (numAnswersPerQuestion);
	glm::dvec3 start(offAxisCamera->getBottomLeft().x + _padding + _individualSize/2.0, 0.0, 0.5);
	glm::dvec3 spacing(_individualSize, 0.0, 0.0);
	for(int i=0; i < _answers.size(); i++) {
		double texHeight = _answerTextures[0][i]->getHeight(); // all answers are the same dimensions;
		double texWidth = _answerTextures[0][i]->getWidth();
		double quadHeightScreen =  texHeight/windowHeight;
		double quadWidthScreen = texWidth/windowWidth;
		glm::dvec3 quad = glm::abs(convertScreenToRoomCoordinates(glm::dvec2(quadWidthScreen+0.5, quadHeightScreen+0.5)));
		_answerHeights.push_back(quad.z);

		glm::dvec2 size = _answerSizes[threadId][i];
		double halfWidth = _answerHeights[i] * size.x / size.y / 2.0f;
		double halfHeight = _answerHeights[i] / 2.0f;
		glm::dvec3 centerPt = start+ (double)i*spacing;
		glm::dvec3 low(-halfWidth, -0.001, -halfHeight);
		glm::dvec3 high(halfWidth, 0.001, halfHeight);
		AABox bounds(start + (double)i*spacing + low, start + (double)i*spacing +high);
		_answerBounds.push_back(bounds);
		
	}

	for(int i=0; i < _questions.size(); i++) {
		double texHeight = _questionTextures[0][i]->getHeight(); // all answers are the same dimensions;
		double texWidth = _questionTextures[0][i]->getWidth();
		double quadHeightScreen =  texHeight/windowHeight;
		double quadWidthScreen = texWidth/windowWidth;
		glm::dvec3 quad = glm::abs(convertScreenToRoomCoordinates(glm::dvec2(quadWidthScreen+0.5, quadHeightScreen+0.5)));
		_questionHeights.push_back(quad.z);	
	}
	
	glfonsDelete(fs);
	glUseProgram(0);
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
	glDeleteFramebuffers(1, &textFBO);

	glPopAttrib(); // restore viewport and enabled bits

	glEnable(GL_TEXTURE_2D);
	// restore the clear color
	glm::dvec3 clearColor = MinVR::ConfigVal("ClearColor", glm::dvec3(0.1), false);
	glClearColor(clearColor.r, clearColor.g, clearColor.b, 1.0f);
}
예제 #4
0
void Feedback::initVBO(int threadId, MinVR::WindowRef window) {

    //initVBOB(threadId, window, "rotating", quadMesh); //
    initVBOB(threadId, window, "touch-smaller", touchMesh);
    initVBOB(threadId, window, "between", betweenMesh);
    //initVBOB(threadId, window, "centOfRot"); //
    //initVBOB(threadId, window, "vector");


    /////////////////////////////
    // VBO for displaying Text //
    /////////////////////////////
    std::vector<int> quadIndices;
    std::vector<GPUMesh::Vertex> quadData;
    GPUMesh::Vertex quadVert;

    float windowHeight = window->getHeight();
    float windowWidth = window->getWidth();
    float texHeight = texMan->getTexture(threadId, "rotating")->getHeight();
    float texWidth = texMan->getTexture(threadId, "rotating")->getWidth();
    float quadHeightScreen =  texHeight/windowHeight;
    float quadWidthScreen = texWidth/windowWidth;

    glm::dvec3 quad = glm::abs(convertScreenToRoomCoordinates(glm::dvec2(quadWidthScreen+0.5, quadHeightScreen+0.5)));

    //std::cout<<"quad: "<<glm::to_string(quad)<<std::endl;
    //std::cout<<"wind H: "<<windowHeight<<std::endl;
    //std::cout<<"wind W: "<<windowWidth<<std::endl;
    //std::cout<<"tex H: "<<texHeight<<std::endl;
    //std::cout<<"tex W: "<<texWidth<<std::endl;

    //std::cout << "quad Height Screen: " <<quadHeightScreen << std::endl;
    //std::cout << "quad W Screen: " << quadWidthScreen << std::endl;

    glm::dvec3 topleft = convertScreenToRoomCoordinates(glm::dvec2(0.1,0.9));
    //std::cout<<"topleft: "<<glm::to_string(topleft)<<std::endl;

    quadVert.position = glm::dvec3(topleft.x, 0.0, topleft.z);
    quadVert.normal = glm::dvec3(0.0, 1.0, 0.0);
    quadVert.texCoord0 = glm::dvec2(0.0, 1.0);
    quadData.push_back(quadVert);
    quadIndices.push_back(quadData.size()-1);

    quadVert.position = glm::dvec3(topleft.x, 0.0, topleft.z+quad.z);
    quadVert.texCoord0 = glm::dvec2(0.0, 0.0);
    quadData.push_back(quadVert);
    quadIndices.push_back(quadData.size()-1);

    quadVert.position = glm::dvec3(topleft.x+quad.x, 0.0, topleft.z);
    quadVert.texCoord0 = glm::dvec2(1.0, 1.0);
    quadData.push_back(quadVert);
    quadIndices.push_back(quadData.size()-1);


    quadVert.position = glm::dvec3(topleft.x+quad.x, 0.0, topleft.z+quad.z);
    quadVert.texCoord0 = glm::dvec2(1.0, 0.0);
    quadData.push_back(quadVert);
    quadIndices.push_back(quadData.size()-1);


    quadMesh.reset(new GPUMesh(GL_STATIC_DRAW, sizeof(GPUMesh::Vertex)*quadData.size(), sizeof(int)*quadIndices.size(),0,quadData,sizeof(int)*quadIndices.size(), &quadIndices[0]));



    //////////////////////////////
    //// VBO for Touch Feedback //
    //////////////////////////////
    //texHeight = texMan->getTexture(threadId, "touch")->getHeight();
    //texWidth = texMan->getTexture(threadId, "touch")->getWidth();
    //float touchHeightScreen =  texHeight/windowHeight;
    //float touchWidthScreen = texWidth/windowWidth;

    //glm::dvec3 touchQuad = glm::abs(convertScreenToRoomCoordinates(glm::dvec2(touchWidthScreen+0.5, touchHeightScreen+0.5)));

    //std::vector<int> touchIndices;
    //std::vector<GPUMesh::Vertex> touchData;
    //GPUMesh::Vertex touchVert;

    //touchVert.position = glm::dvec3(-touchQuad.x, 0.0, -touchQuad.z);
    //touchVert.normal = glm::dvec3(0.0, 1.0, 0.0);
    //touchVert.texCoord0 = glm::dvec2(0.0, 1.0);
    //touchData.push_back(touchVert);
    //touchIndices.push_back(touchData.size()-1);

    //touchVert.position = glm::dvec3(-touchQuad.x, 0.0, touchQuad.z);
    //touchVert.texCoord0 = glm::dvec2(0.0, 0.0);
    //touchData.push_back(touchVert);
    //touchIndices.push_back(touchData.size()-1);

    //touchVert.position = glm::dvec3(touchQuad.x, 0.0, -touchQuad.z);
    //touchVert.texCoord0 = glm::dvec2(1.0, 1.0);
    //touchData.push_back(touchVert);
    //touchIndices.push_back(touchData.size()-1);


    //touchVert.position = glm::dvec3(touchQuad.x, 0.0, touchQuad.z);
    //touchVert.texCoord0 = glm::dvec2(1.0, 0.0);
    //touchData.push_back(touchVert);
    //touchIndices.push_back(touchData.size()-1);


    //touchMesh.reset(new GPUMesh(GL_STATIC_DRAW, sizeof(GPUMesh::Vertex)*touchData.size(), sizeof(int)*touchIndices.size(),0,touchData,sizeof(int)*touchIndices.size(), &touchIndices[0]));

    //// vbo for centroid

    //// vbo for drawing vectors
}