コード例 #1
0
ファイル: rotate.c プロジェクト: NegMozzie/42
int		obj_rot(t_utils *utils, t_objet *list, int sens, int flag)
{
	if (flag == 0)
		utils = rot_eye(utils);
	else if (flag == 1 && list->type != SPHERE)
	{
		utils = rot_pos(utils, list, sens);
		utils = rot_vector(utils, list, sens);
	}
	else if (flag == 2 && list->type != SPHERE)
		utils = norm_rotate(utils, list, sens);
	return (0);
}
コード例 #2
0
// rotate raw values to arrive at final x,y,dx and dy values
void AP_OpticalFlow::apply_orientation_matrix()
{
    Vector3f rot_vector;
    rot_vector(raw_dx, raw_dy, 0);

    // next rotate dx and dy
    rot_vector.rotate(_orientation);

    dx = rot_vector.x;
    dy = rot_vector.y;

    // add rotated values to totals (perhaps this is pointless as we need
    // to take into account yaw, roll, pitch)
    x += dx;
    y += dy;
}
コード例 #3
0
void Space_Object::draw_orbit() {
	
	glPushMatrix();

	float t_x;
	float t_y;

	this->object_orbit.focus_translate(t_x, t_y);;

	glColor3f(0, 1, 0);
	glBegin(GL_LINE_LOOP);

	int i;
	for (i = 0; i<360; i++)
	{
		float rad = deg_to_rad(i);
		// Calculate rotation such that point will lie on new plane defined by orbital normal and the point of the parent.
		GLfloat trans_norm[3];
		GLfloat trans_non_normalizes[3];


		trans_non_normalizes[0] = trans_norm[0] =cos(rad)*this->object_orbit.ellipse_a + t_x;
		trans_non_normalizes[1] = trans_norm[1] = sin(rad)*this->object_orbit.ellipse_b + t_y;
		trans_non_normalizes[2] = trans_norm[2] =  0.0f;
		normalize_vector(trans_norm);

		GLfloat up_norm[] = { 0, 0, 1 };
		GLfloat rot_axis[3];
		vector_cross(up_norm, this->orbit_plane.planeNormal, rot_axis);


		GLfloat rot_angle = asin(vector_length(rot_axis));
		rot_vector((rot_angle), rot_axis[0], rot_axis[1], rot_axis[2], trans_non_normalizes);

		trans_non_normalizes[0] += this->parent_pos[0];
		trans_non_normalizes[1] += this->parent_pos[1];
		trans_non_normalizes[2] += this->parent_pos[2];
		glVertex3fv(trans_non_normalizes);
	}

	glEnd();

	glPopMatrix();
}
コード例 #4
0
void Space_Object::updateOrbit() {
	// For Kepler's formula it will be necessary to use the mass of this object, the mass of the parent, and the speed 
	// to calculate parameters for ellispe, etc
	float temp = this->object_orbit.orbital_theta;

	// THERE IS A BIT OF A MATH BUG RIGHT NOW GO OVER IT SO THAT IT ACCELERATES AT THE RIGHT PLACES
	this->object_orbit.orbital_theta = fmod(temp + atanf((2 * orbit_area) / (orbit_rad*orbit_rad))*this->object_orbit.rate_mod, (2 * M_PI));

	if (this->object_orbit.ellipse_a != 0 && this->object_orbit.ellipse_b != 0) {
		GLfloat translate_vec[3];
		GLfloat rot_axis[3];

		// Default normal is 0,0,1 (x,y plane)
		GLfloat up_norm[] = { 0, 0, 1 };

		float calc_rad = this->object_orbit.curr_rad();
		float x_movement = -calc_rad * cos(this->object_orbit.orbital_theta);
		float y_movement = -calc_rad * sin(this->object_orbit.orbital_theta);

		// W.r.t parent there is no vertical translation at this stage (it is calculcated during rotation phase)
		translate_vec[2] = 0;
		this->object_orbit.focus_translate(translate_vec[0], translate_vec[1]);

		// Calculate rotation such that point will lie on new plane defined by orbital normal and the point of the parent.
		GLfloat trans_norm[3];
		GLfloat trans_non_normalizes[3];
		
		// Position w.r.t parent
		trans_non_normalizes[0] = trans_norm[0] = x_movement + translate_vec[0];
		trans_non_normalizes[1] = trans_norm[1] = y_movement + translate_vec[1];
		trans_non_normalizes[2] = trans_norm[2] = 0.0f;

		// Normalize vector (used for plane calculations)s
		normalize_vector(trans_norm);

		/**
		* CITING:
		* https://gamedev.stackexchange.com/questions/50880/rotating-plane-to-be-parallel-to-given-normal-via-change-of-basis
		* for mathematical reference to this calculation
		*/

		vector_cross(up_norm, this->orbit_plane.planeNormal, rot_axis);

		// Calculate rotation angle to switch to new plane
		GLfloat rot_angle = asin(vector_length(rot_axis));

		// Rotate the point to lie on new plane
		rot_vector((rot_angle), rot_axis[0], rot_axis[1], rot_axis[2], trans_non_normalizes);
		
		// Move w.r.t parent position
		this->world_pos[0] = this->parent_pos[0] + trans_non_normalizes[0];
		this->world_pos[1] = this->parent_pos[1] + trans_non_normalizes[1]; 
		this->world_pos[2] = this->parent_pos[2] + trans_non_normalizes[2];

		// Calculate new orbital radius (used for kepler's calculations)
		orbit_rad = sqrt((translate_vec[0] + x_movement)*(translate_vec[0] + x_movement) + (translate_vec[1] + y_movement)*(translate_vec[1] + y_movement));
	}
	else {
		this->world_pos[0] = 0;
		this->world_pos[1] = 0;
		this->world_pos[2] = 0;
	}

	rotate(this->rotation_rate);

	// Update Satellites
	if (this->satellites.size() > 0) {
		for (Space_Object * o : this->satellites) {
			o->set_parent_pos(this->world_pos[0], this->world_pos[1], this->world_pos[2]);
			o->updateOrbit();
		}
	}
}