コード例 #1
0
void CGravityModifier::m_Force (float4 framepos, AD_Vect3D *pos, AD_Vect3D *vel, AD_Vect3D *accel)
{
    AD_Vect3D posrel, force;
    float4 dist;

    if (p_Mapping==FORCE_PLANAR)
	{
	  if (p_Decay!=0)
	  {
	    vect_sub(pos, &p_CurrentPosition, &posrel);
        dist = fabsf(vect_dot(&p_Force, &posrel));
		vect_scale(&p_ScaledForce, (float4)exp(-p_Decay*dist), accel);
	  }
	  else
	  vect_copy(&p_ScaledForce, accel);
	}
    else
	{
	  vect_sub(&p_CurrentPosition, pos, &force);
      dist = vect_length(&force);
      if (dist != 0) vect_auto_scale(&force, 1.0f/dist);
      if (p_Decay != 0) 
	  {
        vect_scale(&force, p_ScaledStrength*(float4)exp(-p_Decay*dist), accel);
	  }
	  else
	    vect_scale(&force, p_ScaledStrength, accel);
	}
}
コード例 #2
0
void CWindModifier::m_Force (float4 framepos, AD_Vect3D *pos, AD_Vect3D *vel, AD_Vect3D *accel)
{
  AD_Vect3D posrel, tf, p, force, p2;
  float4 dist, freq, turb;

  freq=p_Frequency;
  turb=p_Turbolence;

  if (p_Mapping==FORCE_PLANAR)
  {
    if (p_Decay!=0.0f)
	{
	  vect_sub(pos, &p_CurrentPosition, &posrel);
	  dist=fabsf(vect_dot(&p_Force, &posrel));
      vect_scale(&p_ScaledForce, (float4)exp(-p_Decay*dist), accel);
	}
	else vect_copy(&p_ScaledForce, accel);
  } 
  else
  {
    vect_sub(pos, &p_CurrentPosition, &force);
    dist = vect_length(&force);
    if (dist != 0) vect_auto_scale(&force, 1.0f/dist);
    if (p_Decay != 0)
      vect_scale(&force, p_ScaledStrength*(float4)exp(-p_Decay*dist), accel);
	else
      vect_scale(&force, p_ScaledStrength, accel);
  }

  if (turb != 0)
  {
    vect_sub(pos, &p_CurrentPosition, &p2);
    freq *= 0.01f;

	vect_copy(&p2, &p);
    p.x  = freq * framepos;
    tf.x = noise3(p.x*p_Scale, p.y*p_Scale, p.z*p_Scale);

	vect_copy(&p2, &p);
    p.y  = freq * framepos;
    tf.y = noise3(p.x*p_Scale, p.y*p_Scale, p.z*p_Scale);

	vect_copy(&p2, &p);    
	p.z  = freq * framepos;
    tf.z = noise3(p.x*p_Scale, p.y*p_Scale, p.z*p_Scale);

    turb *= 0.0001f*forceScaleFactor;
    vect_auto_scale(&tf, turb);
	vect_add(accel, &tf, accel);
  }
}
コード例 #3
0
ファイル: Lights.cpp プロジェクト: ApocalypseDesign/ad_public
int32 CLight::m_Init(void *arg1)
{
  int32 kc;

  if (p_ColorTrack)
  {
     // questo swapping serve perche' essendo la colortrack una traccia di posizione (ovvero
     // tripletta di float, che pero' in questo caso sono intesi come RGB) la yz vengono
     // swappate dal keyframer reader, e quindi essendo questi colori non devono essere
     // swappati  ==> serve uno swap per tornare ai dati giusti
     for (kc=0; kc<p_ColorTrack->p_NumKeys; kc++)
     {
       vect_swap_3DS(&p_ColorTrack->p_Keys[kc].p);
       vect_swap_3DS(&p_ColorTrack->p_Keys[kc].incomtg);
       vect_swap_3DS(&p_ColorTrack->p_Keys[kc].outcomtg);
       vect_scale(&p_ColorTrack->p_Keys[kc].p, RGB_MAXVALUE, &p_ColorTrack->p_Keys[kc].p);
	   vect_scale(&p_ColorTrack->p_Keys[kc].incomtg, RGB_MAXVALUE, &p_ColorTrack->p_Keys[kc].incomtg);
       vect_scale(&p_ColorTrack->p_Keys[kc].outcomtg, RGB_MAXVALUE, &p_ColorTrack->p_Keys[kc].outcomtg);
     }
  }
  
  if (p_ColorTrack)
    if (!p_ColorTrack->m_Init(1)) return(0);

  // luce ambientale emessa nulla e speculare massima
  p_D3DLight.Ambient.b=0.0f;
  p_D3DLight.Ambient.g=0.0f;
  p_D3DLight.Ambient.r=0.0f;
  p_D3DLight.Ambient.a=1.0f;
  p_D3DLight.Diffuse.b=p_CurrentColor.z;
  p_D3DLight.Diffuse.g=p_CurrentColor.y;
  p_D3DLight.Diffuse.r=p_CurrentColor.x;
  p_D3DLight.Diffuse.a=1.0f;
  p_D3DLight.Specular.b=p_CurrentColor.z;
  p_D3DLight.Specular.g=p_CurrentColor.y;
  p_D3DLight.Specular.r=p_CurrentColor.x;
  p_D3DLight.Specular.a=1.0f;
  p_D3DLight.Attenuation0=p_Attenuation0;
  p_D3DLight.Attenuation1=p_Attenuation1;
  p_D3DLight.Attenuation2=p_Attenuation2;
  p_D3DLight.Range=p_MaxRange;
  if (!CGeometricObject::m_Init(arg1))
    return(0);
  p_D3DLight.Position.x=p_CurrentPosition.x;
  p_D3DLight.Position.y=p_CurrentPosition.y;
  p_D3DLight.Position.z=p_CurrentPosition.z;
  return(1);
}
コード例 #4
0
ファイル: ray_throw.c プロジェクト: kube/RT
static void		calculate_reflected(t_ray *a, t_ray *b)
{
	t_vector	n;
	t_point		intersection;

	intersection.x = a->origin.x + a->direction.x * a->inter_t;
	intersection.y = a->origin.y + a->direction.y * a->inter_t;
	intersection.z = a->origin.z + a->direction.z * a->inter_t;
	if (a->closest->type == OBJ_SPHERE)
	{
		n.x = intersection.x - a->closest->origin.x;
		n.y = intersection.y - a->closest->origin.y;
		n.z = intersection.z - a->closest->origin.z;
	}
	else if (a->closest->type == OBJ_CYLINDER)
		get_cylinder_normal(&n, a->closest, &intersection);
	else if (a->closest->type == OBJ_CONE)
		get_cone_normal(&n, a->closest, &intersection);
	else
		n = a->closest->normal;
	b->origin = intersection;
	vect_scale(&a->direction, -1);
	b->direction.x = 2 * (vect_dot(&n, &a->direction)) * n.x - a->direction.x;
	b->direction.y = 2 * (vect_dot(&n, &a->direction)) * n.y - a->direction.y;
	b->direction.z = 2 * (vect_dot(&n, &a->direction)) * n.z - a->direction.z;
	normalize_vector(&b->direction);
}
コード例 #5
0
ファイル: vect3ds.c プロジェクト: germolinal/Schedules
void vect_normalize (Vector v)
{
    float mag = vect_mag (v);

    if (mag > 0.0)
        vect_scale (v, v, 1.0/mag);
}
コード例 #6
0
void CWindModifier::m_Update(float4 frame)
{
  CGeometricObject::m_Update(frame);

  if (p_StrengthTrack)
     p_StrengthTrack->m_GetData(frame, &p_Strength);

  if (p_DecayTrack)
     p_DecayTrack->m_GetData(frame, &p_Decay);
  if (p_Decay<0) p_Decay=0;

  if (p_TurbolenceTrack)
     p_TurbolenceTrack->m_GetData(frame, &p_Turbolence);
  if (p_Turbolence<0) p_Turbolence=0;
  
  if (p_FrequencyTrack)
     p_FrequencyTrack->m_GetData(frame, &p_Frequency);
  if (p_Frequency<0) p_Frequency=0;

  if (p_ScaleTrack)
     p_ScaleTrack->m_GetData(frame, &p_Scale);
  if (p_Scale<0) p_Scale=0;

  mat_get_column(&p_WorldMatrix, 1, &p_Force);
  vect_auto_normalize(&p_Force);

  p_ScaledStrength=p_Strength*0.0001f*forceScaleFactor*1.5f;
  vect_scale(&p_Force, p_ScaledStrength, &p_ScaledForce);
}
コード例 #7
0
ファイル: WSMobj.cpp プロジェクト: ApocalypseDesign/ad_public
void AD_WindModifier::build_objectmatrix (float4 framepos)
{
   AD_Vect3D postmp, stmp;
   AD_Quaternion objrot;
   AD_Matrix posttrans, scaling, maux;

   accum_scale.x=accum_scale.y=accum_scale.z=1.0f;
   mat_identity(&currentmatrix_rot);

   // estrazione dei dati col keyframer: niente di piu' facile col c++ !!!
   if (rotationtrack.numkey>0)
   {
     rotationtrack.get_data(framepos, &objrot);
     quat_rotquat_to_matrix(&objrot, &currentmatrix_rot);
   }
   mat_copy(&currentmatrix_rot, &currentmatrix);

   if (scaletrack.numkey>0)
   {
     scaletrack.get_data(framepos, &stmp);
     mat_setmatrix_of_scaling(&scaling, stmp.x, stmp.y, stmp.z);
	 accum_scale.x*=stmp.x;
	 accum_scale.y*=stmp.y;
	 accum_scale.z*=stmp.z;
   }
   else mat_identity(&scaling);
   
   if (positiontrack.numkey>0) positiontrack.get_data(framepos, &currentpos);
   mat_setmatrix_of_pretraslation(&posttrans, &currentpos);

   mat_mul(&scaling, &currentmatrix_rot, &maux);
   mat_mul(&posttrans, &maux, &currentmatrix);
 
   if (father!=(AD_Object3D *)NULL)
   {
     mat_mulaffine(&father->currentmatrix_rot, &currentmatrix_rot, &currentmatrix_rot);
	 mat_mul(&father->currentmatrix, &currentmatrix, &currentmatrix);
     mat_mulvect(&father->currentmatrix, &currentpos, &postmp);
	 vect_copy(&postmp, &currentpos);
	 
	 accum_scale.x*=father->accum_scale.x;
	 accum_scale.y*=father->accum_scale.y;
	 accum_scale.z*=father->accum_scale.z;
   }

   mat_transpose(&currentmatrix_rot, &inverse_rotmatrix);
   mat_get_row(&currentmatrix, 1, &forza);
   vect_auto_normalize(&forza);
   vect_scale(&forza, strenght*0.00016f*forceScaleFactor, &forza);
}
コード例 #8
0
void AD_Object3D::precalc_radius(void)
{
  int16 i;
  float4 aux=-1.0, mn;
  AD_Vect3D midp, paux;

  vect_set(&midp, 0, 0, 0);
  for (i=0; i<num_vertex3D; i++)
  {
	vect_add(&midp, &vertex3D[i].point, &midp);
  }
  vect_scale(&midp, 1.0f/(float)num_vertex3D, &midp);
  vect_copy(&midp, &mid_point);

  for (i=0; i<num_vertex3D; i++)
  {
	vect_sub(&vertex3D[i].point, &midp, &paux);
	mn=vect_lenght(&paux);
    if (mn>aux) aux=mn;
  }
  radius=aux;
}
コード例 #9
0
ファイル: patch.cpp プロジェクト: ApocalypseDesign/ad_public
void AD_PatchObject::Evaluate_vDerivate(AD_Patch *p, float pu, float pv, AD_Vect3D *r)
{
  AD_Vect3D t;
  AD_Vect3D *vp = verteces;
  AD_Vect3D *vecp = vectors;
  int *v=p->vert;
  int *vec=p->vect;
  int *interior=p->interior;

  float pu2 = pu * pu;
  float pu1 = 1.0f - pu;
  float pu12 = pu1 * pu1;
  float u0 = pu12 * pu1;
  float u1 = 3.0f * pu * pu12;
  float u2 = 3.0f * pu2 * pu1;
  float u3 = pu2 * pu;

  // calcolo la derivata in v delle funzioni base
  float pv2 = pv * pv;
  float pv1 = 1.0f - pv;
  float v0 = -3.0f * pv1 * pv1;
  float v1 = 3.0f * pv1 * (1.0f - 3*pv);
  float v2 = 3.0f * pv * (2.0f - 3*pv);
  float v3 = 3.0f * pv2;

  vect_scale(&vp[v[0]], u0*v0, r);
  vect_scale(&vecp[vec[7]], u1*v0, &t);
  vect_add(r, &t, r);
  vect_scale(&vecp[vec[6]], u2*v0, &t);
  vect_add(r, &t, r);
  vect_scale(&vp[v[3]], u3*v0, &t);
  vect_add(r, &t, r);
  vect_scale(&vecp[vec[0]], u0*v1, &t);
  vect_add(r, &t, r);
  vect_scale(&vecp[interior[0]], u1*v1, &t);
  vect_add(r, &t, r);
  vect_scale(&vecp[interior[3]], u2*v1, &t);
  vect_add(r, &t, r);
  vect_scale(&vecp[vec[5]], u3*v1, &t);
  vect_add(r, &t, r);
  vect_scale(&vecp[vec[1]], u0*v2, &t);
  vect_add(r, &t, r);
  vect_scale(&vecp[interior[1]], u1*v2, &t);
  vect_add(r, &t, r);
  vect_scale(&vecp[interior[2]], u2*v2, &t);
  vect_add(r, &t, r);
  vect_scale(&vecp[vec[4]], u3*v2, &t);
  vect_add(r, &t, r);
  vect_scale(&vp[v[1]], u0*v3, &t);
  vect_add(r, &t, r);
  vect_scale(&vecp[vec[2]], u1*v3, &t);
  vect_add(r, &t, r);
  vect_scale(&vecp[vec[3]], u2*v3, &t);
  vect_add(r, &t, r);
  vect_scale(&vp[v[2]], u3*v3, &t);
  vect_add(r, &t, r);
}
コード例 #10
0
ファイル: patch.cpp プロジェクト: ApocalypseDesign/ad_public
// valuta la pezza in (pu, pv) e restituisce il risultato in r
void AD_PatchObject::Evaluate_Patch(AD_Patch *p, float pu, float pv, AD_Vect3D *r)
{
  AD_Vect3D t;
  AD_Vect3D *vp = verteces_tr;
  AD_Vect3D *vecp = vectors_tr;
  int *v=p->vert;
  int *vec=p->vect;
  int *interior=p->interior;

  float pu2 = pu * pu;
  float pu1 = 1.0f - pu;
  float pu12 = pu1 * pu1;
  float u0 = pu12 * pu1;
  float u1 = 3.0f * pu * pu12;
  float u2 = 3.0f * pu2 * pu1;
  float u3 = pu2 * pu;
  float pv2 = pv * pv;
  float pv1 = 1.0f - pv;
  float pv12 = pv1 * pv1;
  float v0 = pv12 * pv1;
  float v1 = 3.0f * pv * pv12;
  float v2 = 3.0f * pv2 * pv1;
  float v3 = pv2 * pv;

  vect_scale(&vp[v[0]], u0*v0, r);
  vect_scale(&vecp[vec[7]], u1*v0, &t);
  vect_add(r, &t, r);
  vect_scale(&vecp[vec[6]], u2*v0, &t);
  vect_add(r, &t, r);
  vect_scale(&vp[v[3]], u3*v0, &t);
  vect_add(r, &t, r);
  vect_scale(&vecp[vec[0]], u0*v1, &t);
  vect_add(r, &t, r);
  vect_scale(&vecp[interior[0]], u1*v1, &t);
  vect_add(r, &t, r);
  vect_scale(&vecp[interior[3]], u2*v1, &t);
  vect_add(r, &t, r);
  vect_scale(&vecp[vec[5]], u3*v1, &t);
  vect_add(r, &t, r);
  vect_scale(&vecp[vec[1]], u0*v2, &t);
  vect_add(r, &t, r);
  vect_scale(&vecp[interior[1]], u1*v2, &t);
  vect_add(r, &t, r);
  vect_scale(&vecp[interior[2]], u2*v2, &t);
  vect_add(r, &t, r);
  vect_scale(&vecp[vec[4]], u3*v2, &t);
  vect_add(r, &t, r);
  vect_scale(&vp[v[1]], u0*v3, &t);
  vect_add(r, &t, r);
  vect_scale(&vecp[vec[2]], u1*v3, &t);
  vect_add(r, &t, r);
  vect_scale(&vecp[vec[3]], u2*v3, &t);
  vect_add(r, &t, r);
  vect_scale(&vp[v[2]], u3*v3, &t);
  vect_add(r, &t, r);
}
コード例 #11
0
ファイル: syn_server.c プロジェクト: mikedw/synquake_tsx
void server_thread_generate_moves( server_thread_t* svt, int cycle )
{
	int i, j;
	tm_sv_client_t* cl;

        //change quest_times to have quests on/off
	int is_quest = ( sv.wl_quest_count &&
				cycle >= sv.quest_times[sv.quest_id] &&
				cycle  < sv.quest_times[sv.quest_id] + sv.wl_quest_duration
				);

	for( i = 0; i < sv.n_clients; i++ )
	{
		cl = sv.clients[i];
		if( cl->tid != svt->tid )	continue;

		tm_entity_movable_t* pl = cl->player;
		rect_t pl_r;
		rect_init4( &pl_r, pl->r.v1.x, pl->r.v1.y, pl->r.v2.x, pl->r.v2.y );
		value_t first_pl_dir = -1;
		for( j = 0; j < sv.n_multiple_actions; j++ )
		{
			if( !sv.randomized_actions )	cl->m_actions[j][M_ACT_ID] = sv.m_actions[j];
			else
			{
				int k, aux = rand_n( 100 );
				for( k = 0; k < n_actions; k++ )
					if( aux < sv.m_actions_ratios[k] )	break;
				assert( k < n_actions );
				cl->m_actions[j][M_ACT_ID] = k;
			}

			if( cl->m_actions[j][M_ACT_ID] == AC_MOVE )
			{
			        //burceam: so, if I understand this correctly, we give random direction and speed
			        //to players; then a bit below, (if( is_quest && ( (act_index % 2) != 0 ) )
			        //we generate a quest move, which will supersede the randomly-establised direction.
				cl->m_actions[j][M_ACT_SPD] = attribute_type_rand( &entity_types[ET_PLAYER]->attr_types[PL_SPEED] );
				cl->m_actions[j][M_ACT_DIR] = attribute_type_rand( &entity_types[ET_PLAYER]->attr_types[PL_DIR] );

				int act_index = cycle * sv.n_multiple_actions + j;
				
				if( is_quest && ( (act_index % 2) == 0 ) )
				{
					cl->m_actions[j][M_ACT_SPD] = cl->m_actions[j][M_ACT_SPD] / 4;
					if( entity_types[ET_PLAYER]->attr_types[PL_SPEED].min > cl->m_actions[j][M_ACT_SPD] )
						cl->m_actions[j][M_ACT_SPD] = entity_types[ET_PLAYER]->attr_types[PL_SPEED].min;
				}
				
				if( is_quest && ( (act_index % 2) != 0 ) )
					cl->m_actions[j][M_ACT_DIR] = server_thread_generate_quest_move( &pl_r, pl->ent_id );

				if( sv.straight_move )
				{
					if( first_pl_dir == -1 )	
					   first_pl_dir = cl->m_actions[j][M_ACT_DIR];
					else						
					   cl->m_actions[j][M_ACT_DIR] = first_pl_dir;
				}

				vect_t move_v;
				vect_scale( &dirs[cl->m_actions[j][M_ACT_DIR]], cl->m_actions[j][M_ACT_SPD], &move_v );
				vect_add( &pl_r.v1, &move_v, &pl_r.v1 );
				vect_add( &pl_r.v2, &move_v, &pl_r.v2 );
				// TO DO: change to allow multiple move records in file
				//server_register_player_move( pl, i );

				#ifdef PRINT_MOVES
				printf( "cl:%3d cycle:%3d j: %d ;   ", cl->cl_id, cycle, j );
				printf( "pos: %3d,%3d - last_dist %d ;  ", (coord_t)pl->r.v1.x, (coord_t)pl->r.v1.y, cl->last_dist );
				printf( "act: %5s spd: %d dir: %5s\n", action_names[ cl->m_actions[j][M_ACT_ID] ],
					cl->m_actions[j][M_ACT_SPD], dir_names[ cl->m_actions[j][M_ACT_DIR] ] );
				#endif
			}
		}
	}
}