Beispiel #1
0
static void particle_init(struct particle *p, struct anim *anim,
		particle_think_t particle_think,
		float x, float y, float w, float h,
		float angle, float vx, float vy, float age_max)
{
	memset(p, 0, sizeof(struct particle));
	p->think = particle_think;
	p->dead = 0;
	p->age = 0;
	p->age_max = age_max;
	set3f(p->v, vx, vy, 0);

	/* Init sprite */
	set3f(p->sprite.position, x, y, 0);
	set2f(p->sprite.scale, w, h);

	animatedsprites_playanimation(&p->sprite, anim);
}
Beispiel #2
0
/**
 * Updates the currently visible tiles based on the offset and the view
 * width/height specified in tiles_init().
 *
 * @param tiles			The tiles struct.
 * @param view_offset	The current offset from origo for this viewport.
 * @param atlas			The atlas to draw from.
 * @param dt			Delta time.
 */
void tiles_think(struct tiles *tiles, vec2 view_offset, struct atlas *atlas, float dt)
{
	animatedsprites_clear(tiles->batcher);

	/* Update draw tiles */
	for(int x = 0; x < tiles->draw_tiles_x; x++) {
		for(int y = 0; y < tiles->draw_tiles_y; y++) {
			struct sprite *draw_tile = tiles_get_draw_tile(tiles->draw_tiles, x, y,
					tiles->draw_tiles_x, tiles->draw_tiles_y);

			if(draw_tile == NULL) {
				continue;
			}

			animatedsprites_add(tiles->batcher, draw_tile);

			float grid_x = (x-1) * tiles->tile_size + tiles->tile_size/2.0f - fmod(view_offset[0], tiles->tile_size);
			float grid_y = (y-1) * tiles->tile_size + tiles->tile_size/2.0f - fmod(view_offset[1], tiles->tile_size);

			/* Get tile at coordinate. */
			struct anim *type = tiles->get_data_at_pixel_fn(view_offset[0] + grid_x,
															view_offset[1] + grid_y,
															tiles->tile_size, tiles->tiles_x, tiles->tiles_y);

			/* Set correct animation. */
			if(draw_tile->anim != type) {
				animatedsprites_playanimation(draw_tile, type);
			}

			set2f(draw_tile->scale, 1.0f, 1.0f);

			/* Move within the viewport. */
			set3f(draw_tile->position, grid_x, grid_y, 0);
		}
	}

	animatedsprites_update(tiles->batcher, atlas, dt);
}
Beispiel #3
0
void cmdHelp(std::string* args, CannonBall* ball)
{
    if (args[0].compare("help") == 0)
    {
        printf("exit                Exits the program\n");
        printf("help                Lists available commands.\n");
        printf("printinfo           Prints velocity and force acting on the cannonball\n");
        printf("setlinvel x y z     Sets velocity of cannonball\n");
        printf("setangvel x y z     Sets angular velocity of ball\n");
        printf("setwind x y z       Sets wind velocity\n");
        printf("setmass m           Sets mass of cannonball\n");
        printf("setradius r         Sets radius of cannonball\n");
        printf("setpos x y z        Sets the position of the cannonball\n");
        printf("reset               Sets position, lin. velocity, ang. velocity and wind to 0.\n");
        printf("launch              Launches the ball\n");

    }
    else if (args[0].compare("printinfo") == 0)
    {
        ball->printInfo();
    }
    else if (args[0].compare("launch") == 0)
    {
        ball->launch = true;
    }
    else if (args[0].compare("setpos") == 0)
    {
        float x, y, z;
        set3f(x, y, z, args);
        ball->pos.x = x;
        ball->pos.y = y;
        ball->pos.z = z;
    }
    else if (args[0].compare("reset") == 0)
    {
        ball->pos = vec3f(10, 0, ball->radius);
        ball->linVel = vec3f(0, 0, 0);
        ball->launch = false;
        wind = vec3f(0, 0, 0);
        ball->angVel = vec3f(0, 0, 0);
    }
    else if (args[0].compare("setlinvel") == 0)
    {
        float x, y, z;
        set3f(x, y, z, args);
        ball->linVel.x = x;
        ball->linVel.y = y;
        ball->linVel.z = z;
        cannon->setDirection(ball->linVel);
    }
    else if (args[0].compare("setangvel") == 0)
    {
        float x, y, z;
        set3f(x, y, z, args);
        ball->angVel.x = x;
        ball->angVel.y = y;
        ball->angVel.z = z;
    }
    else if (args[0].compare("setwind") == 0)
    {
        float x, y, z;
        set3f(x, y, z, args);
        wind.x = x;
        wind.y = y;
        wind.z = z;
    }
    else if (args[0].compare("setmass") == 0)
    {
        float x = 0;
        x = stof(args[1]);
        if (x > EPSILON)
        {
            ball->mass = x;
            ball->gravForce = vec3f(0.0f, 0.0f, ball->mass * -1.0f * GRAVACC);
        }
        else
            printf("Mass too low\n");
    }
    else if (args[0].compare("setradius") == 0)
    {
        float x = 0;
        x = stof(args[1]);
        if (x > EPSILON)
        {
            ball->radius = x;
            ball->area = ball->radius * ball->radius * PI;
        }
        else
            printf("Radius too low\n");
    }
    else if (args[0].compare("clear") == 0)
    {
        SDL_LockMutex(gRenderLock);
        clearBackground();
        SDL_UnlockMutex(gRenderLock);
    }
    else
    {
        printf("Unrecognized command\n");
    }
}
Beispiel #4
0
seal_err_t
SEAL_API
seal_set_listener_vel(float x, float y, float z)
{
    return set3f(AL_VELOCITY, x, y, z);
}
Beispiel #5
0
seal_err_t
SEAL_API
seal_set_listener_pos(float x, float y, float z)
{
    return set3f(AL_POSITION, x, y, z);
}
Beispiel #6
0
 void set_velocity(float x, float y, float z) {
     set3f(AL_VELOCITY, x,y,z);
 }
