void mouse_get_3d_ray(Vec3D *position,Vec3D *vector) { Vec3D cam,pos1,pos2,rotation; GraphicsView view; graphics_get_view(&view); camera_get_position(&cam); gluUnProject(__mouse.x, __mouse.y, 0.99f, view.modelView, view.projectionX, view.viewPort, &pos1.x, &pos1.y, &pos1.z); gluUnProject(__mouse.x, __mouse.y, 1, view.modelView, view.projectionX, view.viewPort, &pos2.x, &pos2.y, &pos2.z); pos2.y *= -1; pos1.y *= -1; vec3d_add(pos1,cam,pos1); vec3d_add(pos2,cam,pos2); if (position) { vec3d_cpy((*position),pos1); } if (vector) { vec3d_sub((*vector),pos2,pos1); vec3d_normalize(vector); camera_get_rotation(&rotation); vec3d_rotate_about_x(vector,rotation.x); vec3d_rotate_about_y(vector,rotation.y); vec3d_rotate_about_z(vector,rotation.z); } }
Vec3d Particle_source_cylinder::uniform_position_in_cylinder( std::default_random_engine &rnd_gen ) { // random point in cylinder along z Vec3d cyl_axis = vec3d_init( ( axis_end_x - axis_start_x ), ( axis_end_y - axis_start_y ), ( axis_end_z - axis_start_z ) ); double cyl_axis_length = vec3d_length( cyl_axis ); double x, y, z; double r, phi; r = sqrt( random_in_range( 0.0, 1.0, rnd_gen ) ) * radius; phi = random_in_range( 0.0, 2.0 * M_PI, rnd_gen ); z = random_in_range( 0.0, cyl_axis_length, rnd_gen ); // x = r * cos( phi ); y = r * sin( phi ); z = z; Vec3d random_pnt_in_cyl_along_z = vec3d_init( x, y, z ); // rotate: // see https://en.wikipedia.org/wiki/Rodrigues'_rotation_formula // todo: Too complicated. Try rejection sampling. Vec3d random_pnt_in_rotated_cyl; Vec3d unit_cyl_axis = vec3d_normalized( cyl_axis ); Vec3d unit_along_z = vec3d_init( 0, 0, 1.0 ); Vec3d rotation_axis = vec3d_cross_product( unit_along_z, unit_cyl_axis ); double rotation_axis_length = vec3d_length( rotation_axis ); if ( rotation_axis_length == 0 ) { if ( copysign( 1.0, vec3d_z( unit_cyl_axis ) ) >= 0 ){ random_pnt_in_rotated_cyl = random_pnt_in_cyl_along_z; } else { random_pnt_in_rotated_cyl = vec3d_negate( random_pnt_in_cyl_along_z ); } } else { Vec3d unit_rotation_axis = vec3d_normalized( rotation_axis ); double rot_cos = vec3d_dot_product( unit_cyl_axis, unit_along_z ); double rot_sin = rotation_axis_length; random_pnt_in_rotated_cyl = vec3d_add( vec3d_times_scalar( random_pnt_in_cyl_along_z, rot_cos ), vec3d_add( vec3d_times_scalar( vec3d_cross_product( unit_rotation_axis, random_pnt_in_cyl_along_z ), rot_sin ), vec3d_times_scalar( unit_rotation_axis, ( 1 - rot_cos ) * vec3d_dot_product( unit_rotation_axis, random_pnt_in_cyl_along_z ) ) ) ); } // shift: Vec3d shifted = vec3d_add( random_pnt_in_rotated_cyl, vec3d_init( axis_start_x, axis_start_y, axis_start_z ) ); return shifted; }
int sphere_cube_intersection( Vec3D center,float r, /*sphere*/ Vec3D box, Vec3D size) /*axis aligned 3d cube*/ { float distance; Vec3D offset; offset.x = -(box.x + (size.x * 0.5)); offset.y = -(box.y + (size.y * 0.5)); offset.z = -(box.z + (size.z * 0.5)); vec3d_add(box,box,offset); vec3d_add(center,center,offset); center.x = fabs(center.x); center.y = fabs(center.y); center.z = fabs(center.z); box.x = fabs(box.x); box.y = fabs(box.y); box.z = fabs(box.z); distance = (box.x - center.x)*(box.x - center.x) + (box.y - center.y)*(box.y - center.y) + (box.z - center.z)*(box.z - center.z); if (distance <= (r * r)) { /*success, intersection with corner*/ return 1; } if ((center.x <= box.x + r) && (center.y <= box.y) && (center.z <= box.z)) { return 1; } if ((center.x <= box.x) && (center.y <= box.y + r) && (center.z <= box.z)) { return 1; } if ((center.x <= box.x) && (center.y <= box.y) && (center.z <= box.z + r)) { return 1; } return 0; }
static void space_body_update(Space *space,Body *body) { GList *it; Cube a,b; Body *other; Vec3D stepVector; Vec3D stepOffVector; if ((!body) || (body->_done))return; vec3d_scale(stepVector,body->velocity,space->stepFactor); vec3d_negate(stepOffVector,stepVector); vec3d_add(body->position,body->position,stepVector); a.x = body->position.x + body->bounds.x; a.y = body->position.y + body->bounds.y; a.z = body->position.z + body->bounds.z; a.w = body->bounds.w; a.h = body->bounds.h; a.d = body->bounds.d; for (it = space->bodylist;it != NULL;it = g_list_next(it)) { if (!it->data)continue; if (it->data == body)continue; /*check for collision*/ other = (Body *)it->data; vec3d_cpy(b,other->position); b.w = other->bounds.w; b.h = other->bounds.h; b.d = other->bounds.d; vec3d_add(b,b,other->bounds); if (cube_cube_intersection(a,b)) { /*call touch functions*/ /*back the f**k off*/ //vec3d_cpy(body->_stepOffVector,stepOffVector); //body->_done = 1; // body->_needsBackoff = 1; if (body->touch.function) { body->touch.function(body->touch.data,other); } } } }
void body_process(Body *body) { if (!body)return; if (body->_needsBackoff) { vec3d_add(body->position,body->position,body->_stepOffVector); } }
/** Updates the camera. */ Camera * camera_update(Camera * self, double dt) { ALLEGRO_DISPLAY *display = al_get_current_display(); double dw = al_get_display_width(display); double dh = al_get_display_height(display); double f = tan(self->field_of_view / 2.0); /* Set up orthograĥic transform for UI, etc. */ al_identity_transform(&self->orthographic_transform); al_orthographic_transform(&self->orthographic_transform, 0, 0, -1, dw, dh, 1000); /* Perspective transform for the main screen 3D view. */ al_identity_transform(&self->perspective_transform); /* Back up camera a bit. */ /* Set up a nice 3D view. */ al_translate_transform_3d(&self->perspective_transform, 0, 0, -1); al_perspective_transform(&self->perspective_transform, -1 * dw / dh * f, f, 1, f * dw / dh, -f, 1000); /* al_perspective_transform(&projection, -1 * dw / dh * f, f, 1, f * dw / dh, -f, 1000); */ /* Set up the camera's position and view transform. */ /* al_build_camera_transform(&self->camera_transform, self->position.x, self->position.y, self->position.z, self->look.x , self->look.y , self->look.z , self->up.x , self->up.y , self->up.z ); */ al_identity_transform(&self->camera_transform); al_translate_transform_3d(&self->camera_transform, self->position.x, self->position.y, self->position.z); al_rotate_transform_3d(&self->camera_transform, 0, -1, 0, self->alpha); al_rotate_transform_3d(&self->camera_transform, -1, 0, 0, self->theta); /* Finally move at the set speed. */ self->position = vec3d_add(self->position, vec3d_mul(self->speed, dt)); return self; }
void mouse_draw_3d_ray() { Vec3D position,vector, position2; mouse_get_3d_ray(&position,&vector); vec3d_scale(vector,vector,100); vec3d_add(position2,position,vector); draw_dot_3D(position, 4, vec3d(1,0,0), 1); draw_line_3D(position, position2, 2, vec3d(0,1,0), 1); draw_dot_3D(position2, 7, vec3d(0,0,1), 1); }
int main(int argc, char *argv[]) { int i; float r = 0; Space *space; Entity *cube1,*cube2; char bGameLoopRunning = 1; Vec3D cameraPosition = {-10,3,0}; Vec3D cameraRotation = {180,0,180}; SDL_Event e; Obj *bgobj; Sprite *bgtext; //my variables Ship *playerShip; int specMode; init_logger("gametest3d.log"); if (graphics3d_init(1024,768,1,"gametest3d",33) != 0) { return -1; } model_init(); obj_init(); entity_init(255); initShips(); bgobj = obj_load("models/mountainvillage.obj"); bgtext = LoadSprite("models/mountain_text.png",1024,1024); //cube1 = newCube(vec3d(0,0,0),"Cubert"); //cube2 = newCube(vec3d(10,0,0),"Hobbes"); //cube1->body.velocity.x = 0.1; space = space_new(); space_set_steps(space,100); space_add_body(space,&cube1->body); space_add_body(space,&cube2->body); //my variables specMode = 0; numShips = 0; shipVel = 0; shipRot = 0; turretRot = 0; gunElev = 0; realTurrRot = 0; playerShip = spawnShip(space, vec3d(-10,0,0), 1); while (bGameLoopRunning) { updateAllShipPos(); for (i = 0; i < 100;i++) { space_do_step(space); } updateAllShipComp(); applyGrav(); if(specMode == 0) { cameraPosition.x = playerShip->hull->body.position.x; cameraPosition.y = (playerShip->hull->body.position.y + 5); cameraPosition.z = playerShip->hull->body.position.z; } while ( SDL_PollEvent(&e) ) { if (e.type == SDL_QUIT) { bGameLoopRunning = 0; } else if (e.type == SDL_KEYDOWN) { if (e.key.keysym.sym == SDLK_ESCAPE) { bGameLoopRunning = 0; } else if (e.key.keysym.sym == SDLK_SPACE) { cameraPosition.z++; } else if (e.key.keysym.sym == SDLK_z) { cameraPosition.z--; } else if (e.key.keysym.sym == SDLK_w) { vec3d_add( cameraPosition, cameraPosition, vec3d( -sin(cameraRotation.z * DEGTORAD), cos(cameraRotation.z * DEGTORAD), 0 )); } else if (e.key.keysym.sym == SDLK_s) { vec3d_add( cameraPosition, cameraPosition, vec3d( sin(cameraRotation.z * DEGTORAD), -cos(cameraRotation.z * DEGTORAD), 0 )); } else if (e.key.keysym.sym == SDLK_d) { vec3d_add( cameraPosition, cameraPosition, vec3d( cos(cameraRotation.z * DEGTORAD), sin(cameraRotation.z * DEGTORAD), 0 )); } else if (e.key.keysym.sym == SDLK_a) { vec3d_add( cameraPosition, cameraPosition, vec3d( -cos(cameraRotation.z * DEGTORAD), -sin(cameraRotation.z * DEGTORAD), 0 )); } else if (e.key.keysym.sym == SDLK_LEFT) { cameraRotation.y -= 1; } else if (e.key.keysym.sym == SDLK_RIGHT) { cameraRotation.y += 1; } else if (e.key.keysym.sym == SDLK_UP) { cameraRotation.x += 1; } else if (e.key.keysym.sym == SDLK_DOWN) { cameraRotation.x -= 1; } else if (e.key.keysym.sym == SDLK_y && shipVel < 0.4) { shipVel += 0.1; } else if (e.key.keysym.sym == SDLK_h && shipVel > 0.05) { shipVel -= 0.1; } else if (e.key.keysym.sym == SDLK_j) { shipRot += 0.5; if(shipRot >= 360){shipRot -= 360;} } else if (e.key.keysym.sym == SDLK_g) { shipRot -= 0.5; if(shipRot < 0){shipRot += 360;} } else if (e.key.keysym.sym == SDLK_m && turretRot < 135) { turretRot += 1; } else if (e.key.keysym.sym == SDLK_b && turretRot > -135) { turretRot -= 1; } else if (e.key.keysym.sym == SDLK_o && gunElev < 50) { gunElev += 0.5; } else if (e.key.keysym.sym == SDLK_l && gunElev > -5) { gunElev -= 0.5; } else if (e.key.keysym.sym == SDLK_q) { if(specMode == 0){specMode = 1;} else {specMode = 0;} } else if (e.key.keysym.sym == SDLK_p) { fireBullet(space, playerShip->gun->body.position, realTurrRot, gunElev, 0.5, -1); } else if (e.key.keysym.sym == SDLK_x) { fireBullet(space, playerShip->hull->body.position, shipRot, 0, 0, -2); } else if (e.key.keysym.sym == SDLK_1) { startLevel(space, 1); } else if (e.key.keysym.sym == SDLK_2) { startLevel(space, 2); } else if (e.key.keysym.sym == SDLK_3) { startLevel(space, 3); } } } graphics3d_frame_begin(); glPushMatrix(); set_camera( cameraPosition, cameraRotation); entity_draw_all(); //updateAllShipModels(); obj_draw( bgobj, vec3d(0,0,2), vec3d(90,90,0), vec3d(5,5,5), vec4d(1,1,1,1), bgtext ); if (r > 360)r -= 360; glPopMatrix(); /* drawing code above here! */ graphics3d_next_frame(); } return 0; }
int main(int argc, char *argv[]) { int i; float r = 0; int f = -15; int g = 0; int l = 0; int y = 0; int u = 15; int q = 0; int gamestate=0; int PlayerHP=15, Bosshealth=30, enemy1health=5, enemy2health=5, Bigtimer=600, CD; int SpawnLemon1=0, SpawnLemon2=0, SpawnLemon3=0, SpawnBigLemon=0, enemybullet=0; float Lemonx1=0, Lemonx2=0, Lemonx3=0, LemonxBig=0, enemybulletx=0; int Lemony1=0, Lemony2=0, Lemony3=0, LemonyBig=0, enemybullety=0; int a=0, b=0, c=0, d=0, count, Goomba_attack1=0, Goomba_attack2=0, Goomba_move1, Goomba_move2; Space *space; Entity *cube1,*cube2, *Actor; char bGameLoopRunning = 1; Vec3D Bosspos = {u, y, 2}; Vec3D enemy1pos = {5, 10, 2}; Vec3D enemy2pos = {5, -10, 2}; Vec3D cameraPosition = {0,0,70.3}; Vec3D cameraRotation = {0,0,360}; SDL_Event e; Obj *megaman,*boss, *mapp, *mape, *lemon, *BossHPBar, *PlayerHPBar, *Goomba; Sprite *megamantexture, *bosstexture, *maptexture1, *maptexture2, *lemontexture, *BosstextureHP, *PlayertextureHP, *Goombatexture; init_logger("gametest3d.log"); if (graphics3d_init(1024,768,1,"gametest3d",33) != 0) { return -1; } model_init(); obj_init(); entity_init(255); //load objects, models here, replace cube with megaman megaman = obj_load("models/MPU.obj"); //load his uv map "texture file" megamantexture = LoadSprite("models/MegaManBody1.png",1024,1024); PlayerHPBar = obj_load("models/cube.obj"); PlayertextureHP = NULL; boss = obj_load("models/Fireman.obj"); bosstexture = LoadSprite("models/FireManBody1.png",1024,1024); BossHPBar = obj_load("models/cube.obj"); BosstextureHP = NULL; Goomba = obj_load("models/goomba.obj"); Goombatexture = LoadSprite("models/goomba_tex.png",1024,1024); mapp = obj_load("models/MidtermMapSingle.obj"); maptexture1 = LoadSprite("models/PlayerTile(Red).png",1024,1024); mape = obj_load("models/MidtermMapSingle.obj"); maptexture2 = LoadSprite("models/BossTile(Blue).png",1024,1024); lemon = obj_load("models/cube.obj"); lemontexture = NULL;//LoadSprite("models/cube_text.png",1024,1024); while (bGameLoopRunning) { entity_think_all(); while ( SDL_PollEvent(&e) ) { if (e.type == SDL_QUIT) { bGameLoopRunning = 0; } else if (e.type == SDL_KEYDOWN) { if (e.key.keysym.sym == SDLK_ESCAPE) { bGameLoopRunning = 0; } else if (e.key.keysym.sym == SDLK_x) { cameraPosition.z++; } else if (e.key.keysym.sym == SDLK_z) { cameraPosition.z--; } else if (e.key.keysym.sym == SDLK_h) { vec3d_add( cameraPosition, cameraPosition, vec3d( -sin(cameraRotation.z * DEGTORAD), cos(cameraRotation.z * DEGTORAD), 0 )); } else if (e.key.keysym.sym == SDLK_y) { vec3d_add( cameraPosition, cameraPosition, vec3d( sin(cameraRotation.z * DEGTORAD), -cos(cameraRotation.z * DEGTORAD), 0 )); } else if (e.key.keysym.sym == SDLK_j) { vec3d_add( cameraPosition, cameraPosition, vec3d( cos(cameraRotation.z * DEGTORAD), sin(cameraRotation.z * DEGTORAD), 0 )); } else if (e.key.keysym.sym == SDLK_g) { vec3d_add( cameraPosition, cameraPosition, vec3d( -cos(cameraRotation.z * DEGTORAD), -sin(cameraRotation.z * DEGTORAD), 0 )); } else if (e.key.keysym.sym == SDLK_d) { if(f >= -5) { f = -5; } else { f += 10; } } else if (e.key.keysym.sym == SDLK_a) { if(f <= -20) { f = -25; } else { f -= 10; } } else if (e.key.keysym.sym == SDLK_w) { if(g >= 5) { g = 10; } else { g += 10; } } else if (e.key.keysym.sym == SDLK_s) { g -= 10; if(g <= -5) { g = -10; } } else if (e.key.keysym.sym == SDLK_LEFT) { cameraRotation.z += 1; } else if (e.key.keysym.sym == SDLK_RIGHT) { cameraRotation.z -= 1; } else if (e.key.keysym.sym == SDLK_UP) { cameraRotation.x += 1; } else if (e.key.keysym.sym == SDLK_DOWN) { cameraRotation.x -= 1; } else if (e.key.keysym.sym == SDLK_SPACE) { CD = TIME + Bigtimer; } else if (e.key.keysym.sym == SDLK_n) { if (enemy1health <= 0 && enemy2health <= 0) { gamestate=1; } } else if (e.key.keysym.sym == SDLK_n) { if (enemy1health <= 0 && enemy2health <= 0) { gamestate=1; } } } else if (e.type == SDL_KEYUP) { if (e.key.keysym.sym == SDLK_SPACE) { if (TIME >= CD && SpawnBigLemon !=1) { SpawnBigLemon = 1; LemonxBig = f; LemonyBig = g; } else if (SpawnLemon1 != 1) { SpawnLemon1 = 1; Lemonx1 = f; Lemony1 = g; } else if (SpawnLemon2 != 1) { SpawnLemon2 = 1; Lemonx2 = f; Lemony2 = g; } else if (SpawnLemon3 != 1) { SpawnLemon3 = 1; Lemonx3 = f; Lemony3 = g; } } } } graphics3d_frame_begin(); glPushMatrix(); set_camera( cameraPosition, cameraRotation); //entity_draw_all(); if (PlayerHP > 0 ) { //Megaman obj_draw( megaman, vec3d(f, g, 2), vec3d(90,90,0), vec3d(0.5,0.5,0.5), vec4d(1,1,1,1), megamantexture ); //Megaman HP BAR obj_draw( PlayerHPBar, vec3d(-30+PlayerHP/(2),20,2), vec3d(90,-90,0), vec3d(.9,.9,PlayerHP/(2)), vec4d(0,1,0,1), PlayertextureHP ); } //Megaman Projectiles //Lemon1 if (SpawnLemon1 != 0) { obj_draw( lemon, vec3d(Lemonx1 + a*(.4), Lemony1, 4), vec3d(90,90,0), vec3d(1,1,2), vec4d(.95,.89,0,1), lemontexture ); a++; if (Lemonx1 + a*(.4) >=30) { SpawnLemon1 = 0; a=0; } else if (Lemonx1 + a*(.4) == enemy1pos.x && Lemony1 == enemy1pos.y) { SpawnLemon1 = 0; a=0; enemy1health -= 1; //slog("Enemy Health %d",enemy1health); } else if (Lemonx1 + a*(.4) == enemy2pos.x && Lemony1 == enemy2pos.y) { SpawnLemon1 = 0; a=0; enemy2health -= 1; //slog("Enemy Health %d",enemy2health); } else if (gamestate == 1 && Lemonx1 + a*(.4) == Bosspos.x && Lemony1 == Bosspos.y) { SpawnLemon1 = 0; a=0; Bosshealth -= 1; //slog("Boss Health %d",Bosshealth); } } //Lemon2 if (SpawnLemon2 != 0) { obj_draw( lemon, vec3d(Lemonx2 + b*(.4), Lemony2, 4), vec3d(90,90,0), vec3d(1,1,2), vec4d(.95,.89,0,1), lemontexture ); b++; if (Lemonx2 + b*(.4) >=30) { SpawnLemon2 = 0; b=0; } else if (Lemonx2 + b*(.4) == enemy1pos.x && Lemony2 == enemy1pos.y) { SpawnLemon2 = 0; b=0; enemy1health -= 1; //slog("Enemy Health %d",enemy1health); } else if (Lemonx2 + b*(.4) == enemy2pos.x && Lemony2 == enemy2pos.y) { SpawnLemon2 = 0; b=0; enemy2health -= 1; //slog("Enemy Health %d",enemy2health); } else if (gamestate == 1 && Lemonx2 + b*(.4) == Bosspos.x && Lemony2 == Bosspos.y) { SpawnLemon2 = 0; b=0; Bosshealth -= 1; //slog("Boss Health %d",Bosshealth); } } if (SpawnLemon3 != 0) { obj_draw( lemon, vec3d(Lemonx3 + c*(.4), Lemony3, 4), vec3d(90,90,0), vec3d(1,1,2), vec4d(.95,.89,0,1), lemontexture ); c++; //lemons fly off staege if (Lemonx3 + c*(.4) >=30) { SpawnLemon3 = 0; c=0; } //lemons collide with enemies else if (Lemonx3 + c*(.4) == enemy1pos.x && Lemony3 == enemy1pos.y) { SpawnLemon3 = 0; c=0; enemy1health -= 1; slog("Enemy Health %d",enemy1health); } else if (Lemonx3 + c*(.4) == enemy2pos.x && Lemony3 == enemy2pos.y) { SpawnLemon3 = 0; c=0; enemy2health -= 1; slog("Enemy Health %d",enemy2health); } else if (gamestate == 1 && Lemonx3 + c*(.4) == Bosspos.x && Lemony3 == Bosspos.y) { SpawnLemon3 = 0; c=0; Bosshealth -= 1; //slog("Boss Health %d",Bosshealth); } } if (SpawnBigLemon != 0) { obj_draw( lemon, vec3d(LemonxBig + d*(.4), LemonyBig, 4), vec3d(90,90,0), vec3d(2,2,4), vec4d(.9,.3,.1,1), lemontexture ); d++; if (LemonxBig + d*(.4) >=30) { SpawnBigLemon = 0; d=0; } else if (LemonxBig + d*(.4) == enemy1pos.x && LemonyBig == enemy1pos.y) { SpawnBigLemon = 0; d=0; enemy1health -= 5; //slog("Enemy Health %d",enemy1health); } else if (LemonxBig + d*(.4) == enemy2pos.x && LemonyBig == enemy2pos.y) { SpawnBigLemon = 0; d=0; enemy2health -= 5; //slog("Enemy Health %d",enemy2health); } else if (gamestate == 1 && LemonxBig + d*(.4) == Bosspos.x && LemonyBig == Bosspos.y) { SpawnBigLemon = 0; d=0; Bosshealth -= 5; slog("Boss Health %d",Bosshealth); } } //MAP obj_draw( mapp, vec3d(-15,0,2), vec3d(90,90,0), vec3d(5,5,5), vec4d(1,1,1,1), maptexture1 ); obj_draw( mape, vec3d(15,0,2), vec3d(90,90,0), vec3d(5,5,5), vec4d(1,1,1,1), maptexture2 ); //Enemies if (gamestate == 0) { if (enemy1health > 0) { //enemy_move(enemypos.x,enemypos.y, &enemypos); //enemy_attack1(Goomba_attack1, &enemy1pos); obj_draw( Goomba, vec3d(enemy1pos.x,enemy1pos.y,2), vec3d(90,-90,0), vec3d(0.1,0.1,0.1), vec4d(1,1,1,1), Goombatexture ); if (Goomba_attack1 == 0) { Goomba_attack1 = rand_ranged( 1, 5); //start to (end - 1) if (Goomba_attack1 == 2) { Goomba_attack1 = 1; } }; if (Goomba_attack1 == 1) { enemy1pos.x -=.1; if (enemy1pos.x <= -30) { Goomba_attack1 = 0; enemy1pos.x = 5; } } } else { enemy1pos.x = 50; enemy1pos.y = 50; } if (enemy2health > 0) { //enemy_move(enemypos.x,enemypos.y, &enemypos); //enemy_attack2(Goomba_attack2, &enemy2pos); obj_draw( Goomba, vec3d(enemy2pos.x,enemy2pos.y,2), vec3d(90,-90,0), vec3d(0.1,0.1,0.1), vec4d(1,1,1,1), Goombatexture ); //bottom Goomba won't attack if (Goomba_attack2 == 0) { Goomba_attack2 = rand_ranged( 1, 5); //start to (end - 1) if (Goomba_attack2 == 2) { Goomba_attack2 = 1; } }; if (Goomba_attack2 == 1) { enemy2pos.x -=.1; if (enemy2pos.x <= -30) { Goomba_attack2 = 0; enemy2pos.x = 5; } } } else { enemy2pos.x = 50; enemy2pos.y = 50; } } if (gamestate != 0) { if (Bosshealth > 0) { Boss_move(Bosspos.x,Bosspos.y, &Bosspos); //Fire man obj_draw( boss, vec3d(Bosspos.x,Bosspos.y,2), vec3d(90,-90,0), vec3d(0.5,0.5,0.5), vec4d(1,1,1,1), bosstexture ); obj_draw( BossHPBar, vec3d(30-Bosshealth/(2.5),20,2), vec3d(90,-90,0), vec3d(.9,.9,Bosshealth/(2.5)), vec4d(1,0,0,1), BosstextureHP ); } else { obj_free(boss); Bosspos.x = 50; Bosspos.y = 50; slog("You WIN!"); } } if (r > 360)r -= 360; glPopMatrix(); /* drawing code above here! */ graphics3d_next_frame(); } return 0; }
Vec3d Particle_to_mesh_map::force_on_particle( Spatial_mesh &spat_mesh, Particle &p ) { double dx = spat_mesh.x_cell_size; double dy = spat_mesh.y_cell_size; double dz = spat_mesh.z_cell_size; int tlf_i, tlf_j, tlf_k; // 'tlf' = 'top_left_far' double tlf_x_weight, tlf_y_weight, tlf_z_weight; Vec3d field_from_node, total_field, force; // next_node_num_and_weight( vec3d_x( p.position ), dx, &tlf_i, &tlf_x_weight ); next_node_num_and_weight( vec3d_y( p.position ), dy, &tlf_j, &tlf_y_weight ); next_node_num_and_weight( vec3d_z( p.position ), dz, &tlf_k, &tlf_z_weight ); // tlf total_field = vec3d_zero(); field_from_node = vec3d_times_scalar( spat_mesh.electric_field[tlf_i][tlf_j][tlf_k], tlf_x_weight ); field_from_node = vec3d_times_scalar( field_from_node, tlf_y_weight ); field_from_node = vec3d_times_scalar( field_from_node, tlf_z_weight ); total_field = vec3d_add( total_field, field_from_node ); // trf field_from_node = vec3d_times_scalar( spat_mesh.electric_field[tlf_i-1][tlf_j][tlf_k], 1.0 - tlf_x_weight ); field_from_node = vec3d_times_scalar( field_from_node, tlf_y_weight ); field_from_node = vec3d_times_scalar( field_from_node, tlf_z_weight ); total_field = vec3d_add( total_field, field_from_node ); // blf field_from_node = vec3d_times_scalar( spat_mesh.electric_field[tlf_i][tlf_j - 1][tlf_k], tlf_x_weight ); field_from_node = vec3d_times_scalar( field_from_node, 1.0 - tlf_y_weight ); field_from_node = vec3d_times_scalar( field_from_node, tlf_z_weight ); total_field = vec3d_add( total_field, field_from_node ); // brf field_from_node = vec3d_times_scalar( spat_mesh.electric_field[tlf_i-1][tlf_j-1][tlf_k], 1.0 - tlf_x_weight ); field_from_node = vec3d_times_scalar( field_from_node, 1.0 - tlf_y_weight ); field_from_node = vec3d_times_scalar( field_from_node, tlf_z_weight ); total_field = vec3d_add( total_field, field_from_node ); // tln field_from_node = vec3d_times_scalar( spat_mesh.electric_field[tlf_i][tlf_j][tlf_k-1], tlf_x_weight ); field_from_node = vec3d_times_scalar( field_from_node, tlf_y_weight ); field_from_node = vec3d_times_scalar( field_from_node, 1.0 - tlf_z_weight ); total_field = vec3d_add( total_field, field_from_node ); // trn field_from_node = vec3d_times_scalar( spat_mesh.electric_field[tlf_i-1][tlf_j][tlf_k-1], 1.0 - tlf_x_weight ); field_from_node = vec3d_times_scalar( field_from_node, tlf_y_weight ); field_from_node = vec3d_times_scalar( field_from_node, 1.0 - tlf_z_weight ); total_field = vec3d_add( total_field, field_from_node ); // bln field_from_node = vec3d_times_scalar( spat_mesh.electric_field[tlf_i][tlf_j - 1][tlf_k-1], tlf_x_weight ); field_from_node = vec3d_times_scalar( field_from_node, 1.0 - tlf_y_weight ); field_from_node = vec3d_times_scalar( field_from_node, 1.0 - tlf_z_weight ); total_field = vec3d_add( total_field, field_from_node ); // brn field_from_node = vec3d_times_scalar( spat_mesh.electric_field[tlf_i-1][tlf_j-1][tlf_k-1], 1.0 - tlf_x_weight ); field_from_node = vec3d_times_scalar( field_from_node, 1.0 - tlf_y_weight ); field_from_node = vec3d_times_scalar( field_from_node, 1.0 - tlf_z_weight ); total_field = vec3d_add( total_field, field_from_node ); // force = vec3d_times_scalar( total_field, p.charge ); return force; }