Exemple #1
0
void Physics::Forces(Vektor &velocity, float c, float aWeight, float dt)
{
	Vektor Fg = Physics::Gravity(aWeight);

	Vektor Fd = Physics::AirResistance(velocity, c);
	if(velocity.z < 0)
		Fd.z = -Fd.z;
	if(velocity.x < 0)
		Fd.x = -Fd.x;
	Vektor Ft = Vektor(Fd.x + Fg.x, Fd.y + Fg.y, Fd.z + Fg.z);

	Vektor acc = Vektor((Ft.x / aWeight), (Ft.y / aWeight), (Ft.z / aWeight));

	Physics::VelocityChange(velocity, acc, dt);


}
Exemple #2
0
Vektor Physics::Wind()
{
	float wind_x = 0; float wind_y = 0;
	
	wind_x = hge->Random_Float(-7.5f, 7.5f); // by removing half of what the maximum value can be,
	wind_y = hge->Random_Float(-7.5f, 7.5f); // roughly 50% of the values will be negative

	return Vektor(wind_x, wind_y, 0);  // wind speed will be  -7.5 < (x,y) < 7.5   => max speed = sqrt(2*7.49) ~= 10.6 m/s
}
Exemple #3
0
Vektor Physics::AirResistance(Vektor &velocity, float c)
{
	//F=c*v^2

	float Fx = c * pow(velocity.x, 2);
	float Fy = c * pow(velocity.y, 2);
	float Fz = c * pow(velocity.z, 2);

	return Vektor(Fx, Fy, Fz);
}
Exemple #4
0
//Rendering functions.
void MAPGEN::set_light(float az, float alt){
	az *= 0.034906585;
	alt *= 0.0174532925;

	float lx, ly, lz;
	lx = 10*sin(az);
	ly = -10*cos(az);
	lz = 10*sin(alt);
	lx *= cos(alt);
	ly *= cos(alt);
	ljus=Vektor(lx, ly, lz);
}
Exemple #5
0
Vektor Physics::CrossProduct(Vektor first, Vektor second)
{
	
	float x,y,z;
	
	//Räknar ut vektorprodukt mellan två vektorer
	x = first.y * second.z - first.z * second.y;
	y = first.z * second.x - first.x * second.z;
	z = first.x * second.y - first.y * second.x;

	return Vektor(x, y, z);
}
Exemple #6
0
Vektor Physics::ArrowInitialVelocity(Bow *bow, float aWeight, float angleUD, float angleSTS)
{
	// Calculate initiate speed for the arrow.
	float velocity = (sqrt(bow->GetEp() * 2 / (aWeight + bow->GetK() * bow->GetWeight())) * 100);


	// Convert angle from degrees to radians.
	float angleUDrad = M_PI / 2 - Physics::DegreeToRad(angleUD);
	float angleSTSrad = M_PI / 2 - Physics::DegreeToRad(angleSTS);


	// Using Spherical coordinate system to find out the velocity-vector using 2 angles.
	float v_x = velocity * sin(angleUDrad) * cos(angleSTSrad);
	float v_y = velocity * sin(angleUDrad) * sin(angleSTSrad);
	float v_z = velocity * cos(angleUDrad);

	return Vektor(v_x, v_y, v_z);
}
Vektor
bicubic_bezier_patch::normal ( float u,float v )
{
	float h[4][4];
	memcpy ( h,m_ps,16*sizeof ( float ) );

	h[0][0]= ( 1-u ) * ( ( 1-v ) *h[0][0]+v*h[0][1] ) +u* ( ( 1-v ) *h[1][0]+v*h[1][1] );
	h[0][1]= ( 1-u ) * ( ( 1-v ) *h[0][1]+v*h[0][2] ) +u* ( ( 1-v ) *h[1][1]+v*h[1][2] );
	h[0][2]= ( 1-u ) * ( ( 1-v ) *h[0][2]+v*h[0][3] ) +u* ( ( 1-v ) *h[1][2]+v*h[1][3] );
	h[1][0]= ( 1-u ) * ( ( 1-v ) *h[1][0]+v*h[1][1] ) +u* ( ( 1-v ) *h[2][0]+v*h[2][1] );
	h[1][1]= ( 1-u ) * ( ( 1-v ) *h[1][1]+v*h[1][2] ) +u* ( ( 1-v ) *h[2][1]+v*h[2][2] );
	h[1][2]= ( 1-u ) * ( ( 1-v ) *h[1][2]+v*h[1][3] ) +u* ( ( 1-v ) *h[2][2]+v*h[2][3] );
	h[2][0]= ( 1-u ) * ( ( 1-v ) *h[2][0]+v*h[2][1] ) +u* ( ( 1-v ) *h[3][0]+v*h[3][1] );
	h[2][1]= ( 1-u ) * ( ( 1-v ) *h[2][1]+v*h[2][2] ) +u* ( ( 1-v ) *h[3][1]+v*h[3][2] );
	h[2][2]= ( 1-u ) * ( ( 1-v ) *h[2][2]+v*h[2][3] ) +u* ( ( 1-v ) *h[3][2]+v*h[3][3] );
	h[0][0]= ( 1-u ) * ( ( 1-v ) *h[0][0]+v*h[0][1] ) +u* ( ( 1-v ) *h[1][0]+v*h[1][1] );
	h[0][1]= ( 1-u ) * ( ( 1-v ) *h[0][1]+v*h[0][2] ) +u* ( ( 1-v ) *h[1][1]+v*h[1][2] );
	h[1][0]= ( 1-u ) * ( ( 1-v ) *h[1][0]+v*h[1][1] ) +u* ( ( 1-v ) *h[2][0]+v*h[2][1] );
	h[1][1]= ( 1-u ) * ( ( 1-v ) *h[1][1]+v*h[1][2] ) +u* ( ( 1-v ) *h[2][1]+v*h[2][2] );
	return Vektor (	- ( ( ( ( 1-v ) *h[0][1]+v *h[1][1] )- ( ( 1-v ) *h[0][0]+v *h[1][0] ) ) / 1 ),
	                - ( ( ( ( 1-u ) *h[1][0]+u *h[1][1] )- ( ( 1-u ) *h[0][0]+u *h[0][1] ) ) / 1 ),
	                3 );
}
Exemple #8
0
Vektor Physics::Gravity(float aWeight)
{
	float Fz = GRAV * aWeight;

	return Vektor(0, 0, Fz); 
}
Exemple #9
0
	Vektor Vektor::operator*(double lhs)
	{

		return Vektor(v1*lhs, v2*lhs, v3*lhs);
	
	}