// --------------------------------------------------------------------------- // Area smoke // --------------------------------------------------------------------------- void eff_complexSmokeSprite() { my->flags = TRANSLUCENT; my->skill1 = 50; wait(1); while(my->alpha < my->skill1) { vec_diff(&my->pan, &my->x, &camera->x); vec_to_angle(&my->pan, &my->pan); my->roll = total_ticks; my->alpha += 0.2 * time_step; wait(1); } while(my->skill2 >= total_ticks || my->skill2 < 0) { vec_diff(&my->pan, &my->x, &camera->x); vec_to_angle(&my->pan, &my->pan); my->roll = total_ticks; wait(1); } while(my->alpha > 0) { vec_diff(&my->pan, &my->x, &camera->x); vec_to_angle(&my->pan, &my->pan); my->roll = total_ticks; my->alpha -= time_step; wait(1); } }
vec_t box_intersect_vector(box_t a, box_t b){ vec_t d = vec_diff(a.pos, b.pos); vec_t r = vec_new(0,0); if (d.x >= 0){ r.x = (b.pos.x - b.size.x) - (a.pos.x + a.size.x); if ( r.x > 0) r.x = 0; }else{ r.x = (b.pos.x + b.size.x) - (a.pos.x - a.size.x); if (r.x < 0) r.x = 0; } if (d.y >= 0){ r.y = (b.pos.y - b.size.y) - (a.pos.y + a.size.y); if ( r.y > 0) r.y = 0; }else{ r.y = (b.pos.y + b.size.y) - (a.pos.y - a.size.y); if (r.y < 0) r.y = 0; } d = vec_abs(r); if(d.x > d.y){ r.x = 0; }else{ r.y = 0; } return r; }
VECTOR* handFingerPos (ENTITY* entHand, BOOL bLeftHand, int fingerId, VECTOR* vecFingerPos, VECTOR* vecFingerDir) { VECTOR vecFinger0, vecFinger1; char* j0 = _chr((g_handBoneFarNames->pstring)[fingerId]); char* j1 = _chr((g_handBoneNearNames->pstring)[fingerId]); vec_for_bone(&vecFinger0, entHand, j0); vec_for_bone(&vecFinger1, entHand, j1); if (bLeftHand) { vec_to_ent(&vecFinger0, entHand); vecFinger0.x *= -1; vec_for_ent(&vecFinger0, entHand); vec_to_ent(&vecFinger1, entHand); vecFinger1.x *= -1; vec_for_ent(&vecFinger1, entHand); } vec_lerp(vecFingerPos, &vecFinger0, &vecFinger1, 0.5); vec_diff(vecFingerDir, &vecFinger1, &vecFinger0); return vecFingerPos; }
//project a vector onto a plane void vec_project(vec_t *n, vec_t *v, vec_t *p) { vec_t *r = (vec_t *)malloc(sizeof(vec_t)); vec_scale(vec_dot(n, v), n, r); vec_diff(r, v, p); free(r); }
struct hs_vec vec_isect_a (const struct hs_vec *a, const struct hs_vec *b, int len) { struct hs_vec new_list = {0}; for (int i = 0; i < a->used; i++) { for (int j = 0; j < b->used; j++) { array_t *isect = array_isect_a (a->elems[i], b->elems[j], len); if (!isect) continue; vec_append (&new_list, isect, false); int idx = new_list.used - 1; struct hs_vec *d = &new_list.diff[idx]; vec_diff (d, isect, &a->diff[i], len); vec_diff (d, isect, &b->diff[j], len); } } return new_list; }
static double vec_dist(double *v1, double *v2) { double d[MAX_DIM]; double sqd; vec_diff(d, v1, v2); sqd = vec_sum_squares(d); return sqrt(sqd); }
int try_snooker_spot(BallsType *balls,struct Vect spot) { int i,available=1; for(i=0;i<22;i++) { if(balls->ball[i].in_game && vec_abs(vec_diff(spot,balls->ball[i].r)) < (balls->ball[i].d) + 0.001) { available=0; } } return available; }
static bot_core::robot_state_t operator-(const bot_core::robot_state_t &lhs, const bot_core::robot_state_t &rhs) { assert(lhs.num_joints==rhs.num_joints); assert(lhs.joint_name==rhs.joint_name); bot_core::robot_state_t res; // use left hand side as reference for values that are not subtracted res.utime = lhs.utime; res.num_joints = lhs.num_joints; res.joint_name = lhs.joint_name; res.pose = lhs.pose - rhs.pose; res.twist = lhs.twist - rhs.twist; res.joint_position = vec_diff(lhs.joint_position, rhs.joint_position); res.joint_velocity = vec_diff(lhs.joint_velocity, rhs.joint_velocity); res.joint_effort = vec_diff(lhs.joint_effort, rhs.joint_effort); res.force_torque = lhs.force_torque - rhs.force_torque; return res; }
// Collision detection of two boxs with arbitrary angles. // Does only one side (a->b) of the collision. // -- If no collision, then no collision.. // -- If returns collision, check the other side (b<-a) // -- A vector will be returned to displace 'a' so that there is no // no collision anymore. The vector returned is one of the normals of 'b'. static vec_t box_o_o_collision(box_t a, box_t b) { // We will perform the collision using b's point of view and axes because // those will be consided the surface normals, and we want to return 'a's' // displacement in terms of 'a's' orientation vectors. -- So this may at times look reveresed. vec_t dist = vec_diff(b.pos, a.pos); // Normalized axis of box b. One of those axes will be the surface normal. vec_t axn[2]; // = { b.axis0, b.axis1 }; float axl[2]; // Half axis length. // Half axis. vec_t ahx0 = vec_scale(a.axis0, a.size.x); vec_t ahx1 = vec_scale(a.axis1, a.size.y); // Distance we need to displace 'a' to remove the collision. // -- (0, 0) => no collision. float col_vec[2] = { 0.0, 0.0 }; int i = 2; axn[0] = b.axis0; axn[1] = b.axis1; axl[0] = b.size.x; axl[1] = b.size.y; while(i--) { float a1, a2, d; // We check if the distance from center to center is smaller // than the sum of the distance from center to box edge // and that projection along each vector normal. // If it is false for one normal, we have no collision. // Otherwise we have the displacement distance to remove the collision. a1 = vec_absdot(axn[i], ahx0); a2 = vec_absdot(axn[i], ahx1); d = vec_absdot(axn[i], dist); col_vec[i] = a1 + a2 + axl[i] - d; if(col_vec[i] <= 0) { // Then there was no intersection. return vec_new(0, 0); } } if(col_vec[0] < col_vec[1]) { if(vec_dot(dist, axn[0]) > 0) { return vec_scale(axn[0], col_vec[0]); } else { return vec_scale(axn[0], -col_vec[0]); } } else { if(vec_dot(dist, axn[1]) > 0) { return vec_scale(axn[1], col_vec[1]); } else { return vec_scale(axn[1], -col_vec[1]); } } }
vprop_t vprop_animate(vprop_t vp, float dt){ vec_t s; if (!(vp.speed == 0.0 || vec_equal(vp.val,vp.target))){ s = vec_scale(vec_normalize(vec_diff(vp.val,vp.target)),vp.speed); if(vec_dist(vp.val,vp.target) < vec_len(s)){ vp.val = vp.target; }else{ vp.val = vec_add(vp.val,s); } } return vp; }
//reflect a vector from a surface plane] void vec_reflect(vec_t *n, vec_t *w, vec_t *v) { vec_t *u = (vec_t *)malloc(sizeof(vec_t)); vec_unit(w, u); vec_scale(-1, u, u); vec_scale((2*vec_dot(u, n)), n, v); vec_diff(u, v, v); free(u); }
void tracer_prep(raytracer *tracer,mcconfig *cfg){ if(tracer->n==NULL && tracer->m==NULL && tracer->d==NULL){ if(tracer->mesh!=NULL) tracer_build(tracer); else MESH_ERROR("tracer is not associated with a mesh"); }else if(cfg->srctype==stPencil && cfg->dim.x>0){ int eid=cfg->dim.x-1; float3 vecS={0.f}, *nodes=tracer->mesh->node, vecAB, vecAC, vecN; int i,ea,eb,ec; float s=0.f, *bary=&(cfg->bary0.x); int *elems=(int *)(tracer->mesh->elem+eid); // convert int4* to int* for(i=0;i<4;i++){ ea=elems[out[i][0]]-1; eb=elems[out[i][1]]-1; ec=elems[out[i][2]]-1; vec_diff(&nodes[ea],&nodes[eb],&vecAB); vec_diff(&nodes[ea],&nodes[ec],&vecAC); vec_diff(&nodes[ea],&(cfg->srcpos),&vecS); vec_cross(&vecAB,&vecAC,&vecN); bary[facemap[i]]=-vec_dot(&vecS,&vecN); } if(cfg->debuglevel&dlWeight) fprintf(cfg->flog,"initial bary-centric volumes [%e %e %e %e]\n", bary[0]/6.,bary[1]/6.,bary[2]/6.,bary[3]/6.); for(i=0;i<4;i++){ if(bary[i]<0.f) MESH_ERROR("initial element does not enclose the source!"); s+=bary[i]; } for(i=0;i<4;i++){ bary[i]/=s; if(bary[i]<1e-5f) cfg->dim.y=ifacemap[i]+1; } } }
//----------------------------------------------------------------------------------------------------------- // View <-> Sphere BUGGY //----------------------------------------------------------------------------------------------------------- int sc_physics_intersectViewSphere(VIEW* inView,VECTOR* inPos,var inRadius) { VECTOR vcTemp1,vcTemp2,vcTemp3; vec_zero(vcTemp1); vec_zero(vcTemp2); vec_zero(vcTemp3); var vTemp1=0; var vTemp2=0; var vTemp3=0; vec_for_angle(vcTemp1,inView.pan); vec_diff(vcTemp2,inPos,inView.x); vTemp1=vec_dot(vcTemp1,vcTemp2); vec_set(vcTemp3,inView.x); vec_scale(vcTemp1,vTemp1); vec_add(vcTemp3,vcTemp1); vec_diff(vcTemp1,inPos,vcTemp3); vTemp2=vec_length(vcTemp1); vTemp1=tanv(atanv( sqrt(2) * tanv(inView.arc/2) ))*vTemp1; return (vTemp2-vTemp1>inRadius); /* VECTOR viewDir; vec_for_angle(viewDir, inView.pan); //vec_scale(viewDir, 5); return sc_physics_intersectConeSphere (inView.x, viewDir, inView.arc, inPos, inRadius ); */ }
void next_position(int *steps) { double newp[MAX_DIM]; double err[MAX_DIM]; int i; tim += 1.0; vec_mul_scalar(newp, incvec, tim); vec_sum(newp, newp, origin); vec_diff(err, newp, position); for (i = 0; i < MAX_DIM; i++) { steps[i] = (int)err[i]; position[i] += (double)steps[i]; } }
/* Function compute_clustering. * This function recomputes the clustering based on the current means. * * Inputs: * n : number of input descriptors * dim : dimension of each input descriptor * k : number of means * v : array of pointers to dim-dimensional descriptors * means : current means, stored in a k*dim dimensional array * * Output: * clustering : new assignment of descriptors to nearest means * (should range between 0 and k-1) * error_out : total error of the new assignment * * Return value : return the number of points that changed assignment */ int compute_clustering(int n, int dim, int k, unsigned char **v, double *means, unsigned int *clustering, double &error_out) { int i; double error = 0.0; int changed = 0; double *vec = (double *) malloc(sizeof(double) * dim); double *work = (double *) malloc(sizeof(double) * dim); for (i = 0; i < n; i++) { fill_vector(vec, v[i], dim); int j; double min_dist = DBL_MAX; unsigned int cluster = 0; for (j = 0; j < k; j++) { vec_diff(dim, vec, means + j * dim, work); double dist = vec_normsq(dim, work); if (dist < min_dist) { min_dist = dist; cluster = j; } } error += min_dist; if (clustering[i] != cluster) changed++; clustering[i] = cluster; } free(vec); free(work); error_out = error; return changed; }
void create_carambol_scene( BallsType * balls ) { int i; myvec vdummy; balls->gametype=GAME_CARAMBOL; /* balls */ balls->nr=3; if( balls->ball != NULL ) billard_free( balls->ball ); balls->ball = billard_malloc(sizeof(BallType)*balls->nr); placecarambolballnrs(balls); for(i=0;i<balls->nr;i++){ balls->ball[i].nr=i; } for(i=0;i<balls->nr;i++){ balls->ball[i].m=BALL_M; /* I_kugel = (m.r^2)2/5 = (m.d^2)/10 */ balls->ball[i].I=BALL_M*BALL_D*BALL_D/10.0/**0.01*/; balls->ball[i].d=BALL_D; balls->ball[i].v=vec_xyz(0.0,0.0,0.0); balls->ball[i].w=vec_xyz(0.0,0.0,0.0); balls->ball[i].b[0]=vec_unit(vec_xyz(rand(),rand(),rand())); vdummy=vec_xyz(rand(),rand(),rand()); balls->ball[i].b[1]=vec_unit(vec_diff(vdummy,vec_proj(vdummy,balls->ball[i].b[0]))); balls->ball[i].b[2]=vec_cross(balls->ball[i].b[0],balls->ball[i].b[1]); balls->ball[i].in_game=1; balls->ball[i].in_hole=0; balls->ball[i].soundplayed=0; } /* white ball */ balls->ball[0].r = vec_xyz( TABLE_W/4.0, -TABLE_L/4.0, 0.0 ); balls->ball[1].r = vec_xyz( 0.0, -TABLE_L/4.0, 0.0 ); balls->ball[2].r = vec_xyz( 0.0, +TABLE_L/4.0, 0.0 ); for( i=0 ; i<balls->nr ; i++ ){ balls->ball[i].path=0; balls->ball[i].pathcnt=0; balls->ball[i].pathsize=0; } }
void set_destination(double *v) { int i; double dif[MAX_DIM]; vec_copy(origin, position); vec_copy(destination, v); tim = 0.0; delta_t = feedrate_begin; dist = vec_dist(position, v); if(dist == 0.0) { vec_clear(incvec); for(i = 0; i < MAX_DIM; i++) amp[i] = amplitude_dc; return; } vec_diff(dif, v, origin); for(i = 0; i < MAX_DIM; i++) incvec[i] = dif[i] / dist; calc_amplitude(); }
void gameOver() { isGameOver = 1; endIngameGUI(); ent_remove(player); panGameOver.pos_x = screen_size.x / 2 - bmap_width(bmapGameOver) / 2; panGameOver.pos_y = screen_size.y / 2 - bmap_height(bmapGameOver) / 2; set(panGameOver, SHOW); vec_set(vecCamTmp, entHut.x); int counter = 1000; while(counter > 0) { cam_angle +=0.005 * time_step; camera.x = cos(cam_angle) * 768; camera.y = sin(cam_angle) * 768; vec_diff(vecCamTmp.x, nullvector, camera.x); vec_to_angle(camera.pan, vecCamTmp); counter--; wait(1); } reset(panGameOver, SHOW); isGameOver = 2; //backToMenu(); }
float vec_dist(vec_t a,vec_t b){ return vec_len(vec_diff(a,b)); }
/** * Collision detection of two box with arbitrary angles. Does * only one side (a->b) of the collision. * if it returns no collision -> no collision * if it returns a collision -> check the other side (b<-a) * It will return a vector to displace a so that there is no collision * anymore. the vector returned is one of the normals of b. */ static vec_t box_o_o_collision(box_t a, box_t b){ /* we will perform the collision using b point of view and axis * because those will be considered the surface normals, and we * want to return 'a' displacement in terms of 'b' surface normals * and not in terms of 'a' orientation vectors. * that's why the logic looks reverse at times * */ vec_t dist = vec_diff(b.pos,a.pos); /* normalized axis of the box b. One of those axis will be the * surface normal. */ vec_t axn[2]; /* = {b.axis0, b.axis1}; */ float axl[2]; /* half axis length */ /* a half axis */ vec_t ahx0 = vec_scale(a.axis0,a.size.x); vec_t ahx1 = vec_scale(a.axis1,a.size.y); /*distance we need to displace a to remove the collision. * (0,0) => no collision*/ float col_vec[2] = { 0.0, 0.0 }; int i = 2; axn[0] = b.axis0; axn[1] = b.axis1; axl[0] = b.size.x; axl[1] = b.size.y; while(i--){ float a1,a2,d; /* we check if the distance from center to center is smaller * than the sum of the distance from center to box edges. * and that projected along each vector normal. * If it is false for one normal, we have no collision. * otherwise we have the displacement distance to remove * the collision. */ a1 = vec_absdot(axn[i],ahx0); a2 = vec_absdot(axn[i],ahx1); d = vec_absdot(axn[i],dist); col_vec[i] = a1 + a2 + axl[i] - d; if(col_vec[i] <= 0){ /* No intersection ! */ return vec_new(0,0); } /*printf("a1:%f\t,a2:%f\t,b1:%f\t,d:%f\tr:%f\n", a1,a2,axl[i],d,col_vec[i] );*/ } /* col_vec has the distance we need to displace 'a' along axn[0],axn[1] * to remove the collision. We now need to pick the shortest * distance and the right direction. * This is just choosing smallest dist and flipping normals if * necessary. */ if(col_vec[0] < col_vec[1]){ if(vec_dot(dist,axn[0]) > 0 ){ return vec_scale(axn[0], col_vec[0]); }else{ return vec_scale(axn[0],-col_vec[0]); } }else{ if(vec_dot(dist,axn[1]) > 0){ return vec_scale(axn[1], col_vec[1]); }else{ return vec_scale(axn[1],-col_vec[1]); } } }
int box_intersect(box_t a, box_t b){ vec_t d = vec_abs(vec_diff(a.pos, b.pos)); return (d.x < a.size.x + b.size.x) && (d.y < a.size.y + b.size.y); }
void ebHandJoint () { set(my, INVISIBLE); vec_scale(my->scale_x, 2); c_updatehull(my, 0); VECTOR v0, v1, v, diff; BOOL isChopped = false; while (1) { updateHandChopped(g_ebHand); int myid = (int)my->skill1; if (myid % 2 == 0) set(my, FLAG2); if (g_ebHand != NULL) { if (g_ebHand->skill1 != 1) break; BOOL bLeftHand = (g_ebHand->skill20 != 0); int fingerId = myid; VECTOR vecFingerPos, vecFingerDir; handFingerPos(g_ebHand, bLeftHand, fingerId, &vecFingerPos, &vecFingerDir); vecFingerPos.y = player->y; vecFingerPos.z -= 32; vec_diff(&diff, &vecFingerPos, my->x); var distplayer = absv(my->x - player->x); if (g_handDropping && vec_length(&diff) > 2) { var distmove = c_move(my, NULL, &diff, IGNORE_PASSABLE | IGNORE_SPRITES | IGNORE_FLAG2); if (g_ebHand->skill2 != 0 && distmove <= 0 && (distplayer < my->max_x * 1.25)) player->PL_HEALTH = 0; } else { if (!g_handDropping && !g_fingerChopped) { if (distplayer < my->max_x * 2) { if (g_playerIsAttacking) { set(my, PASSABLE); if (bLeftHand) // left g_handChopL[my->skill1] = true; else // right g_handChopR[my->skill1] = true; isChopped = true; g_fingerChopped = true; doChopped(g_ebHand, g_ebHand->skill20, my->skill1); updateHandChopped(g_ebHand); ebDoCrazyness(); ebDoHit(); break; } } } } } wait(1); } ptr_remove(my); }
void BSplineSurf::recalcCoords(float ds,float dt) { float s,t; float out[3]; int ns,nt; myVector<float> sv; myVector<float> tv; for (s=U[0]; s<U[1]; s+=ds) { sv.append(s); } sv.append(U[1]); for (t=V[0]; t<V[1]; t+=dt) { tv.append(t); } tv.append(V[1]); total_coords=sv.length()*tv.length(); coords=(float(*)[3])malloc(total_coords*sizeof(float[3])); total_coords=0; for (ns=0; ns<sv.length(); ns++) { s=sv.at(ns); for (nt=0; nt<tv.length(); nt++) { t=tv.at(nt); getParamPoint(s,t,coords[total_coords]); total_coords++; } } myVector<int> N; int striplen; for (ns=0; ns<sv.length()-1; ns++) { N.append(0); striplen=N.length()-1; for (nt=0; nt<tv.length(); nt++) { N.append(nt+tv.length()*ns); N.append(nt+ tv.length()*(ns+1)); } N.at(striplen)=tv.length()*2; } N.append(0); free(strip); strip=(int*)malloc(N.length()*sizeof(int)); memcpy(strip,N.getData(),N.length()*sizeof(int)); free(normals); normals=(float(*)[3])calloc(total_coords,sizeof(float[3])); int *ar,totta,k; ar=strip; while (ar[0]) { totta=ar[0]; ar++; for (k=2; k<totta; k++) { float g1[3],g2[3],g3[3]; vec_diff(g1,coords[ ar[k-2] ],coords[ ar[k-1] ]); vec_diff(g2,coords[ ar[k-1] ],coords[ ar[k] ]); vec_cross_product(g3,g1,g2); vec_normalize(g3); if (k&1) { vec_flip(g3,g3); } vec_sum(normals[ ar[k] ],normals[ ar[k] ],g3); if (k==2) { vec_sum(normals[ ar[0] ],normals[ ar[0] ],g3); vec_sum(normals[ ar[1] ],normals[ ar[1] ],g3); } } ar+=totta; } for (k=0; k<total_coords; k++) { vec_normalize(normals[k]); } }
action ebWarghost () { g_entEbWarghost = my; my->material = g_mtlBossGhost; lvlLavaSuperReset (); var deadRotate = 0; var origScale = my->scale_x; var deadScale = origScale; BOOL isSpining = false; while (1) { // pos { VECTOR vecPos; vecPos.x = my->x; vecPos.y = 1024; vecPos.z = 150; if (player != NULL) { vecPos.x = player->x; vecPos.z = player->z; } vec_lerp(my->x, my->x, &vecPos, time_step * 0.025); } // ang { VECTOR vecLookAt, vecLook; vec_set(&vecLookAt, my->x); vecLookAt.y -= 1000; if (player != NULL) { vecLookAt.x = player->x; vecLookAt.y = player->y; } vec_diff(&vecLook, &vecLookAt, my->x); vec_to_angle(my->pan, &vecLook); if (!isEbWarghostAlive()) { setPlayerControls(false); setPlayerPan(my); deadRotate += 10 * time_step; deadScale += 0.3 * time_step; g_sndEbVol = clamp(g_sndEbVol - g_sndEbVolDec * time_step, 0, 100); snd_tune(g_fhLvlLavastageSong, g_sndEbVol, 3, 0); if (!isSpining) { snd_play(g_sndBossSpin, 100, 0); snd_play(g_sndBossDeadSpeech, 100, 0); isSpining = true; } } my->pan += deadRotate; my->scale_x = my->scale_y = my->scale_z = deadScale; if (my->scale_x / origScale > 3) break; } if (g_ebDoHit) ent_animate(my, "jump", g_ebDoHitPercent, ANM_CYCLE); else ent_animate(my, "attack", total_ticks % 100, ANM_CYCLE); wait(1); } snd_play(g_sndBossSplatter, 100, 0); VECTOR vecPos, vecDir; int i, j, numVerts = ent_status(my, 0); snd_play(g_sndBossDead, 100, 0); set(my, INVISIBLE); for (i = 0; i < numVerts; i++) { vec_for_vertex(&vecPos, my, i+1); vec_diff(&vecDir, &vecPos, my->x); vec_normalize(&vecDir, 1); effEbBlood(&vecPos, &vecDir, 25+random(100), false, 1, 4 + random(4)); } while (redness < 100) { redness = clamp(redness + g_rednessInc * time_step, 0, 100); g_sndEbVol = clamp(g_sndEbVol - g_sndEbVolDec * time_step, 0, 100); snd_tune(g_fhLvlLavastageSong, g_sndEbVol, 5, 0); wait(1); } wait(-1); proc_mode = PROC_GLOBAL; ptr_remove(my); creditsInit(); }
void net_entsync(ENTITY *ent) { ent.event = net_entsync_event; ent.emask |= ENABLE_RECEIVE; ent.smask = NOSEND_ALPHA | NOSEND_AMBIENT | NOSEND_ANGLES | NOSEND_ATTACH | NOSEND_COLOR | NOSEND_FLAGS | NOSEND_FRAME | NOSEND_LIGHT | NOSEND_ORIGIN | NOSEND_SCALE | NOSEND_SKIN | NOSEND_SOUND; // Wait for network handle while(ent.client_id < 0) wait(1); ent.NET_SKILL_LERPSPEED = net_ent_default_lerpspeed; proc_mode = PROC_GLOBAL | PROC_LATE; if(ent.client_id == dplay_id) { // Controller var update = net_ent_sendrate; while(handle(ent) != NULL) { // Send entity updates update -= time_step; if(update <= 0) { // Send position if distance since last update greater the minimum send distance if(vec_dist(ent.x, ent.NET_SKILL_POS_X) > net_ent_mindist) { vec_set(ent.NET_SKILL_POS_X, ent.x); if(net_ent_flags & NET_ENT_UNRELIABLE) send_skill(ent.NET_SKILL_POS_X, SEND_VEC | SEND_ALL | SEND_UNRELIABLE); else send_skill(ent.NET_SKILL_POS_X, SEND_VEC | SEND_ALL); } if(vec_dist(ent.pan, ent.NET_SKILL_ANG_PAN) > net_ent_mindiff) { vec_set(ent.NET_SKILL_ANG_PAN, ent.pan); if(net_ent_flags & NET_ENT_UNRELIABLE) send_skill(ent.NET_SKILL_ANG_PAN, SEND_VEC | SEND_ALL | SEND_UNRELIABLE); else send_skill(ent.NET_SKILL_ANG_PAN, SEND_VEC | SEND_ALL); } update = net_ent_sendrate; } wait(1); } } else { // Receiver while(handle(ent) != NULL) { if(net_ent_lerpfactor > 0) { // Lerping vec_lerp(ent.x, ent.x, ent.NET_SKILL_POS_X, net_ent_lerpfactor); ang_lerp(ent.pan, ent.pan, ent.NET_SKILL_ANG_PAN, net_ent_lerpfactor); } else { // Linear movement VECTOR dir; vec_diff(dir, ent.NET_SKILL_POS_X, ent.x); var dist = vec_length(dir); if(dist > 0.5 * net_ent_mindist) { vec_normalize(dir, minv(ent.NET_SKILL_LERPSPEED * time_step, dist)); vec_add(ent.x, dir); } vec_set(ent.pan, ent.NET_SKILL_ANG_PAN); } wait(1); } } }
// OBB - OBB Intersection Test int sc_physics_intersectOBBOBB(SC_OBB* a, SC_OBB* b) { var EPSILON = 1; int i = 0; int j = 0; var ra = 0; var rb = 0; var R[3][3]; var AbsR[3][3]; for(i = 0; i < 3; i++) { for(j = 0; j < 3; j ++) { R[i][j] = 0; AbsR[i][j] = 0; } } // Compute rotation matrix expressing b in a’s coordinate frame for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { R[0][0] = vec_dot(a.u[i], b.u[j]); } } // Compute translation vector t var t[3]; //vec_zero(t); t[0] = 0; t[1] = 0; t[2] = 0; vec_diff(t, b.c, a.c); // Bring translation into a’s coordinate frame //t = Vector(Dot(t, a.u[0]), Dot(t, a.u[2]), Dot(t, a.u[2])); //schreibfehler ? a.u[2] -> a.u[1] ? vec_set(t, vector( vec_dot(t, a.u[0]), vec_dot(t, a.u[1]), vec_dot(t, a.u[2]) )); // Compute common subexpressions. Add in an epsilon term to // counteract arithmetic errors when two edges are parallel and // their cross product is (near) null (see text for details) for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { AbsR[i][j] = abs(R[i][j]) + EPSILON; } } // Test axes L = A0, L = A1, L = A2 for (i = 0; i < 3; i++) { ra = a.e[i]; rb = b.e[0] * AbsR[i][0] + b.e[1] * AbsR[i][1] + b.e[2] * AbsR[i][2]; if (abs(t[i]) > ra + rb) return 0; } // Test axes L = B0, L = B1, L = B2 for (i = 0; i < 3; i++) { ra = a.e[0] * AbsR[0][i] + a.e[1] * AbsR[1][i] + a.e[2] * AbsR[2][i]; rb = b.e[i]; if (abs(t[0] * R[0][i] + t[1] * R[1][i] + t[2] * R[2][i]) > ra + rb) return 0; } // Test axis L = A0 x B0 ra = a.e[1] * AbsR[2][0] + a.e[2] * AbsR[1][0]; rb = b.e[1] * AbsR[0][2] + b.e[2] * AbsR[0][1]; if (abs(t[2] * R[1][0] - t[1] * R[2][0]) > ra + rb) return 0; // Test axis L = A0 x B1 ra = a.e[1] * AbsR[2][1] + a.e[2] * AbsR[1][1]; rb = b.e[0] * AbsR[0][2] + b.e[2] * AbsR[0][0]; if (abs(t[2] * R[1][1] - t[1] * R[2][1]) > ra + rb) return 0; // Test axis L = A0 x B2 ra = a.e[1] * AbsR[2][2] + a.e[2] * AbsR[1][2]; rb = b.e[0] * AbsR[0][1] + b.e[1] * AbsR[0][0]; if (abs(t[2] * R[1][2] - t[1] * R[2][2]) > ra + rb) return 0; // Test axis L = A1 x B0 ra = a.e[0] * AbsR[2][0] + a.e[2] * AbsR[0][0]; rb = b.e[1] * AbsR[1][2] + b.e[2] * AbsR[1][1]; if (abs(t[0] * R[2][0] - t[2] * R[0][0]) > ra + rb) return 0; // Test axis L = A1 x B1 ra = a.e[0] * AbsR[2][1] + a.e[2] * AbsR[0][1]; rb = b.e[0] * AbsR[1][2] + b.e[2] * AbsR[1][0]; if (abs(t[0] * R[2][1] - t[2] * R[0][1]) > ra + rb) return 0; // Test axis L = A1 x B2 ra = a.e[0] * AbsR[2][2] + a.e[2] * AbsR[0][2]; rb = b.e[0] * AbsR[1][1] + b.e[1] * AbsR[1][0]; if (abs(t[0] * R[2][2] - t[2] * R[0][2]) > ra + rb) return 0; // Test axis L = A2 x B0 ra = a.e[0] * AbsR[1][0] + a.e[1] * AbsR[0][0]; rb = b.e[1] * AbsR[2][2] + b.e[2] * AbsR[2][1]; if (abs(t[1] * R[0][0] - t[0] * R[1][0]) > ra + rb) return 0; // Test axis L = A2 x B1 ra = a.e[0] * AbsR[1][1] + a.e[1] * AbsR[0][1]; rb = b.e[0] * AbsR[2][2] + b.e[2] * AbsR[2][0]; if (abs(t[1] * R[0][1] - t[0] * R[1][1]) > ra + rb) return 0; // Test axis L = A2 x B2 ra = a.e[0] * AbsR[1][2] + a.e[1] * AbsR[0][2]; rb = b.e[0] * AbsR[2][1] + b.e[1] * AbsR[2][0]; if (abs(t[1] * R[0][2] - t[0] * R[1][2]) > ra + rb) return 0; // Since no separating axis is found, the OBBs must be intersecting return 1; }
void create_6hole_walls_snooker( BordersType * walls ) { int i; /* borders */ // walls->nr=30; walls->nr=32; if( walls->border != NULL ) billard_free( walls->border ); walls->border = billard_malloc( sizeof(BorderType)*walls->nr ); /* bonds */ walls->border[0].pnr = 3; walls->border[0].r1 = vec_xyz( +TABLE_W/2.0, +TABLE_L/2.0-HOLE1_W/SQR2, -BALL_D/2.0 ); walls->border[0].r2 = vec_xyz( +TABLE_W/2.0, +HOLE2_W/2.0, 0.0 ); walls->border[0].r3 = vec_xyz( +TABLE_W/2.0, +TABLE_L/2.0-HOLE1_W/SQR2, BALL_D/2.0 ); walls->border[0].n = vec_xyz( -1.0, 0.0, 0.0 ); walls->border[1].pnr = 3; walls->border[1].r1 = vec_xyz( +TABLE_W/2.0, -TABLE_L/2.0+HOLE1_W/SQR2, -BALL_D/2.0 ); walls->border[1].r2 = vec_xyz( +TABLE_W/2.0, -HOLE2_W/2.0, 0.0 ); walls->border[1].r3 = vec_xyz( +TABLE_W/2.0, -TABLE_L/2.0+HOLE1_W/SQR2, BALL_D/2.0 ); walls->border[1].n = vec_xyz( -1.0, 0.0, 0.0 ); walls->border[2].pnr = 3; walls->border[2].r1 = vec_xyz( -TABLE_W/2.0, +TABLE_L/2.0-HOLE1_W/SQR2, -BALL_D/2.0 ); walls->border[2].r2 = vec_xyz( -TABLE_W/2.0, +HOLE2_W/2.0, 0.0 ); walls->border[2].r3 = vec_xyz( -TABLE_W/2.0, +TABLE_L/2.0-HOLE1_W/SQR2, BALL_D/2.0 ); walls->border[2].n = vec_xyz( +1.0, 0.0, 0.0 ); walls->border[3].pnr = 3; walls->border[3].r1 = vec_xyz( -TABLE_W/2.0, -TABLE_L/2.0+HOLE1_W/SQR2, -BALL_D/2.0 ); walls->border[3].r2 = vec_xyz( -TABLE_W/2.0, -HOLE2_W/2.0, 0.0 ); walls->border[3].r3 = vec_xyz( -TABLE_W/2.0, -TABLE_L/2.0+HOLE1_W/SQR2, BALL_D/2.0 ); walls->border[3].n = vec_xyz( +1.0, 0.0, 0.0 ); walls->border[4].pnr = 3; walls->border[4].r1 = vec_xyz( -TABLE_W/2.0+HOLE1_W/SQR2, +TABLE_L/2.0, -BALL_D/2.0 ); walls->border[4].r2 = vec_xyz( +TABLE_W/2.0-HOLE1_W/SQR2, +TABLE_L/2.0, 0.0 ); walls->border[4].r3 = vec_xyz( -TABLE_W/2.0+HOLE1_W/SQR2, +TABLE_L/2.0, BALL_D/2.0 ); walls->border[4].n = vec_xyz( 0.0, -1.0, 0.0 ); walls->border[5].pnr = 3; walls->border[5].r1 = vec_xyz( -TABLE_W/2.0+HOLE1_W/SQR2, -TABLE_L/2.0, -BALL_D/2.0 ); walls->border[5].r2 = vec_xyz( +TABLE_W/2.0-HOLE1_W/SQR2, -TABLE_L/2.0, 0.0 ); walls->border[5].r3 = vec_xyz( -TABLE_W/2.0+HOLE1_W/SQR2, -TABLE_L/2.0, BALL_D/2.0 ); walls->border[5].n = vec_xyz( 0.0, +1.0, 0.0 ); /* edges */ /* upper right */ walls->border[6].pnr = 2; walls->border[6].r1 = vec_xyz( +TABLE_W/2.0, +TABLE_L/2.0-HOLE1_W/SQR2, -BALL_D/2.0 ); walls->border[6].r2 = vec_xyz( +TABLE_W/2.0, +TABLE_L/2.0-HOLE1_W/SQR2, BALL_D/2.0 ); walls->border[18].pnr = 3; walls->border[18].r1 = vec_xyz( +TABLE_W/2.0, +TABLE_L/2.0-HOLE1_W/SQR2, -BALL_D/2.0 ); walls->border[18].r2 = vec_xyz( +TABLE_W/2.0, +TABLE_L/2.0-HOLE1_W/SQR2, BALL_D/2.0 ); walls->border[18].r3 = vec_xyz( +TABLE_W/2.0+1.0, +TABLE_L/2.0-HOLE1_W/SQR2+HOLE1_TAN, 0.0 ); walls->border[18].n = vec_unit(vec_cross(vec_diff(walls->border[18].r2,walls->border[18].r1),vec_diff(walls->border[18].r3,walls->border[18].r1))); /* upper right */ walls->border[7].pnr = 2; walls->border[7].r1 = vec_xyz( +TABLE_W/2.0-HOLE1_W/SQR2, +TABLE_L/2.0, -BALL_D/2.0 ); walls->border[7].r2 = vec_xyz( +TABLE_W/2.0-HOLE1_W/SQR2, +TABLE_L/2.0, BALL_D/2.0 ); walls->border[19].pnr = 3; walls->border[19].r1 = vec_xyz( +TABLE_W/2.0-HOLE1_W/SQR2, +TABLE_L/2.0, -BALL_D/2.0 ); walls->border[19].r2 = vec_xyz( +TABLE_W/2.0-HOLE1_W/SQR2, +TABLE_L/2.0, BALL_D/2.0 ); walls->border[19].r3 = vec_xyz( +TABLE_W/2.0-HOLE1_W/SQR2+HOLE1_TAN, +TABLE_L/2.0+1.0, 0.0 ); walls->border[19].n = vec_unit(vec_cross(vec_diff(walls->border[19].r1,walls->border[19].r2),vec_diff(walls->border[19].r3,walls->border[19].r1))); /* upper left */ walls->border[8].pnr = 2; walls->border[8].r1 = vec_xyz( -TABLE_W/2.0, +TABLE_L/2.0-HOLE1_W/SQR2, -BALL_D/2.0 ); walls->border[8].r2 = vec_xyz( -TABLE_W/2.0, +TABLE_L/2.0-HOLE1_W/SQR2, BALL_D/2.0 ); walls->border[20].pnr = 3; walls->border[20].r1 = vec_xyz( -TABLE_W/2.0, +TABLE_L/2.0-HOLE1_W/SQR2, -BALL_D/2.0 ); walls->border[20].r2 = vec_xyz( -TABLE_W/2.0, +TABLE_L/2.0-HOLE1_W/SQR2, BALL_D/2.0 ); walls->border[20].r3 = vec_xyz( -TABLE_W/2.0-1.0, +TABLE_L/2.0-HOLE1_W/SQR2+HOLE1_TAN, 0.0 ); walls->border[20].n = vec_unit(vec_cross(vec_diff(walls->border[20].r1,walls->border[20].r2),vec_diff(walls->border[20].r3,walls->border[20].r1))); /* upper left */ walls->border[9].pnr = 2; walls->border[9].r1 = vec_xyz( -TABLE_W/2.0+HOLE1_W/SQR2, +TABLE_L/2.0, -BALL_D/2.0 ); walls->border[9].r2 = vec_xyz( -TABLE_W/2.0+HOLE1_W/SQR2, +TABLE_L/2.0, BALL_D/2.0 ); walls->border[21].pnr = 3; walls->border[21].r1 = vec_xyz( -TABLE_W/2.0+HOLE1_W/SQR2, +TABLE_L/2.0, -BALL_D/2.0 ); walls->border[21].r2 = vec_xyz( -TABLE_W/2.0+HOLE1_W/SQR2, +TABLE_L/2.0, BALL_D/2.0 ); walls->border[21].r3 = vec_xyz( -TABLE_W/2.0+HOLE1_W/SQR2-HOLE1_TAN, +TABLE_L/2.0+1.0, 0.0 ); walls->border[21].n = vec_unit(vec_cross(vec_diff(walls->border[21].r2,walls->border[21].r1),vec_diff(walls->border[21].r3,walls->border[21].r1))); /* lower right */ walls->border[10].pnr = 2; walls->border[10].r1 = vec_xyz( +TABLE_W/2.0, -TABLE_L/2.0+HOLE1_W/SQR2, -BALL_D/2.0 ); walls->border[10].r2 = vec_xyz( +TABLE_W/2.0, -TABLE_L/2.0+HOLE1_W/SQR2, BALL_D/2.0 ); walls->border[22].pnr = 3; walls->border[22].r1 = vec_xyz( +TABLE_W/2.0, -TABLE_L/2.0+HOLE1_W/SQR2, -BALL_D/2.0 ); walls->border[22].r2 = vec_xyz( +TABLE_W/2.0, -TABLE_L/2.0+HOLE1_W/SQR2, BALL_D/2.0 ); walls->border[22].r3 = vec_xyz( +TABLE_W/2.0+1.0, -TABLE_L/2.0+HOLE1_W/SQR2-HOLE1_TAN, 0.0 ); walls->border[22].n = vec_unit(vec_cross(vec_diff(walls->border[22].r1,walls->border[22].r2),vec_diff(walls->border[22].r3,walls->border[22].r1))); /* lower right */ walls->border[11].pnr = 2; walls->border[11].r1 = vec_xyz( +TABLE_W/2.0-HOLE1_W/SQR2, -TABLE_L/2.0, -BALL_D/2.0 ); walls->border[11].r2 = vec_xyz( +TABLE_W/2.0-HOLE1_W/SQR2, -TABLE_L/2.0, BALL_D/2.0 ); walls->border[23].pnr = 3; walls->border[23].r1 = vec_xyz( +TABLE_W/2.0-HOLE1_W/SQR2, -TABLE_L/2.0, -BALL_D/2.0 ); walls->border[23].r2 = vec_xyz( +TABLE_W/2.0-HOLE1_W/SQR2, -TABLE_L/2.0, BALL_D/2.0 ); walls->border[23].r3 = vec_xyz( +TABLE_W/2.0-HOLE1_W/SQR2+HOLE1_TAN, -TABLE_L/2.0-1.0, 0.0 ); walls->border[23].n = vec_unit(vec_cross(vec_diff(walls->border[23].r2,walls->border[23].r1),vec_diff(walls->border[23].r3,walls->border[23].r1))); /* lower left */ walls->border[12].pnr = 2; walls->border[12].r1 = vec_xyz( -TABLE_W/2.0, -TABLE_L/2.0+HOLE1_W/SQR2, -BALL_D/2.0 ); walls->border[12].r2 = vec_xyz( -TABLE_W/2.0, -TABLE_L/2.0+HOLE1_W/SQR2, BALL_D/2.0 ); walls->border[24].pnr = 3; walls->border[24].r1 = vec_xyz( -TABLE_W/2.0, -TABLE_L/2.0+HOLE1_W/SQR2, -BALL_D/2.0 ); walls->border[24].r2 = vec_xyz( -TABLE_W/2.0, -TABLE_L/2.0+HOLE1_W/SQR2, BALL_D/2.0 ); walls->border[24].r3 = vec_xyz( -TABLE_W/2.0-1.0, -TABLE_L/2.0+HOLE1_W/SQR2-HOLE1_TAN, 0.0 ); walls->border[24].n = vec_unit(vec_cross(vec_diff(walls->border[24].r2,walls->border[24].r1),vec_diff(walls->border[24].r3,walls->border[24].r1))); /* lower left */ walls->border[13].pnr = 2; walls->border[13].r1 = vec_xyz( -TABLE_W/2.0+HOLE1_W/SQR2, -TABLE_L/2.0, -BALL_D/2.0 ); walls->border[13].r2 = vec_xyz( -TABLE_W/2.0+HOLE1_W/SQR2, -TABLE_L/2.0, BALL_D/2.0 ); walls->border[25].pnr = 3; walls->border[25].r1 = vec_xyz( -TABLE_W/2.0+HOLE1_W/SQR2, -TABLE_L/2.0, -BALL_D/2.0 ); walls->border[25].r2 = vec_xyz( -TABLE_W/2.0+HOLE1_W/SQR2, -TABLE_L/2.0, BALL_D/2.0 ); walls->border[25].r3 = vec_xyz( -TABLE_W/2.0+HOLE1_W/SQR2-HOLE1_TAN, -TABLE_L/2.0-1.0, 0.0 ); walls->border[25].n = vec_unit(vec_cross(vec_diff(walls->border[25].r1,walls->border[25].r2),vec_diff(walls->border[25].r3,walls->border[25].r1))); /* middle left */ walls->border[14].pnr = 2; walls->border[14].r1 = vec_xyz( -TABLE_W/2.0, HOLE2_W/2.0, -BALL_D/2.0 ); walls->border[14].r2 = vec_xyz( -TABLE_W/2.0, HOLE2_W/2.0, BALL_D/2.0 ); walls->border[26].pnr = 3; walls->border[26].r1 = vec_xyz( -TABLE_W/2.0, HOLE2_W/2.0, -BALL_D/2.0 ); walls->border[26].r2 = vec_xyz( -TABLE_W/2.0, HOLE2_W/2.0, BALL_D/2.0 ); walls->border[26].r3 = vec_xyz( -TABLE_W/2.0-1.0, HOLE2_W/2.0-HOLE2_TAN, 0.0 ); walls->border[26].n = vec_unit(vec_cross(vec_diff(walls->border[26].r2,walls->border[26].r1),vec_diff(walls->border[26].r3,walls->border[26].r1))); /* middle left */ walls->border[15].pnr = 2; walls->border[15].r1 = vec_xyz( -TABLE_W/2.0, -HOLE2_W/2.0, -BALL_D/2.0 ); walls->border[15].r2 = vec_xyz( -TABLE_W/2.0, -HOLE2_W/2.0, BALL_D/2.0 ); walls->border[27].pnr = 3; walls->border[27].r1 = vec_xyz( -TABLE_W/2.0, -HOLE2_W/2.0, -BALL_D/2.0 ); walls->border[27].r2 = vec_xyz( -TABLE_W/2.0, -HOLE2_W/2.0, BALL_D/2.0 ); walls->border[27].r3 = vec_xyz( -TABLE_W/2.0-1.0, -HOLE2_W/2.0+HOLE2_TAN, 0.0 ); walls->border[27].n = vec_unit(vec_cross(vec_diff(walls->border[27].r1,walls->border[27].r2),vec_diff(walls->border[27].r3,walls->border[27].r1))); /* middle right */ walls->border[16].pnr = 2; walls->border[16].r1 = vec_xyz( +TABLE_W/2.0, HOLE2_W/2.0, -BALL_D/2.0 ); walls->border[16].r2 = vec_xyz( +TABLE_W/2.0, HOLE2_W/2.0, BALL_D/2.0 ); walls->border[28].pnr = 3; walls->border[28].r1 = vec_xyz( +TABLE_W/2.0, HOLE2_W/2.0, -BALL_D/2.0 ); walls->border[28].r2 = vec_xyz( +TABLE_W/2.0, HOLE2_W/2.0, BALL_D/2.0 ); walls->border[28].r3 = vec_xyz( +TABLE_W/2.0+1.0, HOLE2_W/2.0-HOLE2_TAN, 0.0 ); walls->border[28].n = vec_unit(vec_cross(vec_diff(walls->border[28].r1,walls->border[28].r2),vec_diff(walls->border[28].r3,walls->border[28].r1))); /* middle right */ walls->border[17].pnr = 2; walls->border[17].r1 = vec_xyz( +TABLE_W/2.0, -HOLE2_W/2.0, -BALL_D/2.0 ); walls->border[17].r2 = vec_xyz( +TABLE_W/2.0, -HOLE2_W/2.0, BALL_D/2.0 ); walls->border[29].pnr = 3; walls->border[29].r1 = vec_xyz( +TABLE_W/2.0, -HOLE2_W/2.0, -BALL_D/2.0 ); walls->border[29].r2 = vec_xyz( +TABLE_W/2.0, -HOLE2_W/2.0, BALL_D/2.0 ); walls->border[29].r3 = vec_xyz( +TABLE_W/2.0+1.0, -HOLE2_W/2.0+HOLE2_TAN, 0.0 ); walls->border[29].n = vec_unit(vec_cross(vec_diff(walls->border[29].r2,walls->border[29].r1),vec_diff(walls->border[29].r3,walls->border[29].r1))); /* friction constants and loss factors */ for(i=0;i<walls->nr;i++){ walls->border[i].mu = 0.1; walls->border[i].loss0 = 0.2; walls->border[i].loss_max = 0.5; walls->border[i].loss_wspeed = 4.0; /* [m/s] */ } /* table surface */ #define TABLE_W2 (TABLE_W-BALL_D*0.9) #define TABLE_L2 (TABLE_L-BALL_D*0.9) walls->border[30].pnr = 3; walls->border[30].r1 = vec_xyz( -TABLE_W/2.0, -TABLE_L/2.0, -BALL_D/2.0-0.0001 ); walls->border[30].r2 = vec_xyz( +TABLE_W/2.0, -TABLE_L/2.0, -BALL_D/2.0-0.0001 ); walls->border[30].r3 = vec_xyz( +TABLE_W/2.0, +TABLE_L/2.0, -BALL_D/2.0-0.0001 ); walls->border[30].n = vec_xyz( 0.0, 0.0, 1.0 ); walls->border[31].pnr = 3; walls->border[31].r1 = vec_xyz( -TABLE_W/2.0, -TABLE_L/2.0, -BALL_D/2.0-0.0001 ); walls->border[31].r3 = vec_xyz( +TABLE_W/2.0, +TABLE_L/2.0, -BALL_D/2.0-0.0001 ); walls->border[31].r2 = vec_xyz( -TABLE_W/2.0, +TABLE_L/2.0, -BALL_D/2.0-0.0001 ); walls->border[31].n = vec_xyz( 0.0, 0.0, 1.0 ); #undef TABLE_W2 #undef TABLE_L2 walls->border[30].mu = 0.2; walls->border[30].loss0 = 0.6; walls->border[30].loss_max = 0.99; walls->border[30].loss_wspeed = 1.5; walls->border[31].mu = 0.2; walls->border[31].loss0 = 0.6; walls->border[31].loss_max = 0.99; walls->border[31].loss_wspeed = 1.5; /* holes */ walls->holenr = 6; if( walls->hole != NULL ) billard_free( walls->hole ); walls->hole = billard_malloc(sizeof(HoleType)*walls->holenr); /* middle right */ walls->hole[0].aim = vec_xyz( +TABLE_W/2.0-HOLE2_AIMOFFS, 0.0, 0.0 ); walls->hole[0].pos = vec_xyz( +TABLE_W/2.0+HOLE2_XYOFFS, 0.0, 0.0 ); walls->hole[0].r = HOLE2_R; /* middle left */ walls->hole[1].aim = vec_xyz( -TABLE_W/2.0+HOLE2_AIMOFFS, 0.0, 0.0 ); walls->hole[1].pos = vec_xyz( -TABLE_W/2.0-HOLE2_XYOFFS, 0.0, 0.0 ); walls->hole[1].r = HOLE2_R; /* upper right */ walls->hole[2].aim = vec_xyz( +TABLE_W/2.0-HOLE1_AIMOFFS, +TABLE_L/2.0-HOLE1_AIMOFFS, 0.0 ); walls->hole[2].pos = vec_xyz( +TABLE_W/2.0+HOLE1_XYOFFS, +TABLE_L/2.0+HOLE1_XYOFFS, 0.0 ); walls->hole[2].r = HOLE1_R; /* upper left */ walls->hole[3].aim = vec_xyz( -TABLE_W/2.0+HOLE1_AIMOFFS, +TABLE_L/2.0-HOLE1_AIMOFFS, 0.0 ); walls->hole[3].pos = vec_xyz( -TABLE_W/2.0-HOLE1_XYOFFS, +TABLE_L/2.0+HOLE1_XYOFFS, 0.0 ); walls->hole[3].r = HOLE1_R; /* lower left */ walls->hole[4].aim = vec_xyz( -TABLE_W/2.0+HOLE1_AIMOFFS, -TABLE_L/2.0-HOLE1_AIMOFFS, 0.0 ); walls->hole[4].pos = vec_xyz( -TABLE_W/2.0-HOLE1_XYOFFS, -TABLE_L/2.0-HOLE1_XYOFFS, 0.0 ); walls->hole[4].r = HOLE1_R; /* lower right */ walls->hole[5].aim = vec_xyz( +TABLE_W/2.0-HOLE1_AIMOFFS, -TABLE_L/2.0+HOLE1_AIMOFFS, 0.0 ); walls->hole[5].pos = vec_xyz( +TABLE_W/2.0+HOLE1_XYOFFS, -TABLE_L/2.0-HOLE1_XYOFFS, 0.0 ); walls->hole[5].r = HOLE1_R; }
void create_snooker_scene( BallsType * balls ) { int i; myvec dball1, dball2, vdummy; VMfloat ang, ampl; myvec verr; balls->gametype=GAME_SNOOKER; /* balls */ balls->nr=22; if( balls->ball != NULL ) billard_free( balls->ball ); balls->ball = billard_malloc(sizeof(BallType)*balls->nr); placesnookerballnrs(balls); for(i=0;i<balls->nr;i++){ balls->ball[i].m=BALL_M; /* I_kugel = (m.r^2)2/5 = (m.d^2)/10 */ balls->ball[i].I=BALL_M*BALL_D*BALL_D/10.0/**0.01*/; balls->ball[i].d=BALL_D; balls->ball[i].r = vec_xyz(TABLE_L*3,TABLE_L*3,0.0); /* get balls out of the way */ balls->ball[i].v=vec_xyz(0.0,0.0,0.0); balls->ball[i].w=vec_xyz(0.0,0.0,0.0); balls->ball[i].b[0]=vec_unit(vec_xyz(rand(),rand(),rand())); vdummy=vec_xyz(rand(),rand(),rand()); balls->ball[i].b[1]=vec_unit(vec_diff(vdummy,vec_proj(vdummy,balls->ball[i].b[0]))); balls->ball[i].b[2]=vec_cross(balls->ball[i].b[0],balls->ball[i].b[1]); balls->ball[i].in_game=1; balls->ball[i].in_hole=0; balls->ball[i].soundplayed=0; } dball1=vec_scale(vec_xyz(-0.5*1.01, 0.5*sqrt(3.0)*1.01,0.0),BALL_D); dball2=vec_scale(vec_xyz( 1.01, 0.0, 0.0),BALL_D); /* red balls */ balls->ball[ 1].r = vec_xyz(0.0,TABLE_L/4.0+1.1*BALL_D,0.0); balls->ball[ 8].r = vec_add( balls->ball[ 1].r, dball1 ); balls->ball[ 9].r = vec_add( balls->ball[ 8].r, dball2 ); balls->ball[10].r = vec_add( balls->ball[ 8].r, dball1 ); balls->ball[11].r = vec_add( balls->ball[10].r, dball2 ); balls->ball[12].r = vec_add( balls->ball[11].r, dball2 ); balls->ball[13].r = vec_add( balls->ball[10].r, dball1 ); balls->ball[14].r = vec_add( balls->ball[13].r, dball2 ); balls->ball[15].r = vec_add( balls->ball[14].r, dball2 ); balls->ball[16].r = vec_add( balls->ball[15].r, dball2 ); balls->ball[17].r = vec_add( balls->ball[13].r, dball1 ); balls->ball[18].r = vec_add( balls->ball[17].r, dball2 ); balls->ball[19].r = vec_add( balls->ball[18].r, dball2 ); balls->ball[20].r = vec_add( balls->ball[19].r, dball2 ); balls->ball[21].r = vec_add( balls->ball[20].r, dball2 ); /* color balls */ for(i=7;i>=2;i--) { spot_snooker_ball(balls,i); } /* white ball */ spot_snooker_ball(balls,0); /* add randomness to init positions */ for( i=1 ; i<balls->nr ; i++ ){ ang = (VMfloat)rand()/(VMfloat)RAND_MAX*2.0*M_PI; ampl = (VMfloat)rand()/(VMfloat)RAND_MAX*0.0049*BALL_D; verr = vec_scale( vec_xyz(cos(ang),sin(ang),0.0), ampl ); balls->ball[i].r = vec_add( balls->ball[i].r, verr ); } for( i=0 ; i<balls->nr ; i++ ){ balls->ball[i].path=0; balls->ball[i].pathcnt=0; balls->ball[i].pathsize=0; } balls->ball[0].v=vec_xyz(0.0,0.0,0.0); }
void create_8ball_scene( BallsType * balls ) { int i,j; myvec dball1, dball2, vdummy; VMfloat poserr=0.007; VMfloat ang; myvec verr; balls->gametype=GAME_8BALL; /* balls */ balls->nr=16; if( balls->ball != NULL ) billard_free( balls->ball ); balls->ball = billard_malloc(sizeof(BallType)*balls->nr); place8ballnrs(balls); for(i=0;i<balls->nr;i++){ balls->ball[i].m=BALL_M; /* I_kugel = (m.r^2)2/5 = (m.d^2)/10 */ balls->ball[i].I=BALL_M*BALL_D*BALL_D/10.0/**0.01*/; balls->ball[i].d=BALL_D; balls->ball[i].v=vec_xyz(0.0,0.0,0.0); balls->ball[i].w=vec_xyz(0.0,0.0,0.0); balls->ball[i].b[0]=vec_unit(vec_xyz(rand(),rand(),rand())); vdummy=vec_xyz(rand(),rand(),rand()); balls->ball[i].b[1]=vec_unit(vec_diff(vdummy,vec_proj(vdummy,balls->ball[i].b[0]))); balls->ball[i].b[2]=vec_cross(balls->ball[i].b[0],balls->ball[i].b[1]); balls->ball[i].in_game=1; balls->ball[i].in_hole=0; balls->ball[i].soundplayed=0; } dball1=vec_scale( vec_xyz(-0.5, 0.5*sqrt(3.0), 0.0), (1.0+2.0*poserr)*BALL_D ); dball2=vec_scale( vec_xyz( 1.0, 0.0, 0.0), (1.0+2.0*poserr)*BALL_D ); /* white ball */ balls->ball[0].r = vec_xyz(0.0,-TABLE_L/4.0,0.0); balls->ball[0].w = vec_xyz(0.0,0.0,0.0); /* other balls */ balls->ball[ 1].r = vec_xyz(0.0,TABLE_L/4.0,0.0); balls->ball[ 2].r = vec_add( balls->ball[ 1].r, dball1 ); balls->ball[ 3].r = vec_add( balls->ball[ 2].r, dball2 ); balls->ball[ 4].r = vec_add( balls->ball[ 2].r, dball1 ); balls->ball[ 5].r = vec_add( balls->ball[ 4].r, dball2 ); balls->ball[ 6].r = vec_add( balls->ball[ 5].r, dball2 ); balls->ball[ 7].r = vec_add( balls->ball[ 4].r, dball1 ); balls->ball[ 8].r = vec_add( balls->ball[ 7].r, dball2 ); balls->ball[ 9].r = vec_add( balls->ball[ 8].r, dball2 ); balls->ball[10].r = vec_add( balls->ball[ 9].r, dball2 ); balls->ball[11].r = vec_add( balls->ball[ 7].r, dball1 ); balls->ball[12].r = vec_add( balls->ball[11].r, dball2 ); balls->ball[13].r = vec_add( balls->ball[12].r, dball2 ); balls->ball[14].r = vec_add( balls->ball[13].r, dball2 ); balls->ball[15].r = vec_add( balls->ball[14].r, dball2 ); /* add randomness to init positions */ for( i=1 ; i<balls->nr ; i++ ){ ang = (VMfloat)rand()/(VMfloat)RAND_MAX*2.0*M_PI; //fprintf(stderr,"ball_placemet_err: angle=%f ",ang); verr = vec_scale( vec_xyz(cos(ang),sin(ang),0.0), (poserr*0.95)*BALL_D ); balls->ball[i].r = vec_add( balls->ball[i].r, verr ); } for( i=1 ; i<balls->nr ; i++ ){ for( j=i+1 ; j<balls->nr ; j++ ){ if (vec_abs(vec_diff(balls->ball[i].r,balls->ball[j].r))/BALL_D<1.5){ //fprintf(stderr,"BALLLDISR(%d,%d)=%f\n",balls->ball[i].nr,balls->ball[j].nr,vec_abs(vec_diff(balls->ball[i].r,balls->ball[j].r))/BALL_D); } } } for( i=0 ; i<balls->nr ; i++ ){ balls->ball[i].path=0; balls->ball[i].pathcnt=0; balls->ball[i].pathsize=0; } balls->ball[0].v=vec_xyz(0.0,0.0,0.0); }
void create_9ball_scene( BallsType * balls ) { int i; myvec dball1, dball2, vdummy; VMfloat ang, ampl; myvec verr; balls->gametype=GAME_9BALL; /* balls */ balls->nr=10; if( balls->ball != NULL ) billard_free( balls->ball ); balls->ball = billard_malloc(sizeof(BallType)*balls->nr); place9ballnrs(balls); for(i=0;i<balls->nr;i++){ balls->ball[i].m=BALL_M; /* I_kugel = (m.r^2)2/5 = (m.d^2)/10 */ balls->ball[i].I=BALL_M*BALL_D*BALL_D/10.0/**0.01*/; balls->ball[i].d=BALL_D; balls->ball[i].v=vec_xyz(0.0,0.0,0.0); balls->ball[i].w=vec_xyz(0.0,0.0,0.0); balls->ball[i].b[0]=vec_unit(vec_xyz(rand(),rand(),rand())); vdummy=vec_xyz(rand(),rand(),rand()); balls->ball[i].b[1]=vec_unit(vec_diff(vdummy,vec_proj(vdummy,balls->ball[i].b[0]))); balls->ball[i].b[2]=vec_cross(balls->ball[i].b[0],balls->ball[i].b[1]); balls->ball[i].in_game=1; balls->ball[i].in_hole=0; balls->ball[i].soundplayed=0; } dball1=vec_scale(vec_xyz(-0.5*1.01, 0.5*sqrt(3.0)*1.01,0.0),BALL_D); dball2=vec_scale(vec_xyz(+0.5*1.01, 0.5*sqrt(3.0)*1.01,0.0),BALL_D); /* white ball */ balls->ball[0].r = vec_xyz(0.0,-TABLE_L/4.0,0.0); balls->ball[0].w = vec_xyz(0.0,0.0,0.0); /* other balls */ balls->ball[ 1].r = vec_xyz(0.0,TABLE_L/4.0,0.0); balls->ball[ 2].r = vec_add( balls->ball[1].r, vec_scale(dball2,2.0) ); balls->ball[ 3].r = vec_add( balls->ball[2].r, vec_scale(dball1,2.0) ); balls->ball[ 4].r = vec_add( balls->ball[1].r, vec_scale(dball1,2.0) ); balls->ball[ 5].r = vec_add( balls->ball[1].r, dball1 ); balls->ball[ 6].r = vec_add( balls->ball[1].r, dball2 ); balls->ball[ 7].r = vec_add( balls->ball[2].r, dball1 ); balls->ball[ 8].r = vec_add( balls->ball[4].r, dball2 ); balls->ball[ 9].r = vec_add( balls->ball[1].r, vec_add(dball1,dball2) ); /* add randomness to init positions */ for( i=1 ; i<balls->nr ; i++ ){ ang = rand(); ang = (VMfloat)rand()/(VMfloat)RAND_MAX*2.0*M_PI; ampl = (VMfloat)rand()/(VMfloat)RAND_MAX*0.0049*BALL_D; verr = vec_scale( vec_xyz(cos(ang),sin(ang),0.0), ampl ); balls->ball[i].r = vec_add( balls->ball[i].r, verr ); } for( i=0 ; i<balls->nr ; i++ ){ balls->ball[i].path=0; balls->ball[i].pathcnt=0; balls->ball[i].pathsize=0; } balls->ball[0].v=vec_xyz(0.0,0.0,0.0); }