Beispiel #7
0
 void set_position(float x, float y, float z) {
     set3f(AL_POSITION, x,y,z);
 }
Beispiel #8
0
 void set_direction(float x, float y, float z) {
     set3f(AL_DIRECTION, x,y,z);
 }
Beispiel #9
0
CGO *CrystalGetUnitCellCGO(CCrystal * I)
{
  PyMOLGlobals *G = I->G;
  float v[3];
  CGO *cgo = NULL;
  if(I) {
    cgo = CGONew(G);
#ifndef PURE_OPENGL_ES_2
    CGODisable(cgo, GL_LIGHTING);
#endif

#ifdef _PYMOL_CGO_DRAWARRAYS
    {
      int nverts = 10, pl = 0;
      float *vertexVals;
      vertexVals = CGODrawArrays(cgo, GL_LINE_STRIP, CGO_VERTEX_ARRAY, nverts);	      
      set3f(v, 0, 0, 0);
      transform33f3f(I->FracToReal, v, v);
      vertexVals[pl++] = v[0]; vertexVals[pl++] = v[1]; vertexVals[pl++] = v[2];
      set3f(v, 1, 0, 0);
      transform33f3f(I->FracToReal, v, v);
      vertexVals[pl++] = v[0]; vertexVals[pl++] = v[1]; vertexVals[pl++] = v[2];
      set3f(v, 1, 1, 0);
      transform33f3f(I->FracToReal, v, v);
      vertexVals[pl++] = v[0]; vertexVals[pl++] = v[1]; vertexVals[pl++] = v[2];
      set3f(v, 0, 1, 0);
      transform33f3f(I->FracToReal, v, v);
      vertexVals[pl++] = v[0]; vertexVals[pl++] = v[1]; vertexVals[pl++] = v[2];
      set3f(v, 0, 0, 0);
      transform33f3f(I->FracToReal, v, v);
      vertexVals[pl++] = v[0]; vertexVals[pl++] = v[1]; vertexVals[pl++] = v[2];
      set3f(v, 0, 0, 1);
      transform33f3f(I->FracToReal, v, v);
      vertexVals[pl++] = v[0]; vertexVals[pl++] = v[1]; vertexVals[pl++] = v[2];
      set3f(v, 1, 0, 1);
      transform33f3f(I->FracToReal, v, v);
      vertexVals[pl++] = v[0]; vertexVals[pl++] = v[1]; vertexVals[pl++] = v[2];
      set3f(v, 1, 1, 1);
      transform33f3f(I->FracToReal, v, v);
      vertexVals[pl++] = v[0]; vertexVals[pl++] = v[1]; vertexVals[pl++] = v[2];
      set3f(v, 0, 1, 1);
      transform33f3f(I->FracToReal, v, v);
      vertexVals[pl++] = v[0]; vertexVals[pl++] = v[1]; vertexVals[pl++] = v[2];
      set3f(v, 0, 0, 1);
      transform33f3f(I->FracToReal, v, v);
      vertexVals[pl++] = v[0]; vertexVals[pl++] = v[1]; vertexVals[pl++] = v[2];
    }
    {
      int nverts = 6, pl = 0;
      float *vertexVals;
      vertexVals = CGODrawArrays(cgo, GL_LINES, CGO_VERTEX_ARRAY, nverts);	      
      set3f(v, 0, 1, 0);
      transform33f3f(I->FracToReal, v, v);
      vertexVals[pl++] = v[0]; vertexVals[pl++] = v[1]; vertexVals[pl++] = v[2];
      set3f(v, 0, 1, 1);
      transform33f3f(I->FracToReal, v, v);
      vertexVals[pl++] = v[0]; vertexVals[pl++] = v[1]; vertexVals[pl++] = v[2];
      set3f(v, 1, 1, 0);
      transform33f3f(I->FracToReal, v, v);
      vertexVals[pl++] = v[0]; vertexVals[pl++] = v[1]; vertexVals[pl++] = v[2];
      set3f(v, 1, 1, 1);
      transform33f3f(I->FracToReal, v, v);
      vertexVals[pl++] = v[0]; vertexVals[pl++] = v[1]; vertexVals[pl++] = v[2];
      set3f(v, 1, 0, 0);
      transform33f3f(I->FracToReal, v, v);
      vertexVals[pl++] = v[0]; vertexVals[pl++] = v[1]; vertexVals[pl++] = v[2];
      set3f(v, 1, 0, 1);
      transform33f3f(I->FracToReal, v, v);
      vertexVals[pl++] = v[0]; vertexVals[pl++] = v[1]; vertexVals[pl++] = v[2];
    }
#else
    CGOBegin(cgo, GL_LINE_STRIP);
    set3f(v, 0, 0, 0);
    transform33f3f(I->FracToReal, v, v);
    CGOVertexv(cgo, v);

    set3f(v, 1, 0, 0);
    transform33f3f(I->FracToReal, v, v);
    CGOVertexv(cgo, v);

    set3f(v, 1, 1, 0);
    transform33f3f(I->FracToReal, v, v);
    CGOVertexv(cgo, v);

    set3f(v, 0, 1, 0);
    transform33f3f(I->FracToReal, v, v);
    CGOVertexv(cgo, v);

    set3f(v, 0, 0, 0);
    transform33f3f(I->FracToReal, v, v);
    CGOVertexv(cgo, v);

    set3f(v, 0, 0, 1);
    transform33f3f(I->FracToReal, v, v);
    CGOVertexv(cgo, v);

    set3f(v, 1, 0, 1);
    transform33f3f(I->FracToReal, v, v);
    CGOVertexv(cgo, v);

    set3f(v, 1, 1, 1);
    transform33f3f(I->FracToReal, v, v);
    CGOVertexv(cgo, v);

    set3f(v, 0, 1, 1);
    transform33f3f(I->FracToReal, v, v);
    CGOVertexv(cgo, v);

    set3f(v, 0, 0, 1);
    transform33f3f(I->FracToReal, v, v);
    CGOVertexv(cgo, v);
    CGOEnd(cgo);

    CGOBegin(cgo, GL_LINES);

    set3f(v, 0, 1, 0);
    transform33f3f(I->FracToReal, v, v);
    CGOVertexv(cgo, v);

    set3f(v, 0, 1, 1);
    transform33f3f(I->FracToReal, v, v);
    CGOVertexv(cgo, v);

    set3f(v, 1, 1, 0);
    transform33f3f(I->FracToReal, v, v);
    CGOVertexv(cgo, v);

    set3f(v, 1, 1, 1);
    transform33f3f(I->FracToReal, v, v);
    CGOVertexv(cgo, v);

    set3f(v, 1, 0, 0);
    transform33f3f(I->FracToReal, v, v);
    CGOVertexv(cgo, v);

    set3f(v, 1, 0, 1);
    transform33f3f(I->FracToReal, v, v);
    CGOVertexv(cgo, v);
    CGOEnd(cgo);
#endif

#ifndef PURE_OPENGL_ES_2
    CGOEnable(cgo, GL_LIGHTING);
#endif
    CGOStop(cgo);
  }
  return (cgo);
}