fixutil.cpp

来自「一个symbian 冒险游戏代码」· C++ 代码 · 共 30 行

CPP
30
字号
#include "FixUtil.h"
#include <config.h>


//Returns whether the point (x, y) is right from the line (a, b) or not
bool FixUtil::getPointLineSide( Fix x, Fix y, const FixVec2& a, const FixVec2& b )
{
	x -= a.x;
	y -= a.y;
	Fix otherx = b.x - a.x;
	Fix othery = b.y - a.y;
	return x*othery-y*otherx <= Fix(0);
}

bool FixUtil::testLineLineIntersection( 
	const FixVec2& a0, const FixVec2& a1,
	const FixVec2& b0, const FixVec2& b1 )
{
	Fix n1 = (b1.x-b0.x)*(a0.y-b0.y) - (b1.y-b0.y)*(a0.x-b0.x);
	Fix n2 = (a0.y-b0.y)*(a1.x-a0.x) - (a0.x-b0.x)*(a1.y-a0.y);
    Fix dn = (a1.x-a0.x)*(b1.y-b0.y) - (a1.y-a0.y)*(b1.x-b0.x);
	if ( dn.v > 0 )
		return n1.v < dn.v && n2.v < dn.v && n1.v > 0 && n2.v > 0;
	else if ( dn.v < 0 )
		return n1.v > dn.v && n2.v > dn.v && n1.v < 0 && n2.v < 0;
	return false;
}

// End of File

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?