Esempio n. 1
0
// Determines if 2D segments have a unique intersection.
// If true and rpoint is not NULL, returns intersection point.
// May not have been discussed in class.
bool Intersects(const Segment2D& seg1, const Segment2D& seg2, Point2D *rpoint)
{
  Vector2D u = seg1.point2 - seg1.point1;
  Vector2D v = seg2.point2 - seg2.point1;

  if ( !vsLine2D( Line2D( seg1.point1, u ), Line2D( seg2.point1, v ) ) )
    return false;

  if ( !vsLine2D( Line2D( seg2.point1, v ), Line2D( seg1.point1, u ), rpoint ) )
    return false;

  return true;
}
Esempio n. 2
0
bool intersect2d::aabb_triangle(const AABB_2D &aabb, const Triangle2D &tri) {
	//First check if any of the triangles corners is in the aabb:
	if(aabb.contains(tri.p1) || aabb.contains(tri.p2) || aabb.contains(tri.p3)) return true;

	//Then if any of the aabb corners are in the triangle
	for(const glm::vec2 & c: aabb.corners()) {
		if(tri.contains(c)) return true;
	}

	//Then test if any lines intersect:
	return	aabb_line(aabb, Line2D(tri.p1, tri.p2)) ||
					aabb_line(aabb, Line2D(tri.p2, tri.p3)) ||
					aabb_line(aabb, Line2D(tri.p3, tri.p1));

}
Esempio n. 3
0
	TextureMapper2D::TextureMapper2D(const Polygon3D& polygon, const vector<ofVec2f>& texCoords, int originVertex)
		 : polygon(polygon), texCoords(texCoords), originVertex(originVertex)
	{
		assert(polygon.getVertexs().size() == texCoords.size());
		assert(inRange(originVertex, 0, (int)polygon.getVertexs().size() - 1));
		for (int i = 0; i < texCoords.size(); ++i)
		{
			texEdges.push_back(Line2D(texCoords[i], texCoords[(i + 1) % texCoords.size()]));
		}
	}
Esempio n. 4
0
Line2D
Line2D::getNormalLine(double px, double py) {
  Eigen::Vector3d vn;

  /*Calc the normal*/
  vn(0) = this->v(1);
  vn(1) = -this->v(0);
  vn(2) = -(px*vn(0) + py*vn(1)); //Solve equation Ax+By+C with central point

  return Line2D(vn);
}
Esempio n. 5
0
/*!

 */
