Beispiel #1
0
void HariMain(void)
{
	BOOTINFO *binfo = (BOOTINFO *) ADR_BOOTINFO;
	//char string[40];
	char mCursor[mCursorWidth * mCursorHeight];
	unsigned char strings[4], keyBuffer[32], mouseBuffer[128],i;
	int j;
	int mCursorX, mCursorY;				//鼠标光标显示位置的横纵坐标
	mCursorX = binfo->scrnx / 2;			
	mCursorY = (binfo->scrny - 28)/ 2;		//减去下方任务栏的高度
	
	
	
	init_fifo(&keyFIFO, 32, keyBuffer);				//初始化FIFO缓冲区
	init_fifo(&mouseFIFO, 128, mouseBuffer);		//初始化FIFO缓冲区
	
	init_GDTandIDT();				//初始化GDT和IDT表
	init_pic();						//初始化PIC主从板数据
	io_sti();						//开始接收中断
	
	init_palette();					//初始化调色板
	
	init_screen(binfo->vram, binfo->scrnx, binfo->scrny);				//画出一个windows界面
	
	/*若要接收鼠标中断需要两个步骤,首先必须使鼠标控制电路(就是键盘控制电路的一部分)有效,然后要使鼠标本身有效*/
	init_keyboard();				//初始化键盘控制器电路
	enable_mouse();					//激活鼠标
	
	init_mouse_cursor(mCursor, COL8_008484);							//初始化鼠标光标
	displayShape(binfo->vram, binfo->scrnx, mCursorWidth, mCursorHeight, mCursorX, mCursorY, mCursor, mCursorWidth);		//显示鼠标光标
	
	io_out8(PIC0_IMR, 0xf9); 						/* PIC0开发IRQ(11111001) */
	io_out8(PIC1_IMR, 0xef); 						/* PIC1开放IRQ(11101111) */
	
	for(;;)
	{
		io_cli();
		if(0 == fifo_status(&keyFIFO) + fifo_status(&mouseFIFO))		//当前没有中断产生
		{
			io_stihlt();			//当CPU执行hlt指令之后只有外部中断等之情况才会再次唤醒CPU继续工作
		}
		else
		{
			if(0 != fifo_status(&keyFIFO))
			{
				i = fifo_get(&keyFIFO);
				io_sti();
				sprintf(strings,"%2X",i);
				drawRectangle(binfo->vram, binfo->scrnx, COL8_008484, 0, 0, 15,31);
				displayStrings_CS(binfo->vram, binfo->scrnx, 0, 0, COL8_FFFFFF,strings);
			}
			else if(0 != fifo_status(&mouseFIFO))
			{
				i = fifo_get(&mouseFIFO);
				io_sti();
				sprintf(strings,"%2X",i);
				drawRectangle(binfo->vram, binfo->scrnx, COL8_008484, 0, 50, 15,31);
				displayStrings_CS(binfo->vram, binfo->scrnx, 0, 50, COL8_FFFFFF,strings);
			}
		}
	}	
}
Beispiel #2
0
 void GLWidget::paintGL()
 {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glEnable(GL_DEPTH_TEST);
        glEnable(GL_MULTISAMPLE_ARB);
#if 1
        /*if (stereo_enabled)
        {
            render_stereo();
        }
        else
        {*/
            glMatrixMode(GL_MODELVIEW);
            glLoadIdentity();

            glPushMatrix();
            glRotatef(rotation.x, 1.0, 0.0, 0.0);
            glRotatef(rotation.y, 0.0, 0.0, 1.0); //we switched around the axis so make this rotate_z
            glTranslatef(translation.x, translation.z, translation.y);

            glDisable(GL_TEXTURE_2D);
            glEnable(GL_TEXTURE_GEN_S);
            glEnable(GL_TEXTURE_GEN_T);
            glEnable(GL_TEXTURE_GEN_R);
            glEnable(GL_TEXTURE_CUBE_MAP);

            glBindTexture(GL_TEXTURE_CUBE_MAP, environTex);
            // draw the skybox
            const GLfloat fSkyDist = 100.0;
            const GLfloat fTex = 1.0f;

            glBegin(GL_TRIANGLE_STRIP);

            //west
                glTexCoord3f(-fTex, -fTex , fTex);
                glVertex3f(-fSkyDist, -fSkyDist,  fSkyDist);
                glTexCoord3f(-fTex, fTex, fTex);
                glVertex3f(-fSkyDist, fSkyDist,  fSkyDist);
                glTexCoord3f(-fTex, -fTex, -fTex);
                glVertex3f(-fSkyDist, -fSkyDist, -fSkyDist);
                glTexCoord3f(-fTex, fTex,-fTex);
                glVertex3f(-fSkyDist, fSkyDist,  -fSkyDist);
            //north
                glTexCoord3f(fTex, -fTex,-fTex);
                glVertex3f(fSkyDist, -fSkyDist, -fSkyDist);
                glTexCoord3f(fTex, fTex,-fTex);
                glVertex3f(fSkyDist, fSkyDist, -fSkyDist);
            //east
                glTexCoord3f( fTex, -fTex, fTex);
                glVertex3f( fSkyDist, -fSkyDist,  fSkyDist);
                glTexCoord3f( fTex, fTex, fTex);
                glVertex3f( fSkyDist, fSkyDist,  fSkyDist);
            //south
                glTexCoord3f( -fTex, -fTex, fTex);
                glVertex3f( -fSkyDist, -fSkyDist,  fSkyDist);
                glTexCoord3f( -fTex, fTex, fTex);
                glVertex3f( -fSkyDist, fSkyDist,  fSkyDist);
            glEnd();
            glBegin(GL_QUADS);
            //up
                glTexCoord3f( -fTex, fTex, -fTex);
                glVertex3f( -fSkyDist, fSkyDist,  -fSkyDist);
                glTexCoord3f( -fTex, fTex, fTex);
                glVertex3f( -fSkyDist, fSkyDist,  fSkyDist);
                glTexCoord3f( fTex, fTex, fTex);
                glVertex3f( fSkyDist, fSkyDist,  fSkyDist);
                glTexCoord3f( fTex, fTex, -fTex);
                glVertex3f( fSkyDist, fSkyDist,  -fSkyDist);
            //down
                glTexCoord3f( fTex, -fTex, -fTex);
                glVertex3f( fSkyDist, -fSkyDist,  -fSkyDist);
                glTexCoord3f( fTex, -fTex, fTex);
                glVertex3f( fSkyDist, -fSkyDist,  fSkyDist);
                glTexCoord3f( -fTex, -fTex, fTex);
                glVertex3f( -fSkyDist, -fSkyDist,  fSkyDist);
                glTexCoord3f( -fTex, -fTex, -fTex);
                glVertex3f( -fSkyDist, -fSkyDist,  -fSkyDist);
            glEnd();

            glDisable(GL_TEXTURE_CUBE_MAP);

            glDisable(GL_TEXTURE_GEN_R);


            glPopMatrix();

            glRotatef(-90, 1.0, 0.0, 0.0);

            glRotatef(rotation.x, 1.0, 0.0, 0.0);
            glRotatef(rotation.y, 0.0, 0.0, 1.0); //we switched around the axis so make this rotate_z
            glTranslatef(translation.x, translation.z, translation.y);
            //Draw Origin - Found code at http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=248059

            float ORG[3] = {0,0,0};

            float XP[3] = {1,0,0}, XN[3] = {-1,0,0},
                  YP[3] = {0,1,0}, YN[3] = {0,-1,0},
                  ZP[3] = {0,0,1}, ZN[3] = {0,0,-1};
            glLineWidth (20.0);
            glBegin (GL_LINES);
            glColor3f (1,0,0); // X axis is red.
            glVertex3fv (ORG);
            glVertex3fv (XP );
            glColor3f (0,1,0); // Y axis is green.
            glVertex3fv (ORG);
            glVertex3fv (YP );
            glColor3f (0,0,1); // z axis is blue.
            glVertex3fv (ORG);
            glVertex3fv (ZP );
            glEnd();
            glLineWidth (1.0);

            //RenderUtils::renderBox(float4(light.pos.x-.5,light.pos.y-.5,light.pos.z-.5,1.0f),float4(light.pos.x+.5,light.pos.y+.5,light.pos.z+.5,1.0f),float4(.7,.2,.3,1.0f));
            /*ParticleRigidBody* rbsys = (ParticleRigidBody*)systems["rb1"];
            meshRenderer->renderInstanced(dynamicMeshs["dynamicShape0"],rbsys->getComPosVBO(),rbsys->getComRotationVBO(),rbsys->getNum(),light);
            if(systems.find("flock1")!=systems.end())
            {
                //dout<<"flock------------------"<<endl;
                FLOCK* flock = (FLOCK*)systems["flock1"];
                //effects[renderType]->render(flock->getPosVBO(),flock->getColVBO(),flock->getNum());
                meshRenderer->renderInstanced(dynamicMeshs["dynamicShape1"],flock->getPosVBO(),flock->getRotationVBO(),flock->getNum(),light);
            }
            display(false);
*/
            //FIXME: Have a method to give renderType to each System. That way we can have different
            //Systems with the different effects.
            for(map<QString,System*>::iterator i = systems.begin(); i!=systems.end(); i++)
            {
                if(renderVelocity)
                {
                    effects[systemRenderType[i->first]]->renderVector(i->second->getPosVBO(),i->second->getVelocityVBO(),i->second->getNum());
                }
                //effects[renderType]->render(i->second->getPosVBO(),i->second->getColVBO(),i->second->getNum());
                //FIXME:This is a horrible way of doing this!!
                //if(i->first=="rb1")
                //{
                //    ParticleRigidBody* prb=((ParticleRigidBody*)i->second);
                //    effects["default"]->render(prb->getStaticVBO(),prb->getColVBO(),prb->getStaticNum());
                //}
            }
            //FIXME: Super hacky! I should figure out betterways to determine how to render based on some settings.
            /*SPH* sph = (SPH*)systems["water"];
            glEnable(GL_DEPTH_TEST);
            glEnable(GL_BLEND);
            glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
            glBlendFunc(GL_ONE,GL_ONE);
            Mesh* mcMesh = sph->getMCMesh();
            glEnable(GL_BLEND);
            if(sph->getSettings()->GetSettingAs<bool>("use_color_field","0")&&mcMesh)
            {
		glEnable(GL_CULL_FACE);
                //meshRenderer->render(mcMesh,light);
                meshRenderer->renderFluid(mcMesh,environTex,0,light);
		glDisable(GL_CULL_FACE);
            }
            else
            {
                effects[renderType]->render(systems["water"]->getPosVBO(),systems["water"]->getColVBO(),systems["water"]->getNum());
            }*/
            display(true);
#else
        // set view matrix
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glRotatef(-90, 1.0, 0.0, 0.0);

        glRotatef(rotation.x, 1.0, 0.0, 0.0);
        glRotatef(rotation.y, 0.0, 0.0, 1.0); //we switched around the axis so make this rotate_z
        glTranslatef(translation.x, translation.z, translation.y);

        meshRenderer->render(dynamicMeshs["dynamicShape1"],light);
        glColor4f(0.1f,0.2f,0.4f,1.0f);
        displayShape(pShapes["dynamicShape1"],float3(5.0f,3.f,1.0f),systems["water"]->getSpacing());
        displayShape(pShapes["dynamicShape11"],float3(8.0f,3.f,1.0f),systems["water"]->getSpacing()/2.0f);
        displayShape(pShapes["dynamicShape112"],float3(11.0f,3.f,1.0f),systems["water"]->getSpacing()/4.0f);
        displayShape(pShapes["dynamicShape1123"],float3(14.0f,3.f,1.0f),systems["water"]->getSpacing()/8.0f);
        //displayShape(pShapes["dynamicShape11234"],float3(10.0f,0.0f,0.0f),systems["water"]->getSpacing()/16.0f);
        //}
        //glDisable(GL_DEPTH_TEST);

#endif
        glDisable(GL_MULTISAMPLE_ARB);
        if(renderMovie)
        {
            writeMovieFrame("image","./frames/");
            frameCounter++;
        }
	updateGL();
 }
Beispiel #3
0
void Vehicle::display(
				Point translateToThirdPerson,//this point brings the car into View in first and third person mode
 				GLuint txtSiren,
				GLuint txtCar,
				bool firstPersonMode,
				bool overHeadView
				)
{
		int currName = getName();
		Point Centroid=getOrigin();
		float height = getSpaceDimensions().y;
		float width = getSpaceDimensions().x;
		float depth = getSpaceDimensions().z;
		vector<Point> displayPoints;
		vector<Point> textureCoords;
		glPushMatrix();

		// **********CHANGE FOR OVEHEAD
		if (overHeadView)
		{
			glTranslatef(0,-45,0);
			glTranslatef(getOrigin().x,getOrigin().y,getOrigin().z);
		}else
			glLoadIdentity();
		
		//Light/Siren on Vehicle
		if (siren==0)
		{
			siren= gluNewQuadric();
			gluQuadricNormals(siren, GLU_SMOOTH);
			gluQuadricTexture (siren,GLU_TRUE);			
		}

	if(firstPersonMode)
	{
		glPopMatrix();
		glTranslatef(0,-4,0);
		return;
	}
		
	glColor4f(1,1,1,0.9);

	if(!overHeadView)
	{
		glTranslatef(8,-24,-8);
	}
	else
		glTranslatef(-getOrigin().x,getOrigin().y,-getOrigin().z);

	if (collisionOccurs)
	{ //shake
		glTranslatef(0.5,0.5,-0.5);
		//draw pieces flying off
		glPushMatrix();
		glTranslatef(getOrigin().x,getOrigin().y+2*height,getOrigin().z);
		glEnable(GL_COLOR_MATERIAL);
		glColor4f(0,0,0,1);

		glBegin(GL_TRIANGLES);
		glVertex3f(Centroid.x-2*height,Centroid.y+2.5*height,Centroid.z);
		glVertex3f(Centroid.x-2.1*height,Centroid.y+2.5*height,Centroid.z+height);
		glVertex3f(Centroid.x-2*height,Centroid.y+2.8*height,Centroid.z+height);
		glEnd();

		glBegin(GL_TRIANGLES);
		glVertex3f(Centroid.x-2*height,Centroid.y+height,Centroid.z);
		glVertex3f(Centroid.x-2.1*height,Centroid.y+1.5*height,Centroid.z);
		glVertex3f(Centroid.x-2*height,Centroid.y+1.8*height,Centroid.z+height);
		glEnd();

		glBegin(GL_TRIANGLES);
		glVertex3f(Centroid.x+height,Centroid.y+height,Centroid.z);
		glVertex3f(Centroid.x+height,Centroid.y+1.5*height,Centroid.z);
		glVertex3f(Centroid.x+height,Centroid.y+1,Centroid.z+height);
		glEnd();

		glBegin(GL_TRIANGLES);
		glVertex3f(Centroid.x+height,Centroid.y+1.8*height,Centroid.z);
		glVertex3f(Centroid.x,Centroid.y+1.5*height,Centroid.z-0.5*height);
		glVertex3f(Centroid.x+height,Centroid.y+2*height,Centroid.z);
		glEnd();

		glBegin(GL_TRIANGLES);
		glVertex3f(Centroid.x,Centroid.y+1,Centroid.z);
		glVertex3f(Centroid.x+2*height,Centroid.y+2*height,Centroid.z);
		glVertex3f(Centroid.x,Centroid.y+1,Centroid.z);
		glEnd();

		glBegin(GL_TRIANGLES);
		glVertex3f(Centroid.x-2*height,Centroid.y+2*height,Centroid.z);
		glVertex3f(Centroid.x-2*height,Centroid.y+1.5*height,Centroid.z);
		glVertex3f(Centroid.x-height,Centroid.y+2*height,Centroid.z);
		glEnd();

		glDisable(GL_COLOR_MATERIAL);
		glColor4f(1,1,1,1);

		glPopMatrix();
	}
	

	glBindTexture(GL_TEXTURE_2D,txtCar);

	float damageModifier=(float)damage/(float)maxDamage *2.5;
	
	//Draw Vehicle
	displayPoints.clear();
	textureCoords.clear();
	glLoadName(getName());
	displayPoints.push_back(Point(Centroid.x - width+damageModifier,  Centroid.y - height,  Centroid.z - depth));
	displayPoints.push_back(Point(Centroid.x + width,  Centroid.y - height+damageModifier,  Centroid.z - depth));
	displayPoints.push_back(Point(Centroid.x + width,  Centroid.y + height,  Centroid.z - depth));
	displayPoints.push_back(Point(Centroid.x - width,  Centroid.y + height,  Centroid.z - depth));
	textureCoords =calculateTextureCoords(displayPoints);
	displayShape(displayPoints,textureCoords);

	displayPoints.clear();
	textureCoords.clear();
	displayPoints.push_back(Point(Centroid.x - width+damageModifier,  Centroid.y - height,  Centroid.z + depth));
	displayPoints.push_back(Point(Centroid.x + width,  Centroid.y - height-+damageModifier,  Centroid.z + depth));
	displayPoints.push_back(Point(Centroid.x + width,  Centroid.y - height,  Centroid.z - depth));
	displayPoints.push_back(Point(Centroid.x - width,  Centroid.y - height,  Centroid.z - depth));
	textureCoords =calculateTextureCoords(displayPoints);
	displayShape(displayPoints,textureCoords);

	displayPoints.clear();
	textureCoords.clear();
	displayPoints.push_back(Point(Centroid.x + width,  Centroid.y - height,  Centroid.z - depth-damageModifier));
	displayPoints.push_back(Point(Centroid.x + width,  Centroid.y - height,  Centroid.z + depth-damageModifier));
	displayPoints.push_back(Point(Centroid.x + width,  Centroid.y + height,  Centroid.z + depth));
	displayPoints.push_back(Point(Centroid.x + width+damageModifier,  Centroid.y + height-damageModifier,  Centroid.z - depth));
	textureCoords =calculateTextureCoords(displayPoints);
	displayShape(displayPoints,textureCoords);

	displayPoints.clear();
	textureCoords.clear();
	displayPoints.push_back(Point(Centroid.x - width,  Centroid.y - height+damageModifier,  Centroid.z + depth));
	displayPoints.push_back(Point(Centroid.x - width+damageModifier,  Centroid.y - height+damageModifier,  Centroid.z - depth));
	displayPoints.push_back(Point(Centroid.x - width,  Centroid.y + height,  Centroid.z - depth+damageModifier));
	displayPoints.push_back(Point(Centroid.x - width,  Centroid.y + height,  Centroid.z + depth+damageModifier));
	displayShape(displayPoints,calculateTextureCoords(displayPoints));

	displayPoints.clear();
	textureCoords.clear();
	displayPoints.push_back(Point(Centroid.x - width,  Centroid.y + height,  Centroid.z - depth));
	displayPoints.push_back(Point(Centroid.x + width+damageModifier,  Centroid.y + height+damageModifier,  Centroid.z - depth));
	displayPoints.push_back(Point(Centroid.x + width+damageModifier,  Centroid.y + height+damageModifier,  Centroid.z + depth));
	displayPoints.push_back(Point(Centroid.x - width,  Centroid.y + height,  Centroid.z + depth));
	displayShape(displayPoints,calculateTextureCoords(displayPoints));

	displayPoints.clear();
	textureCoords.clear();
	displayPoints.push_back(Point(Centroid.x + width+damageModifier,  Centroid.y - height,  Centroid.z + depth));
	displayPoints.push_back(Point(Centroid.x - width+damageModifier,  Centroid.y - height,  Centroid.z + depth));
	displayPoints.push_back(Point(Centroid.x - width,  Centroid.y + height,  Centroid.z + depth));
	displayPoints.push_back(Point(Centroid.x + width,  Centroid.y + height,  Centroid.z + depth));
	displayShape(displayPoints,calculateTextureCoords(displayPoints));

	//draw siren
	float lightEmissive[]={1.0,1.0,1.0};
	glMaterialfv(GL_FRONT, GL_EMISSION,lightEmissive);
	glTranslatef(getOrigin().x,getOrigin().y+height,getOrigin().z);
	glBindTexture(GL_TEXTURE_2D,txtSiren);
	gluSphere(siren,height/4, 20,20);
	float lightEmissive2[]={0.0,0.0,0.0};
	glMaterialfv(GL_FRONT, GL_EMISSION,lightEmissive2);
	glPopMatrix();

	collisionOccurs=false;
}