Exemplo n.º 1
0
void QuaternionTest::Draw(ModelviewStack* ms)
{
    useTexture(0);
    setColour(1.0, 1.0, 1.0);

    ms->Push();
    {
        ms->Mult(mat4_cast(_orientation));
        ms->Translate(_transform.position);

        vec4 pos4 = mat4_cast(_orientation) * vec4(1.0, 1.0, 1.0, 1.0);

        drawCube(*ms);
    }
    ms->Pop();

    setColour(0.0, 0.0, 0.0);
    ms->Push();
    {
        ms->Scale(vec3(0.25f, 0.25f, 0.25f));
        drawSphere(*ms);
    }
    ms->Pop();
}
Exemplo n.º 2
0
void selectFace(int x, int y)
{
    GLuint selBuffer[BUFSIZE];
    GLint hits;
    glSelectBuffer(BUFSIZE, selBuffer);
    glRenderMode(GL_SELECT);

    glInitNames();
    glPushName(0);
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    gluPickMatrix((GLfloat) x, (GLfloat) (g_viewport[3] - y),
                  1.0, 1.0, g_viewport);
    gluPerspective(45.0, (GLfloat) g_viewport[2] / (GLfloat) g_viewport[3], 1.0, 300.0);
    drawCube();
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glFlush();

    hits = glRenderMode(GL_RENDER);
    processHits(hits, selBuffer);
    glutPostRedisplay();
}
Exemplo n.º 3
0
void glDisplay()
{
    GLdouble wx, wy, wz;
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    if (abs(g_angleY) >= 1e-06)
    {
        gluUnProject(g_winX, 0.0, g_winZ,
                     g_modelMatrix,
                     g_projMatrix,
                     g_viewport,
                     &wx, &wy, &wz);
	
        glRotatef(g_angleY, wx, wy, wz);
        glGetDoublev(GL_MODELVIEW_MATRIX, g_modelMatrix);
    }

    if (abs(g_angleX) >= 1e-06)
    {
        gluUnProject(0.0, g_winY, g_winZ,
                     g_modelMatrix,
                     g_projMatrix,
                     g_viewport,
                     &wx, &wy, &wz);
	
        glRotatef(g_angleX, wx, wy, wz);
        glGetDoublev(GL_MODELVIEW_MATRIX, g_modelMatrix);
    }

    g_angleX = 0.0;
    g_angleY = 0.0;

    glBindTexture(GL_TEXTURE_3D, texture[0]);
    drawCube();
    glutSwapBuffers();
}
Exemplo n.º 4
0
void drawTile(float x, float y, float z, float scale, int tile, float mx, float my, float mz, Image *image)
{
	UNREFERENCED_PARAMETER(image);
	UNREFERENCED_PARAMETER(mx);
	UNREFERENCED_PARAMETER(my);
	UNREFERENCED_PARAMETER(mx);
	UNREFERENCED_PARAMETER(mz);

	switch (tile) {

		case 1:
			drawCube(x,y,z,scale);
			//drawOcto(x,y,z,scale);
			//drawPoint(x,y,z,scale, mx, my, mz, image);
			break;
		case 2:
			drawPyramid(x,y,z);
			break;

	}



}
Exemplo n.º 5
0
void drawBulb(void)
{
	mvstack.push(model_view);
		set_colour(1.0f, 1.0f, 0.0f);
		drawSphere();

			mvstack.push(model_view);
				model_view *= Translate(0.0f, 2.0f, 0.0f);
				model_view *= Scale(0.25f, 1.0f, 0.25f);
				drawCube();
			model_view = mvstack.pop();

			mvstack.push(model_view);
				model_view *= RotateZ(45);
				model_view *= Translate(0.0f, 2.0f, 0.0f);
				model_view *= Scale(0.25f, 1.0f, 0.25f);
				drawCube();
			model_view = mvstack.pop();

			mvstack.push(model_view);
				model_view *= RotateZ(-45);
				model_view *= Translate(0.0f, 2.0f, 0.0f);
				model_view *= Scale(0.25f, 1.0f, 0.25f);
				drawCube();
			model_view = mvstack.pop();

			mvstack.push(model_view);
				model_view *= RotateZ(90);
				model_view *= Translate(0.0f, 2.0f, 0.0f);
				model_view *= Scale(0.25f, 1.0f, 0.25f);
				drawCube();
				model_view *= Translate(0.0f, -4.0f, 0.0f);
				drawCube();
			model_view = mvstack.pop();

		model_view *= Translate(0.0f, -1.0f, 0.0f);
		set_colour(0.5f, 0.5f, 0.5f);
		drawCube();
	model_view = mvstack.pop();
}
Exemplo n.º 6
0
void invRTSGame::selection(int height)
{
	if(pause_game || !picking_enable) return;

	mouse_over = NULL;

	// draw a black terrain
	if(draw_map)
	{
		glColor3ub(0, 0, 0);
		drawgrid->draw(fow, false);
		terrainPoint();
	}

	if(selection_unit) return;

	if(sinput->mousebutton == SDL_BUTTON_LEFT && sinput->mousestate == 1)
	{
		startMouseSelX = sinput->mousex;
		startMouseSelY = sinput->mousey;
		startAreaSelX = terrainX;
		startAreaSelZ = terrainZ;
		
		areaSel = true;
	}

	else if(sinput->mousebutton == SDL_BUTTON_LEFT && sinput->mousestate == 2)
	{
		startMouseSelX = endMouseSelX;
		startMouseSelY = endMouseSelY;
		endAreaSelX = terrainX;
		endAreaSelZ = terrainZ;
		areaSel = false;
	}

	if(areaSel)
	{
		endMouseSelX = sinput->mousex;
		endMouseSelY = sinput->mousey;
		endAreaSelX = terrainX;
		endAreaSelZ = terrainZ;
	}

	int deltaX = endMouseSelX - startMouseSelX;
	int deltaY = endMouseSelY - startMouseSelY;
	if(areaSel  && (deltaX * deltaY) > 5 * 5)
	{
		selectEntityInArea();
	}

	// TODO : Optimize this !!
	else{
		Uint8 limitcolor = 1;
		nb_selected = 0;

		entities.rewind();
		while(!entities.isEnd())
		{
			invEntity* e = entities.current();

			if(e->mdef->selectable)
			{
				glColor3ub(limitcolor++, 0, 0);
				// draw the box
				glPushMatrix();
				glTranslatef(e->pos.x, 0.f, e->pos.z);
				drawCube(e->mdef->bx, 2.5f, e->mdef->bz);
				glPopMatrix();
			}

			entities.next();
		}

		int selected_color = picking(sinput->mousex, height -  sinput->mousey);

		limitcolor = 1;
		entities.rewind();
		while(!entities.isEnd())
		{
			if(entities.current()->mdef->selectable && selected_color == limitcolor++)
			{
				nb_selected = 1;
				mouse_over = entities.current();
				break;
			}
			entities.next();
		}
		
		if(sinput->mousebutton == SDL_BUTTON_LEFT && sinput->mousestate == 1) {
			if(nb_selected)
			{
				nb_selectedl = 1;
				selectedl[0] = mouse_over;
			}
		}

		if(sinput->mousebutton == SDL_BUTTON_RIGHT && sinput->mousestate == 1) {
			nb_selectedr = nb_selected;
			if(nb_selectedr) selectedr = mouse_over;

			if(nb_selectedr)
			{
				lua_pushnumber(mainL, selectedr->id);
				lua_setglobal(mainL, "target_unit");
			}

			else
			{
				lua_pushnil(mainL);
				lua_setglobal(mainL, "target_unit");
			}
		}
	}

	// notice lua
	lua_pushnumber(mainL, nb_selectedl);
	lua_setglobal(mainL, "nb_selected");

	if(nb_selectedl)
	{
		lua_getglobal(mainL, "selected_units");
		for(int i=0;i<nb_selectedl;i++)
		{
			lua_pushnumber(mainL, i+1);
			lua_pushnumber(mainL, selectedl[i]->id);
			lua_rawset(mainL, -3);
		}
		lua_pop(mainL, 1);
	}

	
}
void right_hand(void){
	glColor3f(0.0, 0.0, 1.0);
	glTranslatef(0.0, -0.75, 0.0);
	glScalef(0.65, 0.3, 1.0);
	drawCube();
}
Exemplo n.º 8
0
JNIEXPORT void JNICALL JNIFUNCTION_NATIVE(nativeDrawFrame(JNIEnv* env, jobject obj))
{
	float width, height;
    float viewProjection[16];

    if (!videoInited) {
#ifdef DEBUG
        LOGI("nativeDrawFrame !VIDEO\n");
#endif        
        return; // No point in trying to draw until video is inited.
    }
#ifdef DEBUG
    LOGI("nativeDrawFrame\n");
#endif        
    if (!gARViewInited) {
        if (!initARView()) return;
    }
    if (gARViewLayoutRequired) layoutARView();
    
    // Upload new video frame if required.
    if (videoFrameNeedsPixelBufferDataUpload) {
        arglPixelBufferDataUploadBiPlanar(gArglSettings, gVideoFrame, gVideoFrame + videoWidth*videoHeight);
        videoFrameNeedsPixelBufferDataUpload = false;
    }
    
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear the buffers for new frame.
    
    // Display the current frame
    arglDispImage(gArglSettings);
    
    if (!program) {
        GLuint vertShader = 0, fragShader = 0;
        // A simple shader pair which accepts just a vertex position and colour, no lighting.
        const char vertShaderString[] =
            "attribute vec4 position;\n"
            "attribute vec4 colour;\n"
            "uniform mat4 modelViewProjectionMatrix;\n"
            "varying vec4 colourVarying;\n"
            "void main()\n"
            "{\n"
                "gl_Position = modelViewProjectionMatrix * position;\n"
                "colourVarying = colour;\n"
            "}\n";
        const char fragShaderString[] =
            "#ifdef GL_ES\n"
            "precision mediump float;\n"
            "#endif\n"
            "varying vec4 colourVarying;\n"
            "void main()\n"
            "{\n"
                "gl_FragColor = colourVarying;\n"
            "}\n";

        if (program) arglGLDestroyShaders(0, 0, program);
        program = glCreateProgram();
        if (!program) {
            ARLOGe("drawCube: Error creating shader program.\n");
            arglGLDestroyShaders(vertShader, fragShader, program);
            return;
        }

        if (!arglGLCompileShaderFromString(&vertShader, GL_VERTEX_SHADER, vertShaderString)) {
            ARLOGe("drawCube: Error compiling vertex shader.\n");
            arglGLDestroyShaders(vertShader, fragShader, program);
            return;
        }
        if (!arglGLCompileShaderFromString(&fragShader, GL_FRAGMENT_SHADER, fragShaderString)) {
            ARLOGe("drawCube: Error compiling fragment shader.\n");
            arglGLDestroyShaders(vertShader, fragShader, program);
            return;
        }
        glAttachShader(program, vertShader);
        glAttachShader(program, fragShader);

        glBindAttribLocation(program, ATTRIBUTE_VERTEX, "position");
        glBindAttribLocation(program, ATTRIBUTE_COLOUR, "colour");
        if (!arglGLLinkProgram(program)) {
            ARLOGe("drawCube: Error linking shader program.\n");
            arglGLDestroyShaders(vertShader, fragShader, program);
            return;
        }
        arglGLDestroyShaders(vertShader, fragShader, 0); // After linking, shader objects can be deleted.

        // Retrieve linked uniform locations.
        uniforms[UNIFORM_MODELVIEW_PROJECTION_MATRIX] = glGetUniformLocation(program, "modelViewProjectionMatrix");
    }
    glUseProgram(program);

    // Set up 3D mode.
    mtxLoadIdentityf(viewProjection);
    mtxMultMatrixf(viewProjection, cameraLens);
    glStateCacheEnableDepthTest();

    // Set any initial per-frame GL state you require here.
    // --->

    // Lighting and geometry that moves with the camera should be added here.
    // (I.e. should be specified before camera pose transform.)
    // --->

    // Draw an object on all valid markers.
    for (int i = 0; i < markersSquareCount; i++) {
        if (markersSquare[i].valid) {
        	float viewProjection2[16];
        	mtxLoadMatrixf(viewProjection2, viewProjection);
            mtxMultMatrixf(viewProjection2, markersSquare[i].pose.T);
            drawCube(viewProjection2, 40.0f, 0.0f, 0.0f, 20.0f);
        }
    }

    if (cameraPoseValid) {

        mtxMultMatrixf(viewProjection, cameraPose);

        // All lighting and geometry to be drawn in world coordinates goes here.
        // --->
    }

    // If you added external OpenGL code above, and that code doesn't use the glStateCache routines,
    // then uncomment the line below.
    //glStateCacheFlush();
    
    // Set up 2D mode.
    mtxLoadIdentityf(viewProjection);
	width = (float)viewPort[viewPortIndexWidth];
	height = (float)viewPort[viewPortIndexHeight];
	mtxOrthof(viewProjection, 0.0f, width, 0.0f, height, -1.0f, 1.0f);
    glStateCacheDisableDepthTest();

    // Add your own 2D overlays here.
    // --->

    // If you added external OpenGL code above, and that code doesn't use the glStateCache routines,
    // then uncomment the line below.
    //glStateCacheFlush();

#ifdef DEBUG
    // Example of 2D drawing. It just draws a white border line. Change the 0 to 1 to enable.
    const GLfloat square_vertices [4][3] = { {0.5f, 0.5f, 0.0f}, {0.5f, height - 0.5f, 0.0f}, {width - 0.5f, height - 0.5f, 0.0f}, {width - 0.5f, 0.5f, 0.0f} };
    const GLubyte square_vertex_colors_white [4][4] = {
        {255, 255, 255, 255}, {255, 255, 255, 255}, {255, 255, 255, 255}, {255, 255, 255, 255}};

    glUniformMatrix4fv(uniforms[UNIFORM_MODELVIEW_PROJECTION_MATRIX], 1, GL_FALSE, viewProjection);

 	glVertexAttribPointer(ATTRIBUTE_VERTEX, 3, GL_FLOAT, GL_FALSE, 0, square_vertices);
	glEnableVertexAttribArray(ATTRIBUTE_VERTEX);
	glVertexAttribPointer(ATTRIBUTE_COLOUR, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, square_vertex_colors_white);
    glEnableVertexAttribArray(ATTRIBUTE_COLOUR);

    if (!arglGLValidateProgram(program)) {
        ARLOGe("Error: shader program %d validation failed.\n", program);
        return;
    }

    glDrawArrays(GL_LINE_LOOP, 0, 4);
#endif

#ifdef DEBUG
    CHECK_GL_ERROR();
#endif
}
Exemplo n.º 9
0
void draw()
{
	cxt->clearScreen();
	// sh.enable(true);
	cam.control(elapsedTime);

	cam.reset();
    //glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient );
    //glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
	//glMaterialf(GL_FRONT, GL_SHININESS, shininess);
	cam.look();

	glEnable(GL_TEXTURE_2D);

	glColor3f(1.0f, 1.0f, 1.0f);

	glPushMatrix();
	glTranslatef(lightPos[0],lightPos[1],lightPos[2]);
	drawCube(0.5f);
	glPopMatrix();

	game.drawMap();
	glCullFace(GL_BACK);
	glEnable(GL_CULL_FACE);
	glEnable(GL_LIGHTING);
	game.drawEntities();
	glDisable(GL_LIGHTING);
	glDisable(GL_CULL_FACE);

	// sh.enable(false);

	game.drawQuads();

	glDisable(GL_TEXTURE_2D);
	cam.begin2d();

	glColor3f(1.f, 1.f, 1.f);

	if(sinput->keys[SDLK_F1])
		print_infos();
	
	if(game.areaSel)
	{
		glColor3f(1.f, 1.f, 1.f);
		glBegin(GL_LINE_STRIP);
		glVertex3i(game.startMouseSelX, game.startMouseSelY, -1.f);
		glVertex3i(game.endMouseSelX, game.startMouseSelY, -1.f);
		glVertex3i(game.endMouseSelX, game.endMouseSelY, -1.f);
		glVertex3i(game.startMouseSelX, game.endMouseSelY, -1.f);
		glVertex3i(game.startMouseSelX, game.startMouseSelY, -1.f);
		glEnd();
	}

	game.drawMinimap();
	game.draw2D();
	cam.end2d();

	if(!showPicking) cxt->flip();

	// print framerate
	if((cxt->secs() - before) >= 5.f)
	{
		printf("After 5s : %g FPS\n", frames/(cxt->secs()-before));
		frames = 0;
		before = cxt->secs();
	}
	else
		frames++;
}
Exemplo n.º 10
0
void GLWidget::paintGL()
{
    glPopMatrix(); // pop the matrix pushed in the pbuffer list

    // push the projection matrix and the entire GL state before
    // doing any rendering into our framebuffer object
    glPushAttrib(GL_ALL_ATTRIB_BITS);
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();

    glViewport(0, 0, fbo->size().width(), fbo->size().height());
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-1, 1, -1, 1, -99, 99);
    glTranslatef(-0.5f, -0.5f, 0.0f);
    glMatrixMode(GL_MODELVIEW);

    // render to the framebuffer object
    fbo->bind();
    glBindTexture(GL_TEXTURE_2D, cubeTexture);
    glCallList(pbufferList);
    fbo->release();

    // pop the projection matrix and GL state back for rendering
    // to the actual widget
    glPopAttrib();
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();

    glBindTexture(GL_TEXTURE_2D, fbo->texture());
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // draw the background
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();

    glVertexPointer(2, GL_INT, 0, faceArray);
    glTranslatef(-1.2f, -0.8f, 0.0f);
    glScalef(0.2f, 0.2f, 0.2f);
    for (int y = 0; y < 5; ++y) {
	for (int x = 0; x < 5; ++x) {
	    glTranslatef(2.0f, 0, 0);
	    glColor4f(0.8f, 0.8f, 0.8f, 1.0f);
	    glDrawArrays(GL_QUADS, 0, 4);
	}
 	glTranslatef(-10.0f, 2.0f, 0);
    }
    glVertexPointer(3, GL_INT, 0, cubeArray);

    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);

    // draw the bouncing cubes
    drawCube(0, 0.0f, 1.5f, 2.5f, 1.5f);
    drawCube(1, 1.0f, 2.0f, 2.5f, 2.0f);
    drawCube(2, 2.0f, 3.5f, 2.5f, 2.5f);
    glPopMatrix();
}
Exemplo n.º 11
0
void manfredMohrP196A::drawComposition(int rowNum, int columnNum){
	float screenSpaceWidth = scale * spacing;
	int screenSpaceBottom = -(int)(rowNum * screenSpaceWidth + screenSpaceWidth/2 - dimensions.height/2.);
	int screenSpaceRight = (int)(columnNum * screenSpaceWidth - screenSpaceWidth/2 + dimensions.width/2.);
	int indexA = getIndexA(rowNum, columnNum);
	int indexB = indexA + 1;
	ofVec4f rotationA, rotationB;
	
	ofVec4f rotationCenterA =
		zeroVector * (1. - cubeARotationPercent) +
		rotations[0] * cubeARotationPercent;
	ofVec4f rotationCenterB =
		rotationCenterA * (1. - cubeBRotationDiffPercent) +
		rotations[1] * cubeBRotationDiffPercent;
	if (rowNum == 0 && columnNum == 0){
		rotationA = rotationCenterA;
		rotationB = rotationCenterB;
	} else {
		rotationA =
			rotationCenterA * (1. - cubeOthersRotationDiffPercent) +
			rotations[indexA] * cubeOthersRotationDiffPercent;
		rotationB =
			rotationCenterB * (1. - cubeOthersRotationDiffPercent) +
			rotations[indexB] * cubeOthersRotationDiffPercent;
	}

	ofPushMatrix();
	{
		ofTranslate(spacing * columnNum, spacing * rowNum, 0);
		ofSetColor(foregroundColor, rearLineOpacity);
		ofDrawLine(0, -spacing/2, 0, spacing/2);
		glEnable(GL_SCISSOR_TEST);  
		{
			//draw cube A
			glScissor(
				screenSpaceRight, 
				screenSpaceBottom, 
				screenSpaceWidth, 
				screenSpaceWidth/2);
			ofSetColor(backgroundColor);
			ofFill();
			drawCube(rotationA);
			ofSetColor(foregroundColor);
			ofNoFill();
			drawCube(rotationA);
	
			//draw cube B
			glScissor(
				screenSpaceRight, 
				screenSpaceBottom + screenSpaceWidth/2, 
				screenSpaceWidth, 
				screenSpaceWidth/2);
			ofSetColor(backgroundColor);
			ofFill();
			drawCube(rotationB);
			ofSetColor(foregroundColor);
			ofNoFill();
			drawCube(rotationB);

			
			//draw inner bg
			glScissor(
				screenSpaceRight + (int)((screenSpaceWidth - scale)/2),
				screenSpaceBottom + (int)((screenSpaceWidth - scale)/2),
				scale,
				scale);
			ofSetColor(backgroundHighlightColor);
			ofFill();
			drawCube(zeroVector);
			
			ofSetColor(foregroundColor);
			ofSetLineWidth(highlightLineWidth);
			ofNoFill();
			//draw inner cube A
			glScissor(
				screenSpaceRight + (int)((screenSpaceWidth - scale)/2),
				screenSpaceBottom + (int)((screenSpaceWidth - scale)/2),
				scale,
				scale/2);
			drawCube(rotationA);
	
			//draw inner cube B
			glScissor(
				screenSpaceRight + (int)((screenSpaceWidth - scale)/2),
				screenSpaceBottom + (int)(screenSpaceWidth/2),
				scale,
				scale/2);
			drawCube(rotationB);

		}
		glDisable(GL_SCISSOR_TEST);  
		
		//draw dividing line
		ofSetLineWidth(1);
		ofDrawLine(-spacing/2, 0, spacing/2, 0);
	}
	ofPopMatrix();
}
Exemplo n.º 12
0
void Car::draw()
{
	if (!active) return;
	// Reinicia transformações
	glPushMatrix();
	glTranslatef(_position.getX(), _position.getY(), _position.getZ() + 0.2);
	glRotatef(_turnAngle, 0, 0, 1);

	//corpo do carro
	glPushMatrix();
	GLfloat bodyAmb[] = { 0.35f,0.0f,0.0f,1.0f };
	GLfloat bodyDiff[] = { 0.69f,0.0f,0.0f,1.0f };
	GLfloat bodySpec[] = { 0.29f,0.28f,0.29f,1.0f };
	GLfloat bodyShine = 46;
	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, bodyAmb);
	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, bodyDiff);
	glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, bodySpec);
	glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, bodyShine);
	glColor3f(1.0f, 0.0f, 0.0f);
	glScalef(1.0f, 0.8f, 0.3f);
	drawCube();
	glPopMatrix();

	//cockpit do carro
	glPushMatrix();
	glTranslatef(-0.2f, 0.0f, 0.20f);
	glScalef(0.4f, 0.6f, 0.1f);
	GLfloat cockpitAmb[] = { 0.07f,0.07f,0.07f,1.0f };
	GLfloat cockpitDiff[] = { 0.13f,0.17f,0.17f,1.0f };
	GLfloat cockpitSpec[] = { 0.42f,0.41f,0.41f,1.0f };
	GLfloat cockpitShine = 4;
	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, cockpitAmb);
	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, cockpitDiff);
	glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, cockpitSpec);
	glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, cockpitShine);
	glColor3f(1.0, 1.0, 1.0);
	drawCube();
	glColor3f(1.0, 0.0, 0.0);
	glutWireCube(1.0);
	glPopMatrix();


	// roda traseira direita
	glPushMatrix();
	GLfloat wheel1Amb[] = { 0.0f,0.0f,0.0f,1.0f };
	GLfloat wheel1Diff[] = { 0.13f,0.13f,0.14f,1.0f };
	GLfloat wheel1Spec[] = { 0.17f,0.18f,0.19f,1.0f };
	GLfloat wheel1Shine = 12;
	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, wheel1Amb);
	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, wheel1Diff);
	glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, wheel1Spec);
	glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, wheel1Shine);
	glColor3f(1.0, 1.0, 1.0);
	glTranslatef(-0.3f, -0.45f, 0.0f);
	glRotated(90, 1, 0, 0);
	glScalef(0.4f, 0.4f, 1.5f);
	drawWheel();
	glColor3f(0, 0, 0);
	glutWireTorus(0.05, 0.2, 32, 32);
	glPopMatrix();


	//perna dianteira direita
	glPushMatrix();
	GLfloat wheel2Amb[] = { 0.0f,0.0f,0.0f,1.0f };
	GLfloat wheel2Diff[] = { 0.13f,0.13f,0.14f,1.0f };
	GLfloat wheel2Spec[] = { 0.17f,0.18f,0.19f,1.0f };
	GLfloat wheel2Shine = 12;
	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, wheel2Amb);
	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, wheel2Diff);
	glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, wheel2Spec);
	glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, wheel2Shine);
	glColor3f(1.0, 1.0, 1.0);
	glTranslatef(0.3f, -0.45f, 0.0);
	glRotated(90, 1, 0, 0);
	glScalef(0.4f, 0.4f, 1.5f);
	drawWheel();
	glColor3f(0.0, 0.0, 0.0);
	glutWireTorus(0.05, 0.2, 32, 32);
	glPopMatrix();


	// roda traseira direita
	glPushMatrix();
	GLfloat wheel3Amb[] = { 0.0f,0.0f,0.0f,1.0f };
	GLfloat wheel3Diff[] = { 0.13f,0.13f,0.14f,1.0f };
	GLfloat wheel3Spec[] = { 0.17f,0.18f,0.19f,1.0f };
	GLfloat wheel3Shine = 12;
	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, wheel3Amb);
	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, wheel3Diff);
	glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, wheel3Spec);
	glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, wheel3Shine);
	glColor3f(1.0, 1.0, 1.0);
	glTranslatef(-0.3f, 0.45f, 0.0f);
	glRotated(90, 1, 0, 0);
	glScalef(0.4f, 0.4f, 1.5f);
	drawWheel();
	glColor3f(0, 0, 0);
	glutWireTorus(0.05, 0.2, 32, 32);
	glPopMatrix();


	//perna dianteira direita
	glPushMatrix();
	GLfloat wheel4Amb[] = { 0.0f,0.0f,0.0f,1.0f };
	GLfloat wheel4Diff[] = { 0.13f,0.13f,0.14f,1.0f };
	GLfloat wheel4Spec[] = { 0.17f,0.18f,0.19f,1.0f };
	GLfloat wheel4Shine = 12;
	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, wheel4Amb);
	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, wheel4Diff);
	glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, wheel4Spec);
	glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, wheel4Shine);
	glColor3f(1.0, 1.0, 1.0);
	glTranslatef(0.3f, 0.45f, 0.0);
	glRotated(90, 1, 0, 0);
	glScalef(0.4f, 0.4f, 1.5f);
	drawWheel();
	glColor3f(0.0, 0.0, 0.0);
	glutWireTorus(0.05, 0.2, 32, 32);
	glPopMatrix();

	glPopMatrix();
}
Exemplo n.º 13
0
void GameSpace::draw(GLfloat cubeWidth)
{
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Clear the background of our window to black
	glClear(GL_COLOR_BUFFER_BIT); //Clear the colour buffer (more buffers later on)
	glLoadIdentity(); // Load the Identity Matrix to reset our drawing locations

	// ---------------------------------------------------------------
	// ------ Drawing of box environment -----------------------------
	// ---------------------------------------------------------------

	int count = 0; // number of rectangles drawn (for alternating color purposes)
	glTranslatef(0.0, 0.0, -1.0f); // start drawing a little ways in.
	for(int i = 0; i < 12; i++) // For each layer
	{
		for(int j = 0; j < 5; j++) // top wall, 5 squares across
		{
			if( count % 2)
				glColor3f(0.0f, 0.0f, 0.0f);
			else
				glColor3f(0.0f, 0.2f, 0.2f);
			count++;
			glBegin(GL_QUADS);
				glVertex3f(-(cubeWidth * 2.5) + cubeWidth*j, -(cubeWidth * 2.5), 0.0 - cubeWidth*i);
				glVertex3f(-(cubeWidth * 2.5) + cubeWidth*j, -(cubeWidth * 2.5), -cubeWidth - cubeWidth*i);
				glVertex3f(-(cubeWidth * 1.5) + cubeWidth*j, -(cubeWidth * 2.5), -cubeWidth - cubeWidth*i);
				glVertex3f(-(cubeWidth * 1.5) + cubeWidth*j, -(cubeWidth * 2.5), 0.0 - cubeWidth*i);
			glEnd();
		}
		count++; // to alternate colors properly
		for(int j = 0; j < 5; j++) // left wall, 5 squares across
		{
			if( count % 2)
				glColor3f(0.0f, 0.0f, 0.0f);
			else
				glColor3f(0.0, 0.2f, 0.2f);
			count++;
			glBegin(GL_QUADS);
				glVertex3f(-(cubeWidth * 2.5), -(cubeWidth * 2.5) + cubeWidth*j, 0.0 - cubeWidth*i);
				glVertex3f(-(cubeWidth * 2.5), -(cubeWidth * 2.5) + cubeWidth*j, -cubeWidth - cubeWidth*i);
				glVertex3f(-(cubeWidth * 2.5), -(cubeWidth * 1.5) + cubeWidth*j, -cubeWidth - cubeWidth*i);
				glVertex3f(-(cubeWidth * 2.5), -(cubeWidth * 1.5) + cubeWidth*j, 0.0 - cubeWidth*i);
			glEnd();
		}
		count++; // to alternate colors properly
		for(int j = 0; j < 5; j++) // bottom wall, 5 squares across
		{
			if( count % 2)
				glColor3f(0.0f, 0.0f, 0.0f);
			else
				glColor3f(0.0, 0.2f, 0.2f);
			count++;
			glBegin(GL_QUADS);
				glVertex3f(-(cubeWidth * 2.5) + cubeWidth*j, (cubeWidth * 2.5), 0.0 - cubeWidth*i);
				glVertex3f(-(cubeWidth * 2.5) + cubeWidth*j, (cubeWidth * 2.5), -cubeWidth - cubeWidth*i);
				glVertex3f(-(cubeWidth * 1.5) + cubeWidth*j, (cubeWidth * 2.5), -cubeWidth - cubeWidth*i);
				glVertex3f(-(cubeWidth * 1.5) + cubeWidth*j, (cubeWidth * 2.5), 0.0 - cubeWidth*i);
			glEnd();
		}
		count++; // to alternate colors properly
		for(int j = 0; j < 5; j++) // right wall, 5 squares across
		{
			if( count % 2)
				glColor3f(0.0f, 0.0f, 0.0f);
			else
				glColor3f(0.0, 0.2f, 0.2f);
			count++;
			glBegin(GL_QUADS);
				glVertex3f((cubeWidth * 2.5), -(cubeWidth * 2.5) + cubeWidth*j, 0.0 - cubeWidth*i);
				glVertex3f((cubeWidth * 2.5), -(cubeWidth * 2.5) + cubeWidth*j, -cubeWidth - cubeWidth*i);
				glVertex3f((cubeWidth * 2.5), -(cubeWidth * 1.5) + cubeWidth*j, -cubeWidth - cubeWidth*i);
				glVertex3f((cubeWidth * 2.5), -(cubeWidth * 1.5) + cubeWidth*j, 0.0 - cubeWidth*i);
			glEnd();
		}
	}
	// Draw the bottom of the box
	for(int i = 0; i < 5; i++)
	{
		for(int j = 0; j < 5; j++)
		{
			if( count % 2)
				glColor3f(0.0f, 0.0f, 0.0f);
			else
				glColor3f(0.0, 0.2f, 0.2f);
			count++;
			glBegin(GL_QUADS);
				glVertex3f(-(cubeWidth * 2.5) + cubeWidth*i, -(cubeWidth * 2.5) + cubeWidth*j, -12*cubeWidth);
				glVertex3f(-(cubeWidth * 1.5) + cubeWidth*i, -(cubeWidth * 2.5) + cubeWidth*j, -12*cubeWidth);
				glVertex3f(-(cubeWidth * 1.5) + cubeWidth*i, -(cubeWidth * 1.5) + cubeWidth*j, -12*cubeWidth);
				glVertex3f(-(cubeWidth * 2.5) + cubeWidth*i, -(cubeWidth * 1.5) + cubeWidth*j, -12*cubeWidth);
			glEnd();
		}
	}
	// ---------------------------------------------------------------
	// ------ End drawing of box environment -------------------------
	// ---------------------------------------------------------------

	// ---------------------------------------------------------------
	// ------ Begin drawing of fallen tetronimos ---------------------
	// ---------------------------------------------------------------
	// Load texture once at the beginning
	GLuint tex_2d = SOIL_load_OGL_texture
		(
			"cube-border.bmp",
			SOIL_LOAD_AUTO,
			SOIL_CREATE_NEW_ID,
			SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT
		);
	glBindTexture(GL_TEXTURE_2D, tex_2d); // bind the texture so the cubes will have border
	for(int k = 11; k >= 0; k--) // for each layer
	{
		for(int dist = length/2 + width/2; dist >=0; dist--) // draw the ones farther from center first for visual appearance
		{
			for(int i = 0; i < width; i++) // double for loop to get all 25 cubes in layer
			{
				for(int j = 0; j < length; j++)
				{

					int index = i + j * length + k * length * width; // convert x,y,z (i,j,k) to index

					if(filled[index] && (abs(width/2 - i) + abs(length/2 - j)) == dist) // if filled and appropriate distance, draw
					{
						glLoadIdentity(); // Load the Identity Matrix to reset our drawing locations
						glTranslatef((i-2)*cubeWidth, (j-2)*cubeWidth, -1.0-0.5*cubeWidth-k*cubeWidth);
						switch (k) // different colors based on height
						{
						case 0:
							glColor3f(1.0, 0.0, 0);
							break;
						case 1:
							glColor3f(0.5, 0.0, 0.9);
							break;
						case 2:
							glColor3f(0.9, 0.5, 0);
							break;
						case 3:
							glColor3f(0.9, 0.9, 0.0);
							break;
						case 4:
							glColor3f(0.0, 0.5, 0.9);
							break;
						case 5:
							glColor3f(0.2, 0.6, 0.4);
							break;
						case 6:
							glColor3f(0.2, 0.1, 0.0);
							break;
						case 7:
							glColor3f(0.9, 0.0, 0.5);
							break;
						case 8:
							glColor3f(0.9, 0.5, 0.9);
							break;
						case 9:
							glColor3f(0.5, 0.5, 0.9);
							break;
						case 10:
							glColor3f(0.5, 0.9, 0.0);
							break;
						case 11:
							glColor3f(0.5, 0.9, 0.9);
							break;

						}

						drawCube(cubeWidth, i, j, tex_2d); // draw the cube

					}
				}
			}
		}
	}
	glDeleteTextures(1, &tex_2d); // delete the texture to free memeory
	// ---------------------------------------------------------------
	// ------ End drawing of fallen tetronimos ---------------------
	// ---------------------------------------------------------------

}
Exemplo n.º 14
0
    void draw(void)
    {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        
//        glEnable(GL_DEPTH_TEST);

        //setOrthographicCubeProjection(1.f);

        glPushMatrix();
        glLoadIdentity();

        glRotatef(rotateX,1,0,0);
        glRotatef(-rotateY,0,1,0);

        glScalef(scale,scale,scale);
        glTranslatef(-0.5,-0.5,-0.5); 

        console.push_back("Hello collisions");
        
        
        glColor3ub(155,155,155);        
        if (showWire) {
            //const size_t size = tris.size();
            glBegin(GL_LINES);
            for (unsigned i=0;i<objs.size();i++) {
                for (unsigned j=0;j<objs[i].faces_.size();j++) {
                    
                    const Real3& a = objs[i].tvx_[objs[i].faces_[j][0]];
                    const Real3& b = objs[i].tvx_[objs[i].faces_[j][1]];
                    const Real3& c = objs[i].tvx_[objs[i].faces_[j][2]];
                    glVertex3fv(&a[0]);
                    glVertex3fv(&b[0]);
                    glVertex3fv(&b[0]);
                    glVertex3fv(&c[0]);
                    glVertex3fv(&c[0]);
                    glVertex3fv(&a[0]);
                }
                if (showNormals) {
                    glColor3ub(0,255,0);
                    for (unsigned j=0;j<objs[i].tnormals_.size();j++) {
                        const Real3& n = objs[i].tnormals_[j];
                        const Real3& v = objs[i].tvx_[j];
                        glVertex3fv(&v[0]);
                        glVertex3fv(&(v+0.01*n)[0]);    
                    }
                }
            }
            glEnd();
        }
        glColor3ub(255,0,0);
//        glBegin(GL_LINES);
//        if (true) {
//            glVertex3f(seg[0].x,seg[0].y,seg[0].z);
//            glVertex3f(seg[1].x,seg[1].y,seg[1].z);
//
//        }
//        glEnd();
//        
//        	public:
//		Vector<const Polygon *> polys_;
//		Vector<int> users_;
//		Vec3f segmentPt0_;
//		Vec3f segmentPt1_;
//	};
      
        
        
        glColor3ub(255,0,0);
        if (showGeom) {
            glEnable(GL_LIGHTING);
            glEnable(GL_LIGHT0);
//            glEnable(GL_DEPTH_TEST);

            glEnableClientState(GL_VERTEX_ARRAY);
            glEnableClientState(GL_NORMAL_ARRAY);

            for(unsigned i=0;i<objs.size();i++) {
                glVertexPointer(3, GL_FLOAT, 0, &objs[i].tvx_[0]);
                glNormalPointer(GL_FLOAT, 0, &objs[i].tnormals_[0]);
                glColorPointer(3,GL_UNSIGNED_BYTE, 0, &objs[i].colors_[0]);
                glDrawElements(	GL_TRIANGLES, objs[i].faces_.size()*3, GL_UNSIGNED_INT, &objs[i].faces_[0]);
            }

            glDisableClientState(GL_VERTEX_ARRAY);
            glDisableClientState(GL_NORMAL_ARRAY);
            
            glDisable(GL_LIGHTING);
//            glDisable(GL_DEPTH_TEST);
        }
        
        glDisable(GL_DEPTH_TEST);

        glBegin(GL_LINES);
        for(unsigned i=0;i<objs.size();i++) {
            glColor3ub(0,255,0);
            
            for (unsigned j=0;j<12;j++) {
                BoxEdge e = coltrees[i]->getRootNode()->aabb.getEdge(j);
                Vec3f s = e.p0;
                Vec3f p = e.p1;
                glVertex3f(s.x,s.y,s.z);
                glVertex3f(p.x,p.y,p.z);
            }

            for (unsigned j=0;j<colres[i].polys_.size();j++) {
                const Real3& a = objs[i].tvx_[colres[i].polys_[j]->getIndex(0)];
                const Real3& b = objs[i].tvx_[colres[i].polys_[j]->getIndex(1)];
                const Real3& c = objs[i].tvx_[colres[i].polys_[j]->getIndex(2)];
                    glVertex3fv(&a[0]);
                    glVertex3fv(&b[0]);
                    glVertex3fv(&b[0]);
                    glVertex3fv(&c[0]);
                    glVertex3fv(&c[0]);
                    glVertex3fv(&a[0]);
            }
            Vec3f s = colres[i].segmentPt0_;
            Vec3f p = colres[i].segmentPt1_;
            glVertex3f(s.x,s.y,s.z);
            glVertex3f(p.x,p.y,p.z);
        }
        glEnd();
        glEnable(GL_DEPTH_TEST); 


        drawCube(1.);
        drawAxis(0.01);
//        glDisable(GL_DEPTH_TEST);
            

        glPopMatrix();

        testTextOverlay();

        glutSwapBuffers();
    }