Line2D
Line2D::perpendicular_bisector( const Vector2D & p1,
                                const Vector2D & p2 )
{
    if( std::fabs( p2.x - p1.x ) < EPSILON
        && std::fabs( p2.y - p1.y ) < EPSILON )
    {
        // input points have same coordiate values.
        std::cerr << "(Line2D::perpendicular_bisector)"
                  << " ***ERROR*** input points have same coordinate values "
                  << p1 << p2
                  << std::endl;
        return Line2D( p1, Vector2D( p1.x + 1.0, p1.y ) );
    }

    double tmp = ( p2.x*p2.x - p1.x*p1.x
                   + p2.y*p2.y - p1.y*p1.y ) * -0.5 ;
    return Line2D( p2.x - p1.x,
                   p2.y - p1.y,
                   tmp );
}
Esempio n. 6
0
std::vector< toxi::geom::Line2D > toxi::geom::Polygon2D::getEdges()
{
	int num = vertices.size();
	std::vector< Line2D > edges;
	for( int i = 0; i < num; i++ )
	{
		int i2 = (i + 1 ) % num;
		//int i2 = std::fmod( ( i + 1 ), num );
		edges.push_back( Line2D( vertices[i], vertices[ i2 ] ) );
	}
	return edges;
}
Esempio n. 7
0
void
ROWdrawAction_drawLane2LaneConnections(const GUILaneWrapper &lane) {
    unsigned int noLinks = lane.getLinkNumber();
    for (unsigned int i=0; i<noLinks; ++i) {
        MSLink::LinkState state = lane.getLane().getLinkCont()[i]->getState();
        const MSLane *connected = lane.getLane().getLinkCont()[i]->getLane();
        if (connected==0) {
            continue;
        }
        switch (state) {
        case MSLink::LINKSTATE_TL_GREEN_MAJOR:
        case MSLink::LINKSTATE_TL_GREEN_MINOR:
            glColor3d(0, 1, 0);
            break;
        case MSLink::LINKSTATE_TL_RED:
            glColor3d(1, 0, 0);
            break;
        case MSLink::LINKSTATE_TL_YELLOW_MAJOR:
        case MSLink::LINKSTATE_TL_YELLOW_MINOR:
            glColor3d(1, 1, 0);
            break;
        case MSLink::LINKSTATE_TL_OFF_BLINKING:
            glColor3d(1, 1, 0);
            break;
        case MSLink::LINKSTATE_TL_OFF_NOSIGNAL:
            glColor3d(0, 1, 1);
            break;
        case MSLink::LINKSTATE_MAJOR:
            glColor3d(1, 1, 1);
            break;
        case MSLink::LINKSTATE_MINOR:
            glColor3d(.2, .2, .2);
            break;
        case MSLink::LINKSTATE_EQUAL:
            glColor3d(.5, .5, .5);
            break;
        case MSLink::LINKSTATE_DEADEND:
            glColor3d(0, 0, 0);
            break;
        }

        glBegin(GL_LINES);
        const Position2D &p1 = lane.getShape()[-1];
        const Position2D &p2 = connected->getShape()[0];
        glVertex2f(p1.x(), p1.y());
        glVertex2f(p2.x(), p2.y());
        glEnd();
        GLHelper::drawTriangleAtEnd(Line2D(p1, p2), (SUMOReal) .4, (SUMOReal) .2);
    }
}
Esempio n. 8
0
void ConvexPolygon2D::ClipToLine(const Line2D &line) {
  if (GetPointCount() == 0) return;
  std::vector<D3DXVECTOR2> new_points;
  D3DXVECTOR2 p0 = points_[points_.size()-1];
  bool p0_inside = line.Distance(p0) < 0;
  std::vector<D3DXVECTOR2>::const_iterator it;
  for (it = points_.begin(); it != points_.end(); ++it) {
    const D3DXVECTOR2 &p1 = *it;
    bool p1_inside = line.Distance(p1) < 0;
    if (p0_inside && p1_inside) {
      new_points.push_back(p1);
    } else if (p0_inside && !p1_inside) {
      new_points.push_back(line.Intersection(Line2D(p0, p1)));
    } else if (!p0_inside && p1_inside) {
      new_points.push_back(line.Intersection(Line2D(p0, p1)));
      new_points.push_back(p1);
    } else {
      // do nothing
    }
    p0 = p1;
    p0_inside = p1_inside;
  }
  points_.swap(new_points);
}
Esempio n. 9
0
Line2D lineToLine2D(const Line& l)
{
    Point a=l.getPointA();
    Point b=l.getPointB();
    return Line2D(a,b);
    /*double aa=a.getX();
    double bb=a.getY();
    double cc=b.getX();
    double dd=b.getY();
    
    double slope=(bb-dd)/(aa-cc);
    double intercept=(aa*dd-bb*cc)/(aa-cc);
    
    std::cout << "y=" << slope << "x+" << intercept << "\n";*/
}
Esempio n. 10
0
WorldObject::WorldObject() {
  seen = false;

  frameLastSeen = -1;
  type = WO_INVALID;
  visionDistance=0.0;
  visionElevation=0.0;
  visionBearing=0.0;
  distance=0.0;
  elevation=0.0;
  bearing=0.0;
  relVel=Vector2D(0.0, 0.0);
  loc = Point2D(0, 0);
  lineLoc = Line2D(loc, loc);
  orientation=0.0;
  sd= Point2D(0.0, 0.0);
  sdOrientation=0.0;
  absVel= Point2D(0.0, 0.0);
  imageCenterX=0;
  imageCenterY=0;
  fieldLineIndex = -1;
  fromTopCamera = false;
}
Esempio n. 11
0
//----------------------------------------------------------------------------
void SimplePendulum::SolveMethod (float* (*method)(float,float,float),
                                  const char* outImage, const char* outText)
{
	float x0 = 0.1f, y0 = 1.0f;
	float h = 0.1f;

	float* output = method(x0, y0, h);
	std::string path = Environment::GetPathW(outText);
	std::ofstream outFile(path.c_str());
	int i;
	for (i = 0; i < SIZE; ++i)
	{
		outFile << "i = " << i << ", " << output[i] << std::endl;
	}

	// Set image to white.
	for (i = 0; i < msImage->GetQuantity(); ++i)
	{
		(*msImage)[i] = GetColor24(255, 255, 255);
	}

	// Draw the approximate solution.
	float y = 256.0f*(output[0] + 3.0f)/6.0f;
	int iY0 = SIZE - 1 - (int)y;
	for (i = 1; i < SIZE; ++i)
	{
		y = 256.0f*(output[i] + 3.0f)/6.0f;
		int iY1 = SIZE - 1 - (int)y;
		Line2D(i - 1, iY0, i, iY1, DrawPixel);
		iY0 = iY1;
	}

	path = Environment::GetPathW(outImage);
	msImage->Save(path.c_str());

	delete1(output);
}
Esempio n. 12
0
Polygon2D halfBanana(std::vector<Line2D>& lines) {
    int n = (int)lines.size() + 4;
    int l, r;
    std::vector<Line2D> deq(n);
    // infinite square boundary
    lines.push_back(Line2D(Vector2D(-INF, -INF), Vector2D( 1,  0)));
    lines.push_back(Line2D(Vector2D( INF, -INF), Vector2D( 0,  1)));
    lines.push_back(Line2D(Vector2D( INF,  INF), Vector2D(-1,  0)));
    lines.push_back(Line2D(Vector2D(-INF,  INF), Vector2D( 0, -1)));
    // sort
    std::sort(lines.begin(), lines.end(), cmpBySlope);
    // find intersection result
    l = 0;
    r = -1;
#define deqSize (r-l+1)
    for(int i=0; i<n; ++i) {
        if(deqSize > 0 && lines[i].parallel(deq[r])) {
            if(lines[i].side(deq[r].p0) >= 0) continue;
            if(deqSize == 1) {
                deq[r] = Line2D(lines[i]);
                continue;
            }
        }
        while(deqSize > 1 && lines[i].side(deq[r].intersect(deq[r-1])) <= 0) r--;
        while(deqSize > 1 && lines[i].side(deq[l].intersect(deq[l+1])) <= 0) l++;
        if(deqSize == 1 && deq[r].ang() + M_PI < lines[i].ang()) return Polygon2D();
        deq[++r] = Line2D(lines[i]);
    }
    while(deqSize > 1 && deq[l].side(deq[r].intersect(deq[r-1])) <= 0) r--;
    if(deqSize < 3) return Polygon2D();
    // generate polygon
    Polygon2D ret;
    for(int i=l; i<r; ++i) ret.push(deq[i].intersect(deq[i+1]));
    ret.push(deq[l].intersect(deq[r]));
    return ret;
}
Esempio n. 13
0
void LinkLinkComponent::render(Graphics& g) {
	LinkComponentStyle* style = (LinkComponentStyle*)this->style;
	if(!style) return;

	g.set_opacity(style->opacity);

	if(!style->glows.empty() && !style->noglows) {
		Vector2D a = src->center(),b = dst->center();
		Vector2D normal = (b-a).normalize().normal();
		Rectangle r = bezier_absolute().get_bounds(); r.augment(1000/canvas->get_zoom());
		double cursize = 0;
		for(uint i=0; i<style->glows.size(); i++) {
			g.reset_clip();
			Circle2D csrc(src->get_bounds().augment(cursize/canvas->get_zoom()));
			Circle2D cdst(dst->get_bounds().augment(cursize/canvas->get_zoom()));
			g.rectangle(r);
			g.mask_circle(csrc);
			g.rectangle(r);
			g.mask_circle(cdst);
			Vector2D n = normal*(cursize/canvas->get_zoom());
			g.line(Line2D(src->center()-n, dst->center()-n));
			g.line(Line2D(src->center()+n, dst->center()+n));
			g.stroke_alpha(style->glows[i].color, (i==0? 2:1)*style->glows[i].size/canvas->get_zoom(), style->glows[i].alpha * style->opacity);
			cursize += (i==0? 1.5:1)*style->glows[i].size;

			// Blur last
			if(i==style->glows.size()-1  && style->bPretty) {
				cursize -= 0.5*style->glows[i].size;
				float alpha = style->glows[i].alpha/2;
				while(alpha > 0.01) {
					alpha *= 0.8;
					Vector2D n = normal*(cursize/canvas->get_zoom());
					g.line(Line2D(src->center()-n, dst->center()-n));
					g.line(Line2D(src->center()+n, dst->center()+n));
					g.stroke_alpha(style->glows[i].color, 4/canvas->get_zoom(), alpha * style->opacity);
					cursize += 2;
				}
			}
		}
	}

	g.set_color(style->color);
	g.set_font(style->font_size, style->font, style->font_style);
	if(style->dashed > 0) g.dash(style->dashed);
	render_line(g, link->bSelected ? style->thickness_selected : style->thickness);
	double t1 = render_arrow(g, _scale * (link->bSelected ? style->arrow_size_selected : style->arrow_size ));


	Bezier b = bezier_absolute();
	double t2 = -1;

	if(style->slashes) {
		if(t2==-1) t2 = b.intersect_location(src->get_bounds());
		if(t2==-1) t2 = 0;
		g.draw_slashes(style->slashes,  b.get((t1+t2)/2), b.get((t1+t2)/2 - 0.01));
	}

	g.scale(_scale);

	if(!link->text.empty() || !link->text2.empty()) {
		if(t2==-1) t2 = b.intersect_location(src->get_bounds());
		if(t2==-1) t2 = 0;
		Vector2D p = b.get((t1+t2)/2);
		if(!link->text.empty() && (style->bText || LinkComponentStyle::bText_force)) {
			Rectangle r(p.x, p.y+6, 0,0);
			r.x /= _scale; r.y /= _scale;
			g.text(link->text, r);
		}
		if(!link->text2.empty() && (style->bText2 || LinkComponentStyle::bText2_force)) {
			Rectangle r(p.x, p.y-6, 0,0);
			r.x /= _scale; r.y /= _scale;
			g.set_font(style->font_size_text2, style->font_text2, style->font_style_text2);
			g.text(link->text2, r);
		}
	}
}
Esempio n. 14
0
long FAR PASCAL 
WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    static int xc = WSIZE/2;
    static int yc = WSIZE/2;
    static int xa, ya, xb, yb;
    static int a = WSIZE/4, b = WSIZE/8;

    switch ( message ) 
    {
    case WM_CREATE:
    {
#ifdef TEST_GEN
        RandomAxes(xa,ya,xb,yb);
#endif
        return 0;
    }
    case WM_PAINT:
    {
        PAINTSTRUCT ps;
        g_hDC = BeginPaint(hWnd,&ps);

#ifdef TEST_ARC
        // Test elliptical arc drawing.  Keep pressing 'n' to get new
        // arcs to draw.

        float dx0 = -a + 2.0f*a*(rand()/float(RAND_MAX));
        float sign0 = 2.0f*( rand() % 2 ) - 1.0f;
        float fx0 = xc + dx0;
        float fy0 = yc + sign0*b*float(sqrt(fabs(1.0f-dx0*dx0/(a*a))));

        float dx1 = -a + 2.0f*a*(rand()/float(RAND_MAX));
        float sign1 = 2.0f*( rand() % 2 ) - 1.0f;
        float fx1 = xc + dx1;
        float fy1 = yc + sign1*b*float(sqrt(fabs(1.0f-dx1*dx1/(a*a))));
        EllipseArc2D(xc,yc,a,b,fx0,fy0,fx1,fy1,DrawEllipsePixel);
#endif

#ifdef TEST_GEN

        // draw bounding rectangle
        Line2D(xc-xa-xb,yc-ya-yb,xc+xa-xb,yc+ya-yb,DrawLinePixel);
        Line2D(xc+xa-xb,yc+ya-yb,xc+xa+xb,yc+ya+yb,DrawLinePixel);
        Line2D(xc+xa+xb,yc+ya+yb,xc-xa+xb,yc-ya+yb,DrawLinePixel);
        Line2D(xc-xa+xb,yc-ya+yb,xc-xa-xb,yc-ya-yb,DrawLinePixel);

        // draw oriented ellipse
        GeneralEllipse2D(xc,yc,xa,ya,xb,yb,DrawEllipsePixel);
#endif   
        EndPaint(hWnd,&ps);
        return 0;
    }
    case WM_CHAR:
    {
        switch ( wParam )
        {
        case 'n':
        case 'N':
#ifdef TEST_GEN
            RandomAxes(xa,ya,xb,yb);
#endif
            InvalidateRect(hWnd,NULL,TRUE);
            break;
        case 'q':
        case 'Q':
        case VK_ESCAPE:
            PostMessage(hWnd,WM_DESTROY,0,0);
        }
        return 0;
    }
    case WM_DESTROY:
    {
        PostQuitMessage(0);
        return 0;
    }
    }
    return DefWindowProc(hWnd,message,wParam,lParam);
}
Esempio n. 15
0
//----------------------------------------------------------------------------
void GeodesicHeightField::OnIdle ()
{
	MeasureTime();

	if (MoveCamera())
	{
		mCuller.ComputeVisibleSet(mScene);
	}

	if (MoveObject())
	{
		mScene->Update();
		mCuller.ComputeVisibleSet(mScene);
	}

	if (mSelected == 2)
	{
		int currQuantity = mGeodesic->GetCurrentQuantity();
		if (currQuantity == 0)
		{
			currQuantity = mPQuantity;
		}

		// Clear the texture image to white.
		memset(mTexture->GetData(0), 0xFF, mTexture->GetNumLevelBytes(0));

		// Draw the approximate path.
		int bound0 = mTexture->GetDimension(0, 0);
		int bound1 = mTexture->GetDimension(1, 0);
		int x0 = (int)(bound0*mPath[0][0] + 0.5);
		int y0 = (int)(bound1*mPath[0][1] + 0.5);
		for (int i = 1; i < currQuantity; ++i)
		{
			int x1 = (int)(bound0*mPath[i][0] + 0.5);
			int y1 = (int)(bound1*mPath[i][1] + 0.5);
			Line2D(x0, y0, x1, y1, DrawCallback);
			x0 = x1;
			y0 = y1;
		}

		mTexture->GenerateMipmaps();
	}

	if (mRenderer->PreDraw())
	{
		mRenderer->ClearBuffers();
		mRenderer->Draw(mCuller.GetVisibleSet());
		DrawFrameRate(8, GetHeight()-8, mTextColor);

		char message[256];
		sprintf(message,
		        "sub = %d, ref = %d, len = %15.12lf, avgcrv = %15.12lf",
		        mGeodesic->GetSubdivisionStep(),
		        mGeodesic->GetRefinementStep(),
		        mDistance, mCurvature/mDistance);
		mRenderer->Draw(8, 16, mTextColor, message);

		mRenderer->PostDraw();
		mRenderer->DisplayColorBuffer();
	}

	UpdateFrameCount();
}
Esempio n. 16
0
//----------------------------------------------------------------------------
void SimplePendulum::Stiff1 ()
{
	const int maxIterations = 1024 + 256;
	const float cSqr = 2.0f, c = Mathf::Sqrt(2.0f);

	float h = 0.01f;
	float x0 = 1.0f, x0Save = x0;
	float y0 = -c*x0;

	float* approx = new1<float>(maxIterations);
	int i;
	for (i = 0; i < maxIterations; ++i)
	{
		float k1X = h*y0;
		float k1Y = h*cSqr*x0;
		float x1 = x0 + 0.5f*k1X;
		float y1 = y0 + 0.5f*k1Y;
		float k2X = h*y1;
		float k2Y = h*cSqr*x1;
		x1 = x0 + 0.5f*k2X;
		y1 = y0 + 0.5f*k2Y;
		float k3X = h*y1;
		float k3Y = h*cSqr*x1;
		x1 = x0 + k3X;
		y1 = y0 + k3Y;
		float k4X = h*y1;
		float k4Y = h*cSqr*x1;
		x1 = x0 + (k1X + 2.0f*k2X + 2.0f*k3X + k4X)/6.0f;
		y1 = y0 + (k1Y + 2.0f*k2Y + 2.0f*k3Y + k4Y)/6.0f;

		approx[i] = x1;
		x0 = x1;
		y0 = y1;
	}

	std::string path = Environment::GetPathW("Data/stiff1.txt");
	std::ofstream outFile(path.c_str());
	for (i = 0; i < maxIterations; ++i)
	{
		outFile << "i = " << i << ", " << approx[i] << std::endl;
	}

	// Set image to white.
	for (i = 0; i < msImage->GetQuantity(); ++i)
	{
		(*msImage)[i] = GetColor24(255, 255, 255);
	}

	// Draw the true solution.
	float y = 256.0f*(x0Save + 3.0f)/6.0f;
	int iY0 = SIZE - 1 - (int)y;
	for (i = 1; i < SIZE; ++i)
	{
		int j = (maxIterations - 1)*i/(SIZE - 1);
		y = 256.0f*(x0Save*Mathf::Exp(-c*j*h) + 3.0f)/6.0f;
		int iY1 = SIZE - 1 - (int)y;
		Line2D(i - 1, iY0, i, iY1, DrawPixel);
		iY0 = iY1;
	}

	path = Environment::GetPathW("Data/stiff1_true.im");
	msImage->Save(path.c_str());

	// Set image to white.
	for (i = 0; i < msImage->GetQuantity(); ++i)
	{
		(*msImage)[i] = GetColor24(255, 255, 255);
	}

	// Draw the approximate solution.
	y = 256.0f*(approx[0] + 3.0f)/6.0f;
	iY0 = SIZE - 1 - (int)y;
	for (i = 1; i < SIZE; ++i)
	{
		int j = (maxIterations - 1)*i/(SIZE - 1);
		y = 256.0f*(approx[j] + 3.0f)/6.0f;
		int iY1 = SIZE - 1 - (int)y;
		Line2D(i - 1, iY0, i, iY1, DrawPixel);
		iY0 = iY1;
	}

	path = Environment::GetPathW("Data/stiff1_appr.im");
	msImage->Save(path.c_str());

	delete1(approx);
}
void OsmAnd::AtlasMapRendererDebugStage_OpenGL::addLine2D(const QVector<glm::vec2>& line, const uint32_t argbColor)
{
    assert(line.size() >= 2);
    _lines2D.push_back(qMove(Line2D(line, argbColor)));
}
Esempio n. 18
0
//----------------------------------------------------------------------------
void RayTrace::DrawWireFrame ()
{
    // Calculate orientation of cube corners relative to u and v.
    float udot0 =  mFrame[0][0] + mFrame[1][0] + mFrame[2][0];
    float udot1 =  mFrame[0][0] + mFrame[1][0] - mFrame[2][0];
    float udot2 = -mFrame[0][0] + mFrame[1][0] - mFrame[2][0];
    float udot3 = -mFrame[0][0] + mFrame[1][0] + mFrame[2][0];
    float vdot0 =  mFrame[0][1] + mFrame[1][1] + mFrame[2][1];
    float vdot1 =  mFrame[0][1] + mFrame[1][1] - mFrame[2][1];
    float vdot2 = -mFrame[0][1] + mFrame[1][1] - mFrame[2][1];
    float vdot3 = -mFrame[0][1] + mFrame[1][1] + mFrame[2][1];

    // Corner locations.
    int x[8],  y[8];

    // (-1, -1, -1)
    x[0] = (int)(mBoundM1*(1.0f - 0.5f*udot0)*0.5f);
    y[0] = (int)(mBoundM1*(1.0f - 0.5f*vdot0)*0.5f);

    // (1, -1, -1)
    x[1] = (int)(mBoundM1*(1.0f - 0.5f*udot3)*0.5f);
    y[1] = (int)(mBoundM1*(1.0f - 0.5f*vdot3)*0.5f);

    // (1, 1, -1)
    x[2] = (int)(mBoundM1*(1.0f + 0.5f*udot1)*0.5f);
    y[2] = (int)(mBoundM1*(1.0f + 0.5f*vdot1)*0.5f);

    // (-1, 1, -1)
    x[3] = (int)(mBoundM1*(1.0f + 0.5f*udot2)*0.5f);
    y[3] = (int)(mBoundM1*(1.0f + 0.5f*vdot2)*0.5f);

    // (-1, -1, 1)
    x[4] = (int)(mBoundM1*(1.0f - 0.5f*udot1)*0.5f);
    y[4] = (int)(mBoundM1*(1.0f - 0.5f*vdot1)*0.5f);

    // (1, -1, 1)
    x[5] = (int)(mBoundM1*(1.0f - 0.5f*udot2)*0.5f);
    y[5] = (int)(mBoundM1*(1.0f - 0.5f*vdot2)*0.5f);

    // (1, 1, 1)
    x[6] = (int)(mBoundM1*(1.0f + 0.5f*udot0)*0.5f);
    y[6] = (int)(mBoundM1*(1.0f + 0.5f*vdot0)*0.5f);

    // (-1, 1, 1)
    x[7] = (int)(mBoundM1*(1.0f + 0.5f*udot3)*0.5f);
    y[7] = (int)(mBoundM1*(1.0f + 0.5f*vdot3)*0.5f);

    // Draw back faces.
    if (mFrame[0][2] < 0.0f)
    {
        // face x = -1
        Line2D(false, x[0], y[0], x[3], y[3]);
        Line2D(false, x[3], y[3], x[7], y[7]);
        Line2D(false, x[7], y[7], x[4], y[4]);
        Line2D(false, x[4], y[4], x[0], y[0]);
    }
    else if (mFrame[0][2] > 0.0f)
    {
        // face x = +1
        Line2D(false, x[1], y[1], x[2], y[2]);
        Line2D(false, x[2], y[2], x[6], y[6]);
        Line2D(false, x[6], y[6], x[5], y[5]);
        Line2D(false, x[5], y[5], x[1], y[1]);
    }

    if (mFrame[1][2] < 0.0f)
    {
        // face y = -1
        Line2D(false, x[0], y[0], x[1], y[1]);
        Line2D(false, x[1], y[1], x[5], y[5]);
        Line2D(false, x[5], y[5], x[4], y[4]);
        Line2D(false, x[4], y[4], x[0], y[0]);
    }
    else if (mFrame[1][2] > 0.0f)
    {
        // face y = +1
        Line2D(false, x[2], y[2], x[3], y[3]);
        Line2D(false, x[3], y[3], x[7], y[7]);
        Line2D(false, x[7], y[7], x[6], y[6]);
        Line2D(false, x[6], y[6], x[2], y[2]);
    }

    if (mFrame[2][2] < 0.0f)
    {
        // face z = -1
        Line2D(false, x[0], y[0], x[1], y[1]);
        Line2D(false, x[1], y[1], x[2], y[2]);
        Line2D(false, x[2], y[2], x[3], y[3]);
        Line2D(false, x[3], y[3], x[0], y[0]);
    }
    else if (mFrame[2][2] > 0.0f)
    {
        // face z = +1
        Line2D(false, x[4], y[4], x[5], y[5]);
        Line2D(false, x[5], y[5], x[6], y[6]);
        Line2D(false, x[6], y[6], x[7], y[7]);
        Line2D(false, x[7], y[7], x[4], y[4]);
    }

    // Fraw front faces.
    if (mFrame[0][2] < 0.0f)
    {
        // face x = +1
        Line2D(true, x[1], y[1], x[2], y[2]);
        Line2D(true, x[2], y[2], x[6], y[6]);
        Line2D(true, x[6], y[6], x[5], y[5]);
        Line2D(true, x[5], y[5], x[1], y[1]);
    }
    else if (mFrame[0][2] > 0.0f)
    {
        // face x = -1
        Line2D(true, x[0], y[0], x[3], y[3]);
        Line2D(true, x[3], y[3], x[7], y[7]);
        Line2D(true, x[7], y[7], x[4], y[4]);
        Line2D(true, x[4], y[4], x[0], y[0]);
    }

    if (mFrame[1][2] < 0.0f)
    {
        // face y = +1
        Line2D(true, x[2], y[2], x[3], y[3]);
        Line2D(true, x[3], y[3], x[7], y[7]);
        Line2D(true, x[7], y[7], x[6], y[6]);
        Line2D(true, x[6], y[6], x[2], y[2]);
    }
    else if (mFrame[1][2] > 0.0f)
    {
        // face y = -1
        Line2D(true, x[0], y[0], x[1], y[1]);
        Line2D(true, x[1], y[1], x[5], y[5]);
        Line2D(true, x[5], y[5], x[4], y[4]);
        Line2D(true, x[4], y[4], x[0], y[0]);
    }

    if (mFrame[2][2] < 0.0f)
    {
        // face z = +1
        Line2D(true, x[4], y[4], x[5], y[5]);
        Line2D(true, x[5], y[5], x[6], y[6]);
        Line2D(true, x[6], y[6], x[7], y[7]);
        Line2D(true, x[7], y[7], x[4], y[4]);
    }
    else if (mFrame[2][2] > 0.0f)
    {
        // face z = -1
        Line2D(true, x[0], y[0], x[1], y[1]);
        Line2D(true, x[1], y[1], x[2], y[2]);
        Line2D(true, x[2], y[2], x[3], y[3]);
        Line2D(true, x[3], y[3], x[0], y[0]);
    }
}
Esempio n. 19
0
Line2D Line2D::OrthogonalLine(void) const {
  return Line2D(start_, start_ + normal_);
}
Esempio n. 20
0
float LineAngleMetric2D::Calculate(const D3DXVECTOR2 &point) const {
  return line_.Angle(Line2D(start_, point)) * (line_.Distance(point) < 0 ? -1 : 1);
}
Esempio n. 21
0
//----------------------------------------------------------------------------
void RayTrace::DrawWireFrame ()
{
    // calculate orientation of cube corners relative to u and v
    float fUDot0 =  m_aafFrame[0][0] + m_aafFrame[1][0] + m_aafFrame[2][0];
    float fUDot1 =  m_aafFrame[0][0] + m_aafFrame[1][0] - m_aafFrame[2][0];
    float fUDot2 = -m_aafFrame[0][0] + m_aafFrame[1][0] - m_aafFrame[2][0];
    float fUDot3 = -m_aafFrame[0][0] + m_aafFrame[1][0] + m_aafFrame[2][0];
    float fVDot0 =  m_aafFrame[0][1] + m_aafFrame[1][1] + m_aafFrame[2][1];
    float fVDot1 =  m_aafFrame[0][1] + m_aafFrame[1][1] - m_aafFrame[2][1];
    float fVDot2 = -m_aafFrame[0][1] + m_aafFrame[1][1] - m_aafFrame[2][1];
    float fVDot3 = -m_aafFrame[0][1] + m_aafFrame[1][1] + m_aafFrame[2][1];

    // corner locations
    int aiX[8], aiY[8];

    // (-1,-1,-1)
    aiX[0] = (int)(m_iBoundM1*(1.0f-0.5f*fUDot0)*0.5f);
    aiY[0] = (int)(m_iBoundM1*(1.0f-0.5f*fVDot0)*0.5f);

    // (1,-1,-1)
    aiX[1] = (int)(m_iBoundM1*(1.0f-0.5f*fUDot3)*0.5f);
    aiY[1] = (int)(m_iBoundM1*(1.0f-0.5f*fVDot3)*0.5f);

    // (1,1,-1)
    aiX[2] = (int)(m_iBoundM1*(1.0f+0.5f*fUDot1)*0.5f);
    aiY[2] = (int)(m_iBoundM1*(1.0f+0.5f*fVDot1)*0.5f);

    // (-1,1,-1)
    aiX[3] = (int)(m_iBoundM1*(1.0f+0.5f*fUDot2)*0.5f);
    aiY[3] = (int)(m_iBoundM1*(1.0f+0.5f*fVDot2)*0.5f);

    // (-1,-1,1)
    aiX[4] = (int)(m_iBoundM1*(1.0f-0.5f*fUDot1)*0.5f);
    aiY[4] = (int)(m_iBoundM1*(1.0f-0.5f*fVDot1)*0.5f);

    // (1,-1,1)
    aiX[5] = (int)(m_iBoundM1*(1.0f-0.5f*fUDot2)*0.5f);
    aiY[5] = (int)(m_iBoundM1*(1.0f-0.5f*fVDot2)*0.5f);

    // (1,1,1)
    aiX[6] = (int)(m_iBoundM1*(1.0f+0.5f*fUDot0)*0.5f);
    aiY[6] = (int)(m_iBoundM1*(1.0f+0.5f*fVDot0)*0.5f);

    // (-1,1,1)
    aiX[7] = (int)(m_iBoundM1*(1.0f+0.5f*fUDot3)*0.5f);
    aiY[7] = (int)(m_iBoundM1*(1.0f+0.5f*fVDot3)*0.5f);

    // draw back faces
    if ( m_aafFrame[0][2] < 0.0f )
    {
        // face x = -1
        Line2D(false,aiX[0],aiY[0],aiX[3],aiY[3]);
        Line2D(false,aiX[3],aiY[3],aiX[7],aiY[7]);
        Line2D(false,aiX[7],aiY[7],aiX[4],aiY[4]);
        Line2D(false,aiX[4],aiY[4],aiX[0],aiY[0]);
    }
    else if ( m_aafFrame[0][2] > 0.0f )
    {
        // face x = +1
        Line2D(false,aiX[1],aiY[1],aiX[2],aiY[2]);
        Line2D(false,aiX[2],aiY[2],aiX[6],aiY[6]);
        Line2D(false,aiX[6],aiY[6],aiX[5],aiY[5]);
        Line2D(false,aiX[5],aiY[5],aiX[1],aiY[1]);
    }

    if ( m_aafFrame[1][2] < 0.0f )
    {
        // face y = -1
        Line2D(false,aiX[0],aiY[0],aiX[1],aiY[1]);
        Line2D(false,aiX[1],aiY[1],aiX[5],aiY[5]);
        Line2D(false,aiX[5],aiY[5],aiX[4],aiY[4]);
        Line2D(false,aiX[4],aiY[4],aiX[0],aiY[0]);
    }
    else if ( m_aafFrame[1][2] > 0.0f )
    {
        // face y = +1
        Line2D(false,aiX[2],aiY[2],aiX[3],aiY[3]);
        Line2D(false,aiX[3],aiY[3],aiX[7],aiY[7]);
        Line2D(false,aiX[7],aiY[7],aiX[6],aiY[6]);
        Line2D(false,aiX[6],aiY[6],aiX[2],aiY[2]);
    }

    if ( m_aafFrame[2][2] < 0.0f )
    {
        // face z = -1
        Line2D(false,aiX[0],aiY[0],aiX[1],aiY[1]);
        Line2D(false,aiX[1],aiY[1],aiX[2],aiY[2]);
        Line2D(false,aiX[2],aiY[2],aiX[3],aiY[3]);
        Line2D(false,aiX[3],aiY[3],aiX[0],aiY[0]);
    }
    else if ( m_aafFrame[2][2] > 0.0f )
    {
        // face z = +1
        Line2D(false,aiX[4],aiY[4],aiX[5],aiY[5]);
        Line2D(false,aiX[5],aiY[5],aiX[6],aiY[6]);
        Line2D(false,aiX[6],aiY[6],aiX[7],aiY[7]);
        Line2D(false,aiX[7],aiY[7],aiX[4],aiY[4]);
    }

    // draw front faces
    if ( m_aafFrame[0][2] < 0.0f )
    {
        // face x = +1
        Line2D(true,aiX[1],aiY[1],aiX[2],aiY[2]);
        Line2D(true,aiX[2],aiY[2],aiX[6],aiY[6]);
        Line2D(true,aiX[6],aiY[6],aiX[5],aiY[5]);
        Line2D(true,aiX[5],aiY[5],aiX[1],aiY[1]);
    }
    else if ( m_aafFrame[0][2] > 0.0f )
    {
        // face x = -1
        Line2D(true,aiX[0],aiY[0],aiX[3],aiY[3]);
        Line2D(true,aiX[3],aiY[3],aiX[7],aiY[7]);
        Line2D(true,aiX[7],aiY[7],aiX[4],aiY[4]);
        Line2D(true,aiX[4],aiY[4],aiX[0],aiY[0]);
    }

    if ( m_aafFrame[1][2] < 0.0f )
    {
        // face y = +1
        Line2D(true,aiX[2],aiY[2],aiX[3],aiY[3]);
        Line2D(true,aiX[3],aiY[3],aiX[7],aiY[7]);
        Line2D(true,aiX[7],aiY[7],aiX[6],aiY[6]);
        Line2D(true,aiX[6],aiY[6],aiX[2],aiY[2]);
    }
    else if ( m_aafFrame[1][2] > 0.0f )
    {
        // face y = -1
        Line2D(true,aiX[0],aiY[0],aiX[1],aiY[1]);
        Line2D(true,aiX[1],aiY[1],aiX[5],aiY[5]);
        Line2D(true,aiX[5],aiY[5],aiX[4],aiY[4]);
        Line2D(true,aiX[4],aiY[4],aiX[0],aiY[0]);
    }

    if ( m_aafFrame[2][2] < 0.0f )
    {
        // face z = +1
        Line2D(true,aiX[4],aiY[4],aiX[5],aiY[5]);
        Line2D(true,aiX[5],aiY[5],aiX[6],aiY[6]);
        Line2D(true,aiX[6],aiY[6],aiX[7],aiY[7]);
        Line2D(true,aiX[7],aiY[7],aiX[4],aiY[4]);
    }
    else if ( m_aafFrame[2][2] > 0.0f )
    {
        // face z = -1
        Line2D(true,aiX[0],aiY[0],aiX[1],aiY[1]);
        Line2D(true,aiX[1],aiY[1],aiX[2],aiY[2]);
        Line2D(true,aiX[2],aiY[2],aiX[3],aiY[3]);
        Line2D(true,aiX[3],aiY[3],aiX[0],aiY[0]);
    }
}
Esempio n. 22
0
Line2D Line2D::ParallelThrough(const D3DXVECTOR2 &point) const {
  return Line2D(point, point + direction_);
}
Esempio n. 23
0
Line2D
Line2D::getPerpendicular (const Point2D& p) const
{
  return Line2D (-m_b, m_a, m_b * p.x - m_a * p.y);
}