当前位置: 首页>>代码示例>>C++>>正文


C++ MyVector::rotate方法代码示例

本文整理汇总了C++中MyVector::rotate方法的典型用法代码示例。如果您正苦于以下问题:C++ MyVector::rotate方法的具体用法?C++ MyVector::rotate怎么用?C++ MyVector::rotate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MyVector的用法示例。


在下文中一共展示了MyVector::rotate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: processColision

void MovableObject::processColision(Object *o){
	MovableObject* mo;
	MyVector *u1, *u2, *axis;
	MyVector *u1n, *u1t, *u2n;
	double alfa1,alfa2,beta1;
	double m1,m2;
	double v1n_s,v1_s,k,fi,new_x,new_y,diff;
	if(o->compute_hit){
	m1 = mass;
	m2 = o->mass;
	if((this->k >= 0) && (o->k >= 0))
		k = 1 - abs(o->k - this->k);
	else
		k = (this->k < o->k) ? this->k + 1 - o->k : o->k + 1 - this->k ;
	if (o->movable){
		mo = (MovableObject*) o;
		u2 = mo->getVector();
	}else{
		mo = NULL;
		u2 = new MyVector(0,0.01);
	}
	u1 = (MyVector*) malloc(sizeof(MyVector));
	(*u1) = result_vector;
	axis = new MyVector(o->getX() - x, o->getY() - y);
	alfa1 = u1->getAngle((*axis));
	alfa2 = u2->getAngle((*axis));
	u1n = new MyVector((*u1)[0],(*u1)[1]);
	u1t = new MyVector((*u1)[0],(*u1)[1]);
	u2n = new MyVector((*u2)[0],(*u2)[1]);

	(*u1n) *= cos(alfa1);
	(*u1t) *= sin(alfa1);
	(*u2n) *= cos(alfa2);

	v1n_s = (m1 * u1n->getSize() + m2 * u2n->getSize() - k * m2 * (u1n->getSize() - u2n->getSize())) / (m1 + m2);
	v1_s = sqrt(pow(v1n_s,2) + pow(u1t->getSize(),2)); // u1t == v1t
	beta1 = atan(u1t->getSize() / v1n_s);

	MyVector y_axis(0,1);
	fi = axis->getAngle(y_axis);
	diff = x - o->getX();

	if((cos(fi) >= 0) && (diff > 0)){
		new_y = y - cos(beta1) * v1_s;
		new_x = x - sin(beta1) * v1_s;
	}else if((cos(fi) >= 0) && (diff < 0)){
		new_y = y - cos(beta1) * v1_s;
		new_x = x + sin(beta1) * v1_s;
	}else if((cos(fi) <= 0) && (diff < 0)){
		new_y = y + cos(beta1) * v1_s;
		new_x = x + sin(beta1) * v1_s;
	}else if((cos(fi) <= 0) && (diff > 0)){
		new_y = y + cos(beta1) * v1_s;
		new_x = x - sin(beta1) * v1_s;
	}

	if((o->getX() - x >= 0) && (o->getY() - y >= 0))
		fi *= -1;
	else if((o->getX() - x < 0) && (o->getY() - y < 0))
		fi *= -1;

	if(!fi) fi = 0.001;

	MyVector w(new_x - x,new_y - y);
	w.rotate(fi);

	result_vector = w;
	}else{
		Mask *m = o->getMask();
		int *col = m->collision_pixel;
		MyVector *v, *w;
		double min_dist = 2000;
		for(int i = 0; i < 4; i++){
			v = m->sides[i];
			MyVector norm((*v)[1],(*v)[0] * -1);
			double c = -norm[0] * (v->getStartX()) - norm[1] * v->getStartY();
			double dist = abs(norm[0] * col[0] + norm[1] * col[1] + c) / norm.getSize();
			if(dist < min_dist){
				min_dist = dist;
				w = v;
			}
		}
		MyVector x_axis(1,0);
		double alfa = x_axis.getAngle(*w);
		MyVector *u = new MyVector(0,1);
		u->rotate(3.141592 / 2 - alfa);
		double f = 4;
		u->changeSize(3 * ACC_CONST * sin(alfa) * f);
		MyVector *u_n = new MyVector((*u)[1],(*u)[0]);
		u_n->changeSize(3 * ACC_CONST * cos(alfa));
		Node *first = (Node*)acceleration_list.getFirst();
		if(acceleration_list.getCount() == 1){
			acceleration_list.addNode(u,1);
			acceleration_list.addNode(u_n,1);
		}else{
			first = first->next;
			if(first)
				(*(MyVector*)(first->data)) = (*u_n);
			first = first->next;
			if(first)
//.........这里部分代码省略.........
开发者ID:vojtsek,项目名称:Machines,代码行数:101,代码来源:Object.cpp


注:本文中的MyVector::rotate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。