void reye(void){
	glColor3f(1.0f, 1.0f, 0.0f);
	glTranslatef(0.25, 0.15, 0.0);
	glScalef(0.3, 0.2, 0.0);
	drawCube();
}
Exemplo n.º 16
0
void GFXDrawUtil::drawCube( const GFXStateBlockDesc &desc, const Box3F &box, const ColorI &color, const MatrixF *xfm )
{
   drawCube( desc, box.getExtents(), box.getCenter(), color, xfm );
}
Exemplo n.º 17
0
void Draw2D::drawCube(SDL_Surface *screen,Cube _cube)
{
    drawCube(screen, _cube.pt1, _cube.pt2, _cube.pt3, _cube.pt4);
}
Exemplo n.º 18
0
void drawRoom(){
    float size = 100;
    drawCube(size);
    glPushMatrix();

}
Exemplo n.º 19
0
void drawModel (pScene sc) {
	pMesh mesh;
	pTransform view;
	pClip clip;
	ubyte sstatic;

	/* default */
	mesh = cv.mesh[sc->idmesh];
	view = sc->view;
	clip = sc->clip;
	if (ddebug) printf("\n-- redraw scene %d, mesh %d\n", sc->idwin, sc->idmesh);

	glDisable(GL_LIGHTING);

	/* draw clipping plane */
	if (clip->active & C_ON) {
		drawClip(sc, clip, mesh, 0);
		glClipPlane(GL_CLIP_PLANE0, clip->eqn);
		glEnable(GL_CLIP_PLANE0);
	} else {
		glDisable(GL_CLIP_PLANE0);
	}

	/* draw object if static scene */
	sstatic = view->mstate > 0 && clip->cliptr->mstate > 0;
	if (sstatic || sc->type & S_FOLLOW) {
		displayScene(sc, sc->mode, 0);
		if (sc->item & S_NUMP || sc->item & S_NUMF) listNum(sc, mesh);

		/* draw normals */
		if (sc->type & S_NORMAL) {
			if (!sc->nlist) sc->nlist = drawNormals(mesh, sc);

			glCallList(sc->nlist);
		}

		/* draw data */
		if (sstatic) displayData(sc, mesh);
	} else if (!(sc->item & S_BOX)) {
		drawBox(sc, mesh, 0);
	}

	/* draw ridges, corners, etc. */
	if ((sc->item & S_GEOM) && sc->glist) {
		glDisable(GL_LIGHTING);
		if (!mesh->ne)
			glPointSize(1);
		else
			glPointSize(5);

		glDisable(GL_COLOR_MATERIAL);
		glCallList(sc->glist);
	}

	glDisable(GL_CLIP_PLANE0);
	if (clip->active & C_EDIT || sc->item & S_BOX)
		drawBox(sc, mesh, 0);

	if (sc->item & S_AXIS)
		drawAxis(sc, mesh->dim);

	if ((mesh->dim == 3 || sc->mode & S_ALTITUDE) && sc->item & S_GRID)
		drawBase(sc, mesh);

	if (sc->cube->active & C_ON)
		drawCube(sc, mesh);

	sstatic |= tiling;
	if (sstatic && clip->active & C_ON && clip->active & C_VOL)
		displayScene(sc, sc->mode, 1);

	if (sc->picklist && !(sc->isotyp & S_PARTICLE)) {
		glEnable(GL_LIGHTING);
		glEnable(GL_COLOR_MATERIAL);
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
		glDisable(GL_POLYGON_OFFSET_FILL);
		glCallList(sc->picklist);
		glEnable(GL_POLYGON_OFFSET_FILL);
		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
		glDisable(GL_COLOR_MATERIAL);
		glDisable(GL_LIGHTING);
	}

	/* show path, if any */
	if (sc->type & S_PATH && sc->path.tlist)
		glCallList(sc->path.tlist);
}
void lower_body(){
	glColor3f(1.0f, 1.0f, 0.0f);
	drawCube();
	left_thigh();
	right_thigh();
}
Exemplo n.º 21
0
void render() {
	glClearColor(0.0, 0.0, 0.0, 1);
	glClearDepth(1.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glLoadIdentity();

	float mtime, seconds, useconds;
	gettimeofday(&new_timeval, NULL);

	seconds  = new_timeval.tv_sec  - previous_timeval.tv_sec;
	useconds = new_timeval.tv_usec - previous_timeval.tv_usec;

	mtime = seconds + useconds/1000000;

	getHuniplacerData()->modeldata.deltatime = mtime;

	float dif = mtime * 40;

	previous_timeval = new_timeval;

	if (getKeyData()->key_left)
		yRotation += dif;
	if (getKeyData()->key_right)
		yRotation -= dif;

	if (getKeyData()->key_plus)
		getHuniplacerData()->modeldata.robot->setSpeed(getHuniplacerData()->modeldata.robot->getSpeed() + dif*3);
	if (getKeyData()->key_min)
		getHuniplacerData()->modeldata.robot->setSpeed(getHuniplacerData()->modeldata.robot->getSpeed() - dif*3);

	if (getKeyData()->key_up)
		xRotation += dif;
	if (getKeyData()->key_down)
		xRotation -= dif;

	if (getKeyData()->key_w)
		getHuniplacerData()->modeldata.pivot.y += dif;
	if (getKeyData()->key_s)
		getHuniplacerData()->modeldata.pivot.y -= dif;

	if (getKeyData()->key_d)
		getHuniplacerData()->modeldata.pivot.x += dif;
	if (getKeyData()->key_a)
		getHuniplacerData()->modeldata.pivot.x -= dif;

	if (getKeyData()->key_q)
		getHuniplacerData()->modeldata.pivot.z += dif;
	if (getKeyData()->key_e)
		getHuniplacerData()->modeldata.pivot.z -= dif;

	if (getHuniplacerData()->modeldata.pivot.x < huniplacer::measures::MIN_X)
		getHuniplacerData()->modeldata.pivot.x = huniplacer::measures::MIN_X;
	if (getHuniplacerData()->modeldata.pivot.x > huniplacer::measures::MAX_X)
		getHuniplacerData()->modeldata.pivot.x = huniplacer::measures::MAX_X;

	if (getHuniplacerData()->modeldata.pivot.y < huniplacer::measures::MIN_Y)
		getHuniplacerData()->modeldata.pivot.y = huniplacer::measures::MIN_Y;
	if (getHuniplacerData()->modeldata.pivot.y > huniplacer::measures::MAX_Y)
		getHuniplacerData()->modeldata.pivot.y = huniplacer::measures::MAX_Y;

	if (getHuniplacerData()->modeldata.pivot.z < huniplacer::measures::MIN_Z)
		getHuniplacerData()->modeldata.pivot.z = huniplacer::measures::MIN_Z;
	if (getHuniplacerData()->modeldata.pivot.z > huniplacer::measures::MAX_Z)
		getHuniplacerData()->modeldata.pivot.z = huniplacer::measures::MAX_Z;

	if(getHuniplacerData()->modeldata.robot->getSpeed() < 20)
		getHuniplacerData()->modeldata.robot->setSpeed(20);
	if(getHuniplacerData()->modeldata.robot->getSpeed() > 500)
		getHuniplacerData()->modeldata.robot->setSpeed(500);

	glRotatef(xRotation, 1, 0, 0);
	glRotatef(yRotation, 0, 1, 0);

	glColor3f(1.0f, 0, 0);
	glPushMatrix();
	glTranslatef(getHuniplacerData()->modeldata.pivot.x + 0.5, getHuniplacerData()->modeldata.pivot.z, getHuniplacerData()->modeldata.pivot.y);
	drawCube(0, 0, 0, 5, 1, 1);
	glPopMatrix();

	glPushMatrix();
	glColor3f(0, 1, 0);
	glTranslatef(getHuniplacerData()->modeldata.pivot.x, getHuniplacerData()->modeldata.pivot.z + 0.5, getHuniplacerData()->modeldata.pivot.y);
	drawCube(0, 0, 0, 1, 5, 1);
	glPopMatrix();

	glPushMatrix();
	glColor3f(0, 0, 1);
	glTranslatef(getHuniplacerData()->modeldata.pivot.x, getHuniplacerData()->modeldata.pivot.z, getHuniplacerData()->modeldata.pivot.y + 0.5);
	drawCube(0, 0, 0, 1, 1, 5);
	glPopMatrix();

	getHuniplacerData()->modeldata.robot->draw();

	glColor4f(0.3, 0.3, 0.3, 0.1);

	glPushMatrix();
	glDepthMask(GL_FALSE);
	glCallList(cubelist);
	glDepthMask(GL_TRUE);
	glPopMatrix();

	glLoadIdentity();
	char str[256];

	glDisable(GL_DEPTH_TEST);
	glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
	glRasterPos2i(-(screen_width / 5), 65);
	sprintf(str, "pivot location x:%g", getHuniplacerData()->modeldata.pivot.x);
	glutBitmapString(GLUT_BITMAP_HELVETICA_10, (unsigned char*) str);
	glRasterPos2i(-(screen_width / 5), 55);
	sprintf(str, "pivot location y:%g", getHuniplacerData()->modeldata.pivot.y);
	glutBitmapString(GLUT_BITMAP_HELVETICA_10, (unsigned char*) str);
	glRasterPos2i(-(screen_width / 5), 45);
	sprintf(str, "pivot location z:%g", getHuniplacerData()->modeldata.pivot.z);
	glutBitmapString(GLUT_BITMAP_HELVETICA_10, (unsigned char*) str);

	float rx, ry, rz;
	getHuniplacerData()->modeldata.robot->getPosition(&rx, &ry, &rz);
	glRasterPos2i(-(screen_width / 5), 35);
	sprintf(str, "robot location x:%g", rx);
	glutBitmapString(GLUT_BITMAP_HELVETICA_10, (unsigned char*) str);
	glRasterPos2i(-(screen_width / 5), 25);
	sprintf(str, "robot location y:%g", ry);
	glutBitmapString(GLUT_BITMAP_HELVETICA_10, (unsigned char*) str);
	glRasterPos2i(-(screen_width / 5), 15);
	sprintf(str, "robot location z:%g", rz);
	glutBitmapString(GLUT_BITMAP_HELVETICA_10, (unsigned char*) str);
	glRasterPos2i(-(screen_width / 5), 5);
	sprintf(str, "speed:%g", getHuniplacerData()->modeldata.robot->getSpeed());
	glutBitmapString(GLUT_BITMAP_HELVETICA_10, (unsigned char*) str);

	glEnable(GL_DEPTH_TEST);
	glutSwapBuffers();

	ros::spinOnce();
	if(!ros::ok()){
		glutDestroyWindow(glutGetWindow());
	}
}
Exemplo n.º 22
0
void drawFlowerStem() {
        mvstack.push(model_view);
                set_colour(0.5, 0.35, 0.05);
                //draw pieces of the stem
                //#1
                mvstack.push(model_view);
                        model_view *= RotateZ(1.25*sin(TIME));
                        model_view *= Translate(0, 1.0, 0);
                        model_view *= RotateZ(1.25*sin(TIME));
                        model_view *= Scale(.15, 1, .15);
                        drawCube();
                model_view = mvstack.pop();
                //#2
                mvstack.push(model_view);
                        model_view *= RotateZ(2.5*sin(TIME));
                        model_view *= Translate(0, 2, 0);
                        model_view *= RotateZ(2.5*sin(TIME));
                        model_view *= Scale(.15, 1, .15);
                        drawCube();
                model_view = mvstack.pop();
                //#3
                mvstack.push(model_view);
                        model_view *= RotateZ(3.75*sin(TIME));
                        model_view *= Translate(0, 3, 0);
                        model_view *= RotateZ(3.75*sin(TIME));
                        model_view *= Scale(.15, 1, .15);
                        drawCube();
                model_view = mvstack.pop();
                //#4
                mvstack.push(model_view);
                        model_view *= RotateZ(5*sin(TIME));
                        model_view *= Translate(0, 4, 0);
                        model_view *= RotateZ(5*sin(TIME));
                        model_view *= Scale(.15, 1, .15);
                        drawCube();
                model_view = mvstack.pop();
                //#5
                mvstack.push(model_view);
                        model_view *= RotateZ(6.25*sin(TIME));
                        model_view *= Translate(0, 5, 0);
                        model_view *= RotateZ(6.25*sin(TIME));
                        model_view *= Scale(.15, 1, .15);
                        drawCube();
                model_view = mvstack.pop();
                //#6
                mvstack.push(model_view);
                        model_view *= RotateZ(7.5*sin(TIME));
                        model_view *= Translate(0, 6, 0);
                        model_view *= RotateZ(7.5*sin(TIME));
                        model_view *= Scale(.15, 1, .15);
                        drawCube();
                model_view = mvstack.pop();
                //#7
                mvstack.push(model_view);
                        model_view *= RotateZ(8.75*sin(TIME));
                        model_view *= Translate(0, 7, 0);
                        model_view *= RotateZ(8.75*sin(TIME));
                        model_view *= Scale(.15, 1, .15);
                        drawCube();
                model_view = mvstack.pop();
                //#8
                mvstack.push(model_view);
                        model_view *= RotateZ(10*sin(TIME));
                        model_view *= Translate(0, 8, 0);
                        model_view *= RotateZ(10*sin(TIME));
                        model_view *= Scale(.15, 1, .15);
                        drawCube();
                model_view = mvstack.pop();
        model_view = mvstack.pop();
}
Exemplo n.º 23
0
int main(int argc, char *argv[]){
	getinfo(&screen);
	clear(0);
	
	Triangle tri[] = {
	    {-1,0,1, -1,1,1, -2,0,1, 0xFFFF},{-2,1,1, -1,1,1, -2,0,1, 0xFFFF},
	    {-1,0,0, -1,1,0, -2,0,0, 0xFFFF},{-2,1,0, -1,1,0, -2,0,0, 0xFFFF},
	    
	    {-1,0,0, -1,0,1, -2,0,0, 0xFFFF},{-2,0,0, -1,0,1, -2,0,1, 0xFFFF},
	    {-1,1,0, -1,1,1, -2,1,0, 0xFFFF},{-2,1,0, -1,1,1, -2,1,1, 0xFFFF},
	    
	    {-1,0,0, -1,1,1, -1,0,1, 0xFFFF},{-1,0,0, -1,1,1, -1,1,0, 0xFFFF},
	    {-2,0,0, -2,1,1, -2,0,1, 0xFFFF},{-2,0,0, -2,1,1, -2,1,0, 0xFFFF}
	};
	
	Line complex[] = {
	    {2,2,2, 3,2,2, 0xFFFFFF},
	    {2,2,2, 2,2,3, 0xFFFFFF},
	    {3,2,2, 3,2,3, 0xFFFFFF},
	    {2,2,3, 3,2,3, 0xFFFFFF},

	    {2,2,2, 2.5,1,2.5, 0xFFFFFF},
	    {2,2,3, 2.5,1,2.5, 0xFFFFFF},
	    {3,2,2, 2.5,1,2.5, 0xFFFFFF},
	    {3,2,3, 2.5,1,2.5, 0xFFFFFF}
	};
	
	Camera defaultcam = {0, 0, -2, 0, 0, 0, 0, 0, 1};
	Player p = {defaultcam, {100,2,0.5,0.25, //size
				defaultcam.cx,defaultcam.cy,defaultcam.cz, //position
				0,0,0, //velocity
				0,0,0, //force
				defaultcam.ox,defaultcam.oy,defaultcam.oz, //orientation
				0,0,0, //angular speed
				0,0,0 //torque
				}};
	int i;
	Cube c[] = {newCube(0.25, 0, 0, 0, 0xFF),
		    newCube(0.5, 1, 1, 1, 0xFF00),
		    newCube(1, -2, 2, 2, 0xFF0000)};
	char update = 1;
	while(!checkkey(KEYQ)){
		if(checkkey(KEYW)) movePlayer(&p, 0, 0, 0.2);
		if(checkkey(KEYA)) movePlayer(&p, 0.2, 0, 0);
		if(checkkey(KEYS)) movePlayer(&p, 0, 0, -0.2);
		if(checkkey(KEYD)) movePlayer(&p, -0.2, 0, 0);
		if(checkkey(KEYSPACE) & p.o.y==0){
		    p.o.vy = 0.2;
		}
		//if(checkkey(KEYLEFTCONTROL)) movePlayer(&p, 0, -0.2, 0);
		
		if(checkkey(KEYK)>0 & p.o.ox < M_PI/2) p.o.ox += 0.05;
		if(checkkey(KEYI)>0 & p.o.ox > -M_PI/2) p.o.ox -= 0.05;
		if(checkkey(KEYL)) p.o.oy += 0.05;
		if(checkkey(KEYJ)) p.o.oy -= 0.05;
		
		if(checkkey(KEYE)==1) wireframe = !wireframe;
		
		if(checkkey(KEYX)) resetPlayer(&p, defaultcam);
		
		
		    updatePlayer(&p);
		    
		    clear(0);
		
		    drawTriangles3D(tri, sizeof(tri)/sizeof(Triangle), p.c);
		    drawSphere(1,1,-1,0.2,0xFF00FF,p.c);
		    for(i = 0; i < sizeof(c)/sizeof(Cube); i++) drawCube(c[i], p.c);
		    drawLines3D(complex, sizeof(complex)/sizeof(Line), p.c);
		    
		    drawtext(0,0,"Wireframe test. Press q to exit.",0xFFFFFF);
		    drawline(screen.x/2-8,screen.y/2,screen.x/2+8,screen.y/2,0xFFFFFF);
		    drawline(screen.x/2,screen.y/2-8,screen.x/2,screen.y/2+8,0xFFFFFF);

		for(i = 0; i < 7; i++) hlt();
	}
	reset();
	return 0;
}
Exemplo n.º 24
0
void draw(){


	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glMatrixMode(GL_MODELVIEW);

	


	glLoadIdentity();             // Reset
	glPushMatrix();

#ifdef ANIMATION_SHOW 
	glRotatef(fRotateViewPhi, 1.0f, 0.0f, 0.0f);
	glRotatef(fRotateViewSigma, 0.0f, 1.0f, 0.0f);

#else
	glRotatef((float)mousex,0.0f,1.0f,0.0f);
	glRotatef((float)mousey,1.0f,0.0f,0.0f);

//	glRotatef(45.0f,1.0f,0.0f,0.0f);
//	glRotatef(45.0f,0.0f,1.0f,0.0f);
#endif

#ifdef ANIMATION_SHOW
	glScalef(0.5f, 0.5f, 0.5f);
#else
	glScalef(0.4f, 0.4f, 0.4f);
#endif
	glTranslatef(-1.5f,-1.5f,-1.5f);


#ifdef ANIMATION_SHOW
	drawCube(fRotateSlice);
#else
	resetBuffers();

	int iInc;
	for(iInc = 0; iInc < 54; iInc++){
//		if(cMoveArr[2][iInc] == 1)
			drawNumberedFace(CUBE_SIZE, CORNER_RADIUS, iInc);
	}

	//	Cubes Being Rotated
	drawFullCube(CUBE_SIZE, CORNER_RADIUS);
#endif
	glPopMatrix();

#ifdef ANIMATION_SHOW
	//	code to update permutations when move has completed
	if(fRotateSlice >= 90.0f){
		fRotateSlice = 0.0f;
		unsigned char cFace = 0;
		unsigned char cDir = 0;
		unsigned char cMove = 0;

		if(iMoveState == MOVE_STATE_BACKWARD){	// Working the way back on permutations
			cFace = (*cMarker) & MOVE_FACES;					// filter out Direction (Face remains)
			cDir = (~((*cMarker) & MOVE_DIRS)) & MOVE_DIRS;				// filter out Face (Direciton remains) then Reverse Direction
			cMove = cFace | cDir;							// combine to apply effective going in reverse
			cApplySingleMove(&cMove);

			if(cMarker == cMoves){
				generateRandomMoves((unsigned char)(0));
				cMarker = cMoves;
				iMoveState = MOVE_STATE_FORWARD;
			}else
				cMarker--;

		}else if(iMoveState == MOVE_STATE_FORWARD){
			cApplySingleMove(cMarker);

			if((cMarker - cMoves) >= (iArrayCount - 1))
				iMoveState = MOVE_STATE_BACKWARD;				//	reverse direction
			else
				cMarker++;

		}

	}else
		fRotateSlice += SPEED_SLICE;


	fRotateViewPhi += SPEED_VIEW_PHI;
	fRotateViewSigma += SPEED_VIEW_SIGMA;

#endif

//	glutPostRedisplay();

	glutSwapBuffers();


}
Exemplo n.º 25
0
int main(int argc, char** argv)
{
	std::cout << "Ami ViewPort3" << std::endl;
	// Init GLFW
	glfwInit();
	// Create a GLFWwindow object that we can use for GLFW's functions
	GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "LearnOpenGL", nullptr, nullptr);
	

	glfwMakeContextCurrent(window);

	// Set the required callback functions
	glfwSetKeyCallback(window, key_callback);

	glEnable(GL_DEPTH_TEST); // Depth Testing
	glDepthFunc(GL_LEQUAL);
	glDisable(GL_CULL_FACE);
	glCullFace(GL_BACK);

	// Set this to true so GLEW knows to use a modern approach to retrieving function pointers and extensions
	glewExperimental = GL_TRUE;
	// Initialize GLEW to setup the OpenGL Function pointers
	glewInit();

	glfwGetFramebufferSize(window, &width, &height);
	
	

	//Shader ourShader("C:\\C++\\ViewPort3\\ViewPort3\\Debug\\default.vs", "C:\\C++\\ViewPort3\\ViewPort3\\Debug\\default.frag");

	while (!glfwWindowShouldClose(window))
	{

		// Scale to window size
		GLint windowWidth, windowHeight;
		glfwGetWindowSize(window, &windowWidth, &windowHeight);

		// Draw stuff
		glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		

		{
			glViewport(0, windowHeight / 2, windowWidth / 2, windowHeight / 2);           // top left
			glMatrixMode(GL_PROJECTION_MATRIX);
			glLoadIdentity();
			gluPerspective(80, (double)windowWidth / (double)windowHeight, 0.1, 100);
			glMatrixMode(GL_MODELVIEW_MATRIX);
			glTranslatef(0, 0, -5);
			//ourShader.Use();  // as soon as i use shader, image wont rotate
			drawTriangle();
			
		}

		{
			glViewport(windowWidth / 2, 0, windowWidth / 2, windowHeight / 2);           // bottom right
			glMatrixMode(GL_PROJECTION_MATRIX);
			glLoadIdentity();
			gluPerspective(-45, (double)windowWidth / (double)windowHeight, 0.1, 100);
			glMatrixMode(GL_MODELVIEW_MATRIX);
			glTranslatef(0, 0, -5);
			drawCube();
		}

		glfwSwapBuffers(window);
		
		glfwPollEvents();

	}

	// Terminate GLFW, clearing any resources allocated by GLFW.
	glfwTerminate();
	return 0;
	return 0;
}
void loop()
{
	drawCube();
	delay(ROTATION_SPEED);
}
Exemplo n.º 27
0
void MyGLWidget::paintGL()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  // Clear The Screen And The Depth Buffer
    glLoadIdentity();       // Reset The Current Modelview Matrix
    glTranslatef( 0.0f, 0.0f, z );

    glEnable(GL_TEXTURE_GEN_S);
    glEnable(GL_TEXTURE_GEN_T);

    glBindTexture( GL_TEXTURE_2D, texture[filter*2 + 1] );
    glPushMatrix();

    glRotatef( xrot, 1.0f, 0.0f, 0.0f);
    glRotatef( yrot, 0.0f, 1.0f, 0.0f);

    /* Determine what object to draw */
    switch( object )
    {
    case 0:
        /* Draw our cube */
        drawCube( );
        break;
    case 1:
        /* Draw a cylinder */
        glTranslatef( 0.0f, 0.0f, -1.5f );
        gluCylinder( quadratic, 1.0f, 1.0f, 3.0f, 32, 32 );
        break;
    case 2:
        /* Draw a sphere */
        gluSphere( quadratic, 1.3f, 32, 32 );
        break;
    case 3:
        /* Draw a cone */
        glTranslatef( 0.0f, 0.0f, -1.5f );
        gluCylinder( quadratic, 1.0f, 0.0f, 3.0f, 32, 32 );
        break;
    };

    glPopMatrix();

    /* Disable Texture Coord Generation For S */
    glDisable( GL_TEXTURE_GEN_S );
    /* Disable Texture Coord Generation For T */
    glDisable( GL_TEXTURE_GEN_T );

    /* This Will Select The BG Texture */
    glBindTexture( GL_TEXTURE_2D, texture[filter*2] );
    glPushMatrix();
        glTranslatef( 0.0f, 0.0f, -29.0f );
        glBegin( GL_QUADS );
            glNormal3f( 0.0f, 0.0f, 1.0f);
            glTexCoord2f( 0.0f, 0.0f ); glVertex3f( -13.3f, -10.0f,  10.0f );
            glTexCoord2f( 1.0f, 0.0f ); glVertex3f(  13.3f, -10.0f,  10.0f );
            glTexCoord2f( 1.0f, 1.0f ); glVertex3f(  13.3f,  10.0f,  10.0f );
            glTexCoord2f( 0.0f, 1.0f ); glVertex3f( -13.3f,  10.0f,  10.0f );
        glEnd();
    glPopMatrix();

    xrot += xspeed; /* Add xspeed To xrot */
    yrot += yspeed; /* Add yspeed To yrot */

    showFPS();
}
Exemplo n.º 28
0
void display(void)
{
	// update the logic and simulation
	time += timeSpeed;
	solarSystem.calculatePositions(time);

	if (controls.forward) camera.forward();		if (controls.backward) camera.backward();
	if (controls.left) camera.left();			if (controls.right) camera.right();
	if (controls.yawLeft) camera.yawLeft();		if (controls.yawRight) camera.yawRight();
	if (controls.rollLeft) camera.rollLeft();	if (controls.rollRight) camera.rollRight();
	if (controls.pitchUp) camera.pitchUp();		if (controls.pitchDown) camera.pitchDown();

	// clear the buffers
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glColor3f(1.0, 1.0, 1.0);

	
	// set up the perspective matrix for rendering the 3d world
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(70.0f, (float)screenWidth / (float)screenHeight, 0.001f, 500.0f);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	

	// perform the camera orientation transform
	camera.transformOrientation();

	// draw the skybox
	glBindTexture(GL_TEXTURE_2D, stars->getTextureHandle());
	drawCube();

	// perform the camera translation transform
	camera.transformTranslation();

	
	
	GLfloat lightPosition[] = { 0.0, 0.0, 0.0, 1.0 };
	glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
	
	// render the solar system
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_LIGHTING);

	solarSystem.render();
	glDisable(GL_LIGHTING);

	// possibly render orbits
	if (showOrbits)
		solarSystem.renderOrbits();
	
	glDisable(GL_DEPTH_TEST);

	// set up ortho matrix for showing the UI (help dialogue)
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0.0, (GLdouble) screenWidth, (GLdouble) screenHeight, 0.0);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	
	// draw the help dialogue
	if (helpDialogue)
	{
		glBindTexture(GL_TEXTURE_2D, help->getTextureHandle());
		glBegin(GL_QUADS);
			glTexCoord2f(0.0f, 0.0f);	glVertex2f(0.0f, 0.0f);
			glTexCoord2f(1.0f, 0.0f);	glVertex2f(512.0f, 0.0f);
			glTexCoord2f(1.0f, 1.0f);	glVertex2f(512.0f, 512.0f);
			glTexCoord2f(0.0f, 1.0f);	glVertex2f(0.0f, 512.0f);
		glEnd();
	}

	glFlush();
	glutSwapBuffers();
}
Exemplo n.º 29
0
void EdManipGUIObject::draw (EdLevelToolWindow *parent, const std::shared_ptr<CameraObject> &camera, DTfloat scale)
{
    if (getSelection().size() != 1)
        return;
        
    GUIObject *gui_object = checkedCast<GUIObject*>(getSelection().front());
    if (!gui_object)
        return;
    
        
    // Override the camera with a screen aligned one
    CameraObject gui_camera = *camera;  // Copy all camera attributes
    gui_camera.setOrtho(0.0F,1.0F,0.0F,1.0F,1.0F,-1.0F);
    gui_camera.setTranslationLocal(Vector3(0.0F,0.0F,0.0F));
    gui_camera.setOrientationLocal(Matrix3::identity());
        
    DrawUtils::activateCamera(&gui_camera);
        
    Matrix4 axis;
    Matrix4 transform = getManipulatorTransform();
    
    scale = 7.0F / System::getRenderer()->getScreenWidth();

    ::glPushName(0);
    
    Rectangle r = gui_object->getRectangle();
    
    Vector3 p0 = Vector3(r.getMinusX(), r.getMinusY(), 0.0F);
    Vector3 p1 = Vector3(r.getPlusX(), r.getMinusY(), 0.0F);
    Vector3 p2 = Vector3(r.getPlusX(), r.getPlusY(), 0.0F);
    Vector3 p3 = Vector3(r.getMinusX(), r.getPlusY(), 0.0F);
    
    // Translate
    ::glLoadName(TRANSLATE);
    axis = Matrix4(     Matrix3(    1.0F, 0.0F, 0.0F,
                                    0.0F, 1.0F, 0.0F,
                                    0.0F, 0.0F, 1.0F), 
                        Vector3(0.0F,0.0F,0.0F), 
                        scale);
    drawCube(&_red_material, transform * axis);
    
    // X Axis
    ::glLoadName(MINUS_X);
    axis = Matrix4(     Matrix3(    1.0F, 0.0F, 0.0F,
                                    0.0F, 1.0F, 0.0F,
                                    0.0F, 0.0F, 1.0F), 
                        (p0+p3)*0.5F, 
                        scale);
    drawCube(&_red_material, transform * axis);

    ::glLoadName(PLUS_X);
    axis = Matrix4(     Matrix3(    1.0F, 0.0F, 0.0F,
                                    0.0F, 1.0F, 0.0F,
                                    0.0F, 0.0F, 1.0F), 
                        (p1+p2)*0.5F, 
                        scale);
    drawCube(&_red_material, transform * axis);
    
    // Y Axis
    ::glLoadName(MINUS_Y);
    axis = Matrix4(     Matrix3(    1.0F, 0.0F, 0.0F,
                                    0.0F, 1.0F, 0.0F,
                                    0.0F, 0.0F, 1.0F), 
                        (p0+p1)*0.5F, 
                        scale);
    drawCube(&_red_material, transform * axis);

    ::glLoadName(PLUS_Y);
    axis = Matrix4(     Matrix3(    1.0F, 0.0F, 0.0F,
                                    0.0F, 1.0F, 0.0F,
                                    0.0F, 0.0F, 1.0F), 
                        (p2+p3)*0.5F, 
                        scale);
    drawCube(&_red_material, transform * axis);

    ::glLoadName(0);
    
    // Draw Lines
    DrawBatcher b;
    b.batchBegin(&_line_material, transform, DrawBatcher::BATCH_LINE_LOOP, DrawBatcher::FMT_V);

    b.vertex(p0);
    b.vertex(p1);
    b.vertex(p2);
    b.vertex(p3);

    b.batchEnd();

    
    ::glPopName();  // Pop component
    
    
    DrawUtils::activateCamera(camera);
}
Exemplo n.º 30
0
void HelloVrui::display(GLContextData& contextData) const
	{
	/* Print the modelview and projection matrices: */
//        GLdouble mv[16],p[16];
//        glGetDoublev(GL_MODELVIEW_MATRIX,mv);
//        glGetDoublev(GL_PROJECTION_MATRIX,p);

#if 0 // Printing matrices
        std::cout << "Display matrices " << std::endl;
        std::cout << "VRUI MV:" << std::endl;
	for(int i=0;i<4;++i)
		{
		for(int j=0;j<4;++j)
			std::cout<<" "<<std::setw(12)<<mv[i+j*4];
                std::cout << std::endl;
                }
                std::cout << std::endl << "VRUI P:" << std::endl;
//		std::cout<<"        ";
	for(int i=0;i<4;++i)
          {
		for(int j=0;j<4;++j)
			std::cout<<" "<<std::setw(12)<<p[i+j*4];
		std::cout<<std::endl;
		}
	std::cout<<std::endl;
#endif

	/* Save OpenGL state: */
	glPushAttrib(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_ENABLE_BIT|GL_LIGHTING_BIT|GL_POLYGON_BIT);
        if(this->drawGLCube)
          {
          drawCube();
          }
        else
          {

        /* Directly set the projection and model view matrices for the camera
         * This syncs up the VRUI and VTK camera
         * NOTE: Since, VTK takes a transpose of the matrices internally
         * before rendering, the matrices are transposed here first and then set
         * on the camera to nullify the transpose.
         */
//        double p1[16], mv1[16];
//        this->transposeMatrix4x4(p,p1);
//        this->cam->SetProjectionTransformMatrix(p);
//        this->transposeMatrix4x4(mv,mv1);
//        this->cam->SetViewTransformMatrix(mv);

        /* Render the scene */
        renWin->Render();

        /* It is observed that in the VRUI coordinate space, VTK's +Z axis
         * becomes the -Y axis. This causes, the light to always be at an
         * inverse position to the camera. To counter-act this association, the
         * light's transform matrix is set to an inverse of the camera's model
         * view matrix.
         */
//        vtkMatrix4x4* mat = 0;
//        mat->DeepCopy(this->cam->GetModelViewTransformMatrix());
//        if(!mat)
//          {
//          std::cout << "mat is null" << std::endl;
//          }
//        mat->Invert();
//        vtkLightCollection* lC = this->ren->GetLights();
//        lC->InitTraversal();
//        vtkLight* light = lC->GetNextItem();
//        light->SetTransformMatrix(mat);

          }
	glPopAttrib();
	}