Ejemplo n.º 1
0
int main(void)
{
	FsOpenWindow(16,16,800,600,1);

	OglPrim a,b;

	a.AddVertex(100,100);
	a.AddVertex(200,100);
	a.AddVertex(120,170);
	a.AddVertex(150,65);
	a.AddVertex(180,170);

	b=a;
	a.Move(5,5);

	while(FSKEY_ESC!=FsInkey())
	{
		FsPollDevice();

		glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);

		glColor3ub(0,0,0);
		a.Draw(GL_LINE_LOOP);

		if(0!=FsGetKeyState(FSKEY_LEFT))
		{
			a.Move(-10,0);
		}
		if(0!=FsGetKeyState(FSKEY_RIGHT))
		{
			a.Move(10,0);
		}
		if(0!=FsGetKeyState(FSKEY_UP))
		{
			a.Move(0,-10);
		}
		if(0!=FsGetKeyState(FSKEY_DOWN))
		{
			a.Move(0,10);
		}

		glColor3ub(0,0,255);
		b.Draw(GL_LINE_LOOP);

		FsSwapBuffers();
		FsSleep(25);
	}

	return 0;
}
Ejemplo n.º 2
0
void MovableByArrowKeys::Move(void)
{
	if(0!=FsGetKeyState(FSKEY_LEFT))
	{
		x-=5;
	}
	if(0!=FsGetKeyState(FSKEY_RIGHT))
	{
		x+=5;
	}
	if(0!=FsGetKeyState(FSKEY_UP))
	{
		y-=5;
	}
	if(0!=FsGetKeyState(FSKEY_DOWN))
	{
		y+=5;
	}
}
Ejemplo n.º 3
0
int FsCheckKeyHeldDown(void)
{
	int keyCode;
	for(keyCode=FSKEY_NULL+1; keyCode<FSKEY_NUM_KEYCODE; keyCode++)
	{
		if(0!=FsGetKeyState(keyCode))
		{
			return 1;
		}
	}
	return 0;
}
Ejemplo n.º 4
0
/* Thunder movement simulation. Currently it's not driven by Newton Equation.
   Whenever user press control keys, we move the plane by one step. */
