Beispiel #1
1
double crush(vector2 s, vector2 p, vector2 center, int r)
{
    // 이차 방정식 ax^2+bx+c=0 형태를 만든다
    double a = p.dot(p);
    double b = 2*(s-center).dot(p);
    double c = center.dot(center)+s.dot(s)-r*r-2*center.dot(s);

    double d = b*b - 4*a*c;

    // 전혀 안부딪힘
    if(d < 0) {
        return INFITY;
    } 

    // 시간t의 근은 무조건 양수 2개가 나와야 된다(또는 양수 중근)
    // 그 중 작은 값만 취하기 때문에 큰 값은 버린다
    double solv = (-b - sqrt(d)) / 2*a;
    // 음수가 하나라도 나오면 공은 장애물에 부딪히지 않는다
    if(solv < 0) {
        return INFITY;
    } else {
        return solv;
    }
}
Beispiel #2
0
static vector2 trunk(const vector2& v, number smallestVal)
{
	vector2 t;
	t.x() = smallestVal * round(v.x() / smallestVal);
	t.y() = smallestVal * round(v.y() / smallestVal);
	return t;
}
Beispiel #3
0
const vector2 vector2::operator / (const vector2 &v2) const
{
	vector2 r;
	r.x() = x() / v2.x();
	r.y() = y() / v2.y();
	return r;
}
Beispiel #4
0
vector2 vector2::Transform(const vector2& v, const matrix& m)
{
	vector2 result = vector2( 
								(v.x() * m(0,0)) + (v.y() * m(0,1)) + m(3,0),
								(v.x() * m(1,0)) + (v.y() * m(1,1)) + m(3,1));
	return result;
	
}
Beispiel #5
0
double hitCircle(vector2 here, vector2 dir, vector2 center, double radius) {
	double a = dir.dot(dir);
	double b = 2 * dir.dot(here - center);
	double c = center.dot(center) + here.dot(here) - 2 * here.dot(center) - radius * radius;
	vector<double> sols = equation(a, b, c);
	if (sols.empty() || sols[0] < EPSILON) return INF;
	return sols[0];
}
Beispiel #6
0
vector4 vector4::Transform(const vector2& v, const matrix& m)
{
	vector4 result = vector4(	
						(v.x() * m(0,0)) + (v.y() * m(1,0)) + m(3,0),
						(v.x() * m(0,1)) + (v.y() * m(1,1)) + m(3,1),
						(v.x() * m(0,2)) + (v.y() * m(1,2)) + m(3,2),
						(v.x() * m(0,3)) + (v.y() * m(1,3)) + m(3,3));
	return result;
	
}
Beispiel #7
0
vector<double> solve(vector2 here, vector2 dir, vector<vector2>& center, vector<double>& radius) {
	double n = center.size();
	dir = dir.normalize();
	vector<double> ret;
	double cnt=0;
	while (cnt < 100) {
		double circle = -1;
		double time = INF*0.5;

		for (double i = 0; i < n; ++i) {
			double cand = hitCircle(here, dir, center[i], radius[i] + 1);
			if (cand < time) {
				time = cand;
				circle = i;
			}
		}
		if (circle == -1) break;
		cnt++;
		ret.push_back(circle);
		vector2 contact = here + dir * time;

		dir = reflect(here, dir, center[circle], contact);
		here = contact;
	}
	return ret;
}
Beispiel #8
0
bool QtWindowSystem::init(const vector2<int>& r, int /*bpp*/, bool /*fullscreen*/)
{
	if (view_ == nullptr)
	{
		// check for Qt Application class instance
		if (QApplication::instance() == nullptr)
		{
			int argc = 0;
			static QApplication application(argc, nullptr);
		}
		view_ = new QtView;
		view_->setGeometry(0, 0, r.x(), r.y());
		set_format(WindowContextFormat());
	}

	return true;
}
Beispiel #9
0
edge::edge(vector2 a, vector2 uv_a, float z_a, vector2 b, vector2 uv_b, float z_b) {
	
	if (a.get_y() > b.get_y()) {
		this->a = b;
		this->uv_a = uv_b;
		this->b = a;
		this->uv_b = uv_a;
		this->z_b = z_a;
		this->z_a = z_b;
	}
	else {
		this->a = a;
		this->b = b;
		this->uv_a = uv_a;
		this->uv_b = uv_b;
		this->z_a = z_a;
		this->z_b = z_b;
	}
}
Beispiel #10
0
void MyCB(system::UINT32 msg, system::UINT64 wParam, system::UINT64 lParam)
{
    switch(msg)
    {
    case WM_DESTROY:
    case WM_QUIT:
        g_quit = true;
        break;

    case WM_MOUSEMOVE:
        g_mousePos.set((float)GET_X_LPARAM(lParam), (float)GET_Y_LPARAM(lParam));
        g_mouseLButtonDown = (wParam & MK_RBUTTON);
        break;
    }
}
Beispiel #11
0
void fn(vector2 W) {
	W.push_back(111);
	return;
}
Beispiel #12
0
// Equality operations
bool vector2::operator == (const vector2 &v) const
{
	return ((x() == v.x()) && (y() == v.y()));
}
Beispiel #13
0
float vector2::Dot(const vector2& v1, const vector2& v2)
{
	return v1.Dot(v2);
}
Beispiel #14
0
// Returns the dot product of two vectors
float vector2::Dot(const vector2 &v2) const
{
	return ((x() * v2.x()) + (y() * v2.y()));
}
Beispiel #15
0
vector3::vector3(const vector2& source, float z)
{ 
	v[0] = source.x(), v[1] = source.y(), v[2] = z; 
}
Beispiel #16
0
inline
bool operator ==(const vector2 &lhs, const vector2 &rhs) {
  return lhs.get_x() == rhs.get_x() && lhs.get_y() == rhs.get_y();
}
Beispiel #17
0
// 사영을 이용해 반사 방향벡터를 구한다
vector2 reflect(vector2 p, vector2 b)
{
    // 단위벡터로 만들어야 제대로된 답이 나온다
    return (p-p.project(b)*2).normalize();
}
Beispiel #18
0
int main()
{
    freopen ("in.txt", "r", stdin);

    int n, m, x, y, z, p;

    scanf ("%d %d %d %d %d %d", &n, &m, &x, &y, &z, &p);

    x %= 4;
    y %= 2;
    z %= 4;

    center = vector2((float)(n) / 2.0f, (float) (m) / 2.0f);

    vector2 v;
    vector2 location;

    printf ("center: "); center.print_debug();

    for (int i = 0; i < p; i++)
    {
        input.get();

        if (input.x < center.x)
            input.x += 0.5f;
        else if (input.x > center.x)
            input.x -= 0.5f;

        if (input.y < center.y)
            input.y += 0.5f;
        else if (input.y > center.y)
            input.y -= 0.5f;

        printf ("input: "); input.print_debug();

        v.x = input.x - center.x;
        v.y = input.y - center.y;

        printf ("v: "); v.print_debug();

        v.clockwise(x);

        v.print_debug();

        input.x = v.x + center.x;
        input.y = v.y + center.y;

        if (y > 0 && !cmp (input.y, center.y))
            input.y = center.y - input.y + center.y;

        v.x = input.x - center.x;
        v.y = input.y - center.y;

        v.counter_clockwise(z);

        location.x = center.x + v.x;
        location.y = center.y + v.y;

        location.print_debug();
    }

    return 0;
}
Beispiel #19
0
vector2 reflect(vector2 here, vector2 dir, vector2 center, vector2 contact) {
	return (dir - dir.project(contact - center) * 2).normalize();
}
Beispiel #20
0
// 원점에서 벡터 b 가 벡터 a 의 반시계 방향이면 양수, 시계 방향이면 음수, 평행이면 0 을 반환한다
double ccw(vector2 a, vector2 b) {
    return a.cross(b);
}
Beispiel #21
0
	vector2 project(const vector2& rhs) const {
		vector2 r = rhs.normalize();
		return r * r.dot(*this);
	}