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


C++ Point2f::reset方法代码示例

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


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

示例1: polyPegCollision_p


//.........这里部分代码省略.........
				rebound._x = normal._x;
				rebound._y = normal._y;
				
			}
			
		}
	}
	//if Edge don't collision and check corner collision
	
	if(collisionDist == INFINITY)
	{
		for(int i = 0; i < subs; i++)
		{
			Point2f cornerToBall;
			cornerToBall = trans - vertices[i];
			cornerDist = cornerToBall.magnitude() - ball.radius;
			
			if(cornerDist < collisionDist)
			{
				cornerIndex = i;
				nextCornerIndex = i + 1;
				if(i == 0)
					prevCornerIndex = subs - 1;
				else
					prevCornerIndex = i - 1;
				
				collisionDist = cornerDist;
				
				cornerToBall.normalize();
				rebound._x = cornerToBall._x;
				rebound._y = cornerToBall._y;
				
				//calculate cornerNomral_1 and cornerNomral_2
				if(dotProduct(rebound, transVel) > 0.0)
				{
					//check a segment line from current corner and previous corner
					cornerNormal_1 = vertices[cornerIndex] - vertices[prevCornerIndex];
					cornerNormal_1.normalize();
					
					//check a segment line from current corner and next corner
					cornerNormal_2 = vertices[cornerIndex] - vertices[nextCornerIndex];	
					cornerNormal_2.normalize();
					
					if(dotProduct(cornerNormal_1, transVel) < 0.0)
					{
						rebound = cornerNormal_1;
					}
					else if(dotProduct(cornerNormal_2, transVel) < 0.0)
					{
						rebound = cornerNormal_2;
					}
					else
					{
						rebound.reset();
						collisionDist = INFINITY;
					}				
				}
			}
		}
		//normalize rebound 
		rebound.normalize();
		
	}
	
	
	
	if(collisionDist > 0.0f)
	{
		return false;
	}
	else
	{
		//calcuate component that gets mirrored
		orthogBallVelMag= dotProduct(rebound, transVel);
		transVel._x -= 2.0f * orthogBallVelMag * rebound._x;
		transVel._y -= 2.0f * orthogBallVelMag * rebound._y;
		
		//calculate transVelocity
		transPolyVelDotReb = dotProduct(rebound, transPegPolyVel);
		transVel._x += transPolyVelDotReb * rebound._x;
		transVel._y += transPolyVelDotReb * rebound._y;
		
		//setting ball's velocity with new velocity
		ball.velocity_p._x = cosf(rotation) * transVel._x - sinf(rotation) * transVel._y;
		ball.velocity_p._y = sin(rotation) * transVel._x + cosf(rotation) * transVel._y;
		
		//relocation ball
		trans._x -= 2.0 * collisionDist * rebound._x;
		trans._y -= 2.0 * collisionDist * rebound._y;
		
		orig._x = cosf(rotation) * trans._x - sinf(rotation) * trans._y;
		orig._y = sinf(rotation) * trans._x + cosf(rotation) * trans._y;
		
		ball.position_p = orig + position;
		
		return true;
	}
	
	
}
开发者ID:doomscout,项目名称:RTRASSIGN3,代码行数:101,代码来源:Peg.cpp

示例2: polyPegCollision


//.........这里部分代码省略.........
			cornerDist = cornerToBall.magnitude() - ball.radius;
			
			if(cornerDist < collisionDist)
			{
				cornerIndex = i;
				nextCornerIndex = i + 1;
				if(i == 0)
					prevCornerIndex = subs - 1;
				else
					prevCornerIndex = i - 1;
				
				collisionDist = cornerDist;
				
				cornerToBall.normalize();
				rebound._x = cornerToBall._x;
				rebound._y = cornerToBall._y;
				
				//calculate cornerNomral_1 and cornerNomral_2
				if(dotProduct(rebound, transVel) > 0.0)
				{
					//check a segment line from current corner and previous corner
					cornerNormal_1 = vertices[cornerIndex] - vertices[prevCornerIndex];
					cornerNormal_1.normalize();
					
					//check a segment line from current corner and next corner
					cornerNormal_2 = vertices[cornerIndex] - vertices[nextCornerIndex];	
					cornerNormal_2.normalize();
					
					if(dotProduct(cornerNormal_1, transVel) < 0.0)
					{
						rebound = cornerNormal_1;
					}
					else if(dotProduct(cornerNormal_2, transVel) < 0.0)
					{
						rebound = cornerNormal_2;
					}
					else
					{
						rebound.reset();
						collisionDist = INFINITY;
					}				
				}
			}
		}
		//normalize rebound 
		rebound.normalize();
		
		//visual Debug Mode
		if(visualDebug)
		{
			glPushMatrix();
			glTranslatef(position.getX(), position.getY(), 0.0);
			glRotatef(180.0f * rotation / PI_F, 0.0f, 0.0f, 1.0f);	
			glColor3f(1,0,0);
			glPointSize(3);
			glBegin(GL_POINTS);
			glVertex2f(
			vertices[cornerIndex]._x, 
			vertices[cornerIndex]._y);
			glEnd();
			glPopMatrix();		
		}
	}
	
	
	
	if(collisionDist > 0.0f)
	{
		return false;
	}
	else
	{
		//calcuate component that gets mirrored
		orthogBallVelMag= dotProduct(rebound, transVel);
		transVel._x -= 2.0f * orthogBallVelMag * rebound._x;
		transVel._y -= 2.0f * orthogBallVelMag * rebound._y;
		
		//calculate transVelocity
		transPolyVelDotReb = dotProduct(rebound, transPegPolyVel);
		transVel._x += transPolyVelDotReb * rebound._x;
		transVel._y += transPolyVelDotReb * rebound._y;
		
		//setting ball's velocity with new velocity
		ball.velocity._x = cosf(rotation) * transVel._x - sinf(rotation) * transVel._y;
		ball.velocity._y = sin(rotation) * transVel._x + cosf(rotation) * transVel._y;
		
		//relocation ball
		trans._x -= 2.0 * collisionDist * rebound._x;
		trans._y -= 2.0 * collisionDist * rebound._y;
		
		orig._x = cosf(rotation) * trans._x - sinf(rotation) * trans._y;
		orig._y = sinf(rotation) * trans._x + cosf(rotation) * trans._y;
		
		ball.position = orig + position;
		
		return true;
	}
	
	
}
开发者ID:doomscout,项目名称:RTRASSIGN3,代码行数:101,代码来源:Peg.cpp


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