void Thunder::Move(double deltaT) {
    if(FsGetKeyState(FSKEY_A)!=0)
	{
		position.x -= velocity;
	}
	if(FsGetKeyState(FSKEY_D)!=0)
	{
		position.x += velocity;
	}
    if(FsGetKeyState(FSKEY_S)!=0)
    {
        position.y += velocity;
    }
    if(FsGetKeyState(FSKEY_W)!=0){
        position.y -= velocity;
    }
    
    /* you wanna move thunder out of screen? NO WAY! Muahahahaha */
    if (position.x < 0) position.x = 0;
    if (position.x > WINDOW_WID) position.x = WINDOW_WID;
    if (position.y < size_y / 2) position.y = size_y / 2;
    if (position.y > WINDOW_HEI - size_y / 2) position.y = WINDOW_HEI - size_y / 2;
}
Ejemplo n.º 5
0
int main(int argc,char **argv)
{
    Options opt;
    if(!parse_args(&opt,argc,argv)){
        return 1;
    }
    char strk[256],strmu[256],strsigma[256],striso[256];
    int terminate=0;
    CameraObject camera;
    OrbitingViewer orbit;

	orbit.focusY=4.0;

    camera.z=10.0;

    FsOpenWindow(16,16,800,600,1);


    Cylinder cylinder;
	cylinder.setRadius(9.0);

    YsVec3 min(-10.0,0.0,-10.0);
    YsVec3 max(10.0,20.0,10.0);
    Box box;
    box.setMinMax(min,max);

    std::vector <YsVec3> iniPos;
    const double interval=0.9;
    CreateUniformInitialParticleLocation(iniPos,10,40,10,YsVec3(10.0,20.0,0.0),interval);

    std::vector <YsVec3> drip;
    CreateUniformInitialParticleLocation(drip,5,5,5,YsVec3(0.0,20.0,0.0),interval);

	ParticleSimulation sim;
    if(opt.infile){
        sim.read(opt.infile);
    }
    else{
	    //sim.init(iniPos);
    }
	sim.setObstacle(box);
	//sim.calculate_force();
	//sim.calculate_force();

	sim.mode=sim.MODE_NORMAL;



	glClearColor(0,0,0,0);

	YSBOOL pause=YSFALSE;
    YSBOOL cube=YSFALSE;
    YSBOOL savestl=YSFALSE;

    while(0==terminate)
    {
        FsPollDevice();

        int wid,hei;
        FsGetWindowSize(wid,hei);

        int key=FsInkey();
        switch(key)
        {
        case FSKEY_K:
            {
            printf("Enter k:\n");
            fscanf(stdin,"%lf",strk);
            double k=atof(strk);
            sim.setK(k);
            break;
            }
        case FSKEY_M:
            {
            printf("Enter mu:\n");
            fscanf(stdin,"%lf",strmu);
            double mu=atof(strmu);
            sim.setMu(mu);
            break;
            }
        case FSKEY_S:
            {
            printf("Enter Sigma:\n");
            fscanf(stdin,"%lf",strmu);
            double sigma=atof(strsigma);
            sim.setSigma(sigma);
            break;
            }
        case FSKEY_Q:
            if(cube){
                cube=YSFALSE;
            }
            else{
                cube=YSTRUE;
            }
            break;
        case FSKEY_I:
            {
                printf("Enter isolevel:\n");
                fscanf(stdin,"%lf",striso);
                double iso=atof(striso);
                sim.setIso(iso);
                break;
            }
        case FSKEY_L:
            if(savestl){
                savestl=YSFALSE;
            }
            else{
                savestl=YSTRUE;
            }
            break;

        case FSKEY_D:
            sim.placeParticles(drip);
            break;

		case FSKEY_P:
			YsFlip(pause);
			break;
        case FSKEY_ESC:
            terminate=1;
            break;
        }


		if(FSKEY_SPACE==key || YSTRUE!=pause)
		{
			sim.update();
		}

        if(0!=FsGetKeyState(FSKEY_LEFT))
        {
            orbit.h+=YsPi/180.0;
        }
        if(0!=FsGetKeyState(FSKEY_RIGHT))
        {
            orbit.h-=YsPi/180.0;
        }
        if(0!=FsGetKeyState(FSKEY_UP))
        {
            orbit.p+=YsPi/180.0;
        }
        if(0!=FsGetKeyState(FSKEY_DOWN))
        {
            orbit.p-=YsPi/180.0;
        }
        if(0!=FsGetKeyState(FSKEY_F) && orbit.dist>1.0)
        {
            orbit.dist/=1.05;
        }
        if(0!=FsGetKeyState(FSKEY_B) && orbit.dist<200.0)
        {
            orbit.dist*=1.05;
        }
        orbit.SetUpCamera(camera);

        glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);

        glViewport(0,0,wid,hei);

        // Set up 3D drawing
        camera.SetUpCameraProjection();
        camera.SetUpCameraTransformation();

        glEnable(GL_DEPTH_TEST);
        glEnable(GL_POLYGON_OFFSET_FILL);
        glPolygonOffset(1,1);

        // 3D drawing from here
		glPushMatrix();
		glPointSize(3);
        if(cube){
           sim.drawMesh();
           if(savestl){
               sim.shl.SaveBinStl("test.stl");
               printf("stl saved\n");
               savestl=YSFALSE;
           }
        }
        else{
            sim.drawParticles();
        }
        //sim.drawColorFieldGrid();

        glPopMatrix();

        // Set up 2D drawing
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(0,(float)wid-1,(float)hei-1,0,-1,1);

        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();

        glDisable(GL_DEPTH_TEST);

        FsSwapBuffers();
        FsSleep(25);
    }
    //sim.write(opt.outfile);

    return 0;
}
Ejemplo n.º 6
0
void Button::Update()
{
	// Updates stored values of the button object
	FsPollDevice();
	// Intigers such as U and D correspond to up and down buttons being pressed
	// If it is being pressed, it is a 1, otherwise it is a 0
    if(0!=FsGetKeyState(SF))
        F=1;
	else
		F=0;
    if(0!=FsGetKeyState(SB))
        B=1;
	else
		B=0;
	if(0!=FsGetKeyState(SL))
        L=1;
	else
		L=0;
    if(0!=FsGetKeyState(SR))
        R=1;
	else
		R=0;
	if(0!=FsGetKeyState(SU))
        U=1;
	else
		U=0;
	if(0!=FsGetKeyState(SD))
        D=1;
	else
		D=0;
    if(0!=FsGetKeyState(FSKEY_ESC))
        E=1; 
	else
		E=0;    
	if(0!=FsGetKeyState(GR))
        reset =1;
	else
		reset = 0;
	if(0 != FsGetKeyState(GC))
		cont = 1;
	else
		cont = 0;

	if(0 != FsGetKeyState(GP))
	{
		pause = 1;
	}
	else
		pause = 0;

	if(0 != FsGetKeyState(G1))
		one = 1;
	else
		one = 0;

	if(0 != FsGetKeyState(G2))
	{
		two = 1;
	}
	else
		two = 0;


	
}
Ejemplo n.º 7
0
int main(void)
{
    Vector2 bulletV(0, -10);
    Vector2 cannonV(0, -20);
    Vector2 laserV(0, -1);
    Vector2 bulletPosition(300, 400);
    Vector2 laserPosition(100, 400);
    Vector2 cannonPosition(200, 400);
    Vector2 velocity(1, 1);
    MissileList missiles;
    Missile *missile;
    MissileNode *laser = NULL;
    int laserReload = 0;
    int cannonReload = 0;
    int bulletReload = 0;
    int firing = 0;

    srand(time(NULL));
    FsOpenWindow(0,0,600, 800,1);
    glClearColor(0, 0, 0, 1);

    bool running = true;

    while(running)
    {
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
        FsPollDevice();

        int key=FsInkey();
        int lb, mb, rb, mx, my;
        int mouse = FsGetMouseEvent(lb, mb, rb, mx, my);

        if(FSKEY_ESC==key)
        {
            running=false;
        }
        if(FsGetKeyState(FSKEY_UP))
        {
            bulletV.rotate(0.05);
            cannonV.rotate(0.05);
            laserV.rotate(0.05);
        }
        if(FsGetKeyState(FSKEY_DOWN))
        {
            bulletV.rotate(-0.05);
            cannonV.rotate(-0.05);
            laserV.rotate(-0.05);
        }
        
        if(FSMOUSEEVENT_LBUTTONDOWN == mouse) {
            firing = 1;
        } else if (FSMOUSEEVENT_LBUTTONUP == mouse) {
            firing = 0;
        }
            
        if (firing == 1) {
            if (laserReload <= 0) {
                laserReload = 100;
                missile = new Laser(gBlue, 100, laserPosition, laserV, 1);
                laser = missiles.InsertFront(missile);
            }
            if (bulletReload <= 0) {
                bulletReload = 100;
                missile = new Bullet(gRed, 100, bulletPosition, bulletV, 1);
                missiles.InsertFront(missile);
            }
            if (cannonReload <= 0) {
                cannonReload = 100;
                missile = new Cannon(gGreen, 100, cannonPosition, cannonV, 1);
                missiles.InsertFront(missile);
            }
        }
        else if (firing == 0 && laser) {
            missiles.Delete(laser);
            laser = NULL;
            laserReload = 0;
        }

        MissileNode *node;
        node = missiles.getFront();
        while(node) {
            node->dat->Move(1.0);
            node->dat->Draw();
            if (!node->dat->CheckInWindow()) {
                node = missiles.Delete(node);
            } else {
                node = node->next;
            }
        }
        
        if (bulletReload > 0) bulletReload -= 10;
        if (cannonReload > 0) cannonReload -= 10;

/*
if(key == FSKEY_UP) printf("UP!!!!\n");
if(key == FSKEY_SPACE) printf("SPACE!!!\n");
if (FsCheckKeyHeldDown()) printf("KEY DOWN!!!\n");
*/
        FsSwapBuffers();


        FsSleep(25);
    }

    return 0;
}