void touchmind::view::linkedge::impl::ArrowLinkEdgeView::CreateDeviceDependentResources(
    touchmind::Context *pContext, ID2D1RenderTarget *pRenderTarget) {
  if (GetLinkModel().expired()) {
    return;
  }
  auto link = GetLinkModel().lock();
  if (!link->IsValid()) {
    return;
  }
  auto linkEdge = link->GetEdge(GetEdgeId());
  auto node = link->GetNode(GetEdgeId());
  if (linkEdge->IsRepaintRequired(GetRepaintCounter()) || m_pArrowGeometry == nullptr || m_pBrush == nullptr) {
    ID2D1Factory *pD2DFactory = pContext->GetD2DFactory();

    D2D1_POINT_2F point0 = link->GetEdgePoint(GetEdgeId());
    std::vector<D2D1_POINT_2F> points;
    view::GeometryBuilder::CalculateArrowPoints(point0, linkEdge->GetMarkerSize() + link->GetLineWidth(),
                                                linkEdge->GetMarkerSize() + link->GetLineWidth(), linkEdge->GetAngle(),
                                                node->GetAncestorPosition(), points);
    m_pArrowGeometry = nullptr;
    CHK_RES(m_pArrowGeometry,
            view::GeometryBuilder::CreatePathGeometryFromPoints(pD2DFactory, points, &m_pArrowGeometry));

    m_pBrush = nullptr;
    CHK_RES(m_pBrush, pRenderTarget->CreateSolidColorBrush(link->GetLineColor(), D2D1::BrushProperties(), &m_pBrush));
    SetRepaintCounter(linkEdge);
  }
}
Example #2
0
/*
================
sdVehiclePathGrid::SetupPathPoints
================
*/
void sdVehiclePathGrid::SetupPathPoints( const idVec3& position, idStaticList< idVec3, MAX_SCRIPTENTITY_PATHPOINTS >& pathPoints, int seed, float cornerX, float cornerY ) const {
	int x, y;
	int xmin, ymin;
	GetCoordsForPoint( x, y, xmin, ymin, position );

	int nx, ny;
	GetEdgePoint( x, y, nx, ny, seed, cornerX, cornerY );

	idVec3 edgePos;
	GetPointInternal( nx, ny, edgePos );

	AdjustTargetForStart( edgePos, position, x, y, xmin, ymin );

	bool ymainaxis = abs( ny - y ) > abs( nx - x );

	int loopPos;
	int loopDir;
	int loopStart;
	int loopEnd;
	float loopLen;
	
	if ( ymainaxis ) {
		loopPos		= ny;
		loopStart	= ny;
		loopDir		= ny > y ? -1 : 1;
		loopLen		= ny - y;
		loopEnd		= y;
	} else {
		loopPos		= nx;
		loopStart	= nx;
		loopDir		= nx > x ? -1 : 1;
		loopLen		= nx - x;
		loopEnd		= x;
	}

	idVec3 endPoint;
	GetPoint( x, y, endPoint );

	idVec3 lastPos;
	GetPoint( nx, ny, lastPos );

	idVec3 inVector = ( endPoint - lastPos );
	inVector[ 2 ] = 0.f;
	inVector.Normalize();
	float scale = 64.f; // inVector.Normalize();

	pathPoints.Clear();

	while ( loopPos != loopEnd ) {
		int currentPos[ 2 ];

		loopPos += loopDir;
		float frac = ( loopPos - loopStart ) / loopLen;

		if ( ymainaxis ) {
			currentPos[ 0 ] = nx + ( ( nx - x ) * frac );
			currentPos[ 1 ] = loopPos;
		} else {
			currentPos[ 0 ] = loopPos;
			currentPos[ 1 ] = ny + ( ( ny - y ) * frac );
		}

		idVec3 newPos;
		GetPointInternal( currentPos[ 0 ], currentPos[ 1 ], newPos );

		//AddSection( lastPos, inVector, newPos, endPoint, loopPos != loopEnd, inSpline );
		pathPoints.Append( newPos );
		lastPos = newPos;
	}

	// add the final point
	idVec3 hoverPos = position;
	hoverPos[ 2 ] = lastPos[ 2 ];
	pathPoints.Append( hoverPos );
}
Example #3
0
/*
================
sdVehiclePathGrid::SetupPath
================
*/
void sdVehiclePathGrid::SetupPath( const idVec3& position, idList< splineSection_t >& inSpline, idList< splineSection_t >& outSpline, int seed ) const {
	int x, y;
	int xmin, ymin;
	GetCoordsForPoint( x, y, xmin, ymin, position );

	int nx, ny;
	GetEdgePoint( x, y, nx, ny, seed, 0, 0 );

	idVec3 edgePos;
	GetPointInternal( nx, ny, edgePos );

	AdjustTargetForStart( edgePos, position, x, y, xmin, ymin );

	bool ymainaxis = abs( ny - y ) > abs( nx - x );

	int loopPos;
	int loopDir;
	int loopStart;
	int loopEnd;
	float loopLen;
	
	if ( ymainaxis ) {
		loopPos		= ny;
		loopStart	= ny;
		loopDir		= ny > y ? -1 : 1;
		loopLen		= ny - y;
		loopEnd		= y;
	} else {
		loopPos		= nx;
		loopStart	= nx;
		loopDir		= nx > x ? -1 : 1;
		loopLen		= nx - x;
		loopEnd		= x;
	}

	idVec3 endPoint;
	GetPoint( x, y, endPoint );

	idVec3 lastPos;
	GetPoint( nx, ny, lastPos );

	idVec3 inVector = ( endPoint - lastPos );
	inVector[ 2 ] = 0.f;
	inVector.Normalize();
	float scale = 64.f; // inVector.Normalize();

	inSpline.Clear();

	while ( loopPos != loopEnd ) {
		int currentPos[ 2 ];

		loopPos += loopDir;
		float frac = ( loopPos - loopStart ) / loopLen;

		if ( ymainaxis ) {
			currentPos[ 0 ] = nx + ( ( nx - x ) * frac );
			currentPos[ 1 ] = loopPos;
		} else {
			currentPos[ 0 ] = loopPos;
			currentPos[ 1 ] = ny + ( ( ny - y ) * frac );
		}

		idVec3 newPos;
		GetPointInternal( currentPos[ 0 ], currentPos[ 1 ], newPos );

		AddSection( lastPos, inVector, newPos, endPoint, loopPos != loopEnd, inSpline );
	}

	{
		idVec3 hoverPos = position;
		hoverPos[ 2 ] = lastPos[ 2 ];

		idVec3 temp = ( hoverPos - lastPos );
		scale = temp.Normalize() * 0.125f;

		idVec3 newInVector( 0.f, 0.f, -1.f );
		newInVector += temp * 0.2f;
		newInVector.Normalize();

		splineSection_t& section = inSpline.Alloc();

		section.AddValue( 0.f, lastPos );
		section.AddValue( 1.f / 3.f, lastPos + ( inVector * ( scale ) ) );
		section.AddValue( 2.f / 3.f, hoverPos - ( newInVector * ( scale ) ) );
		section.AddValue( 1.f, hoverPos );

		lastPos		= hoverPos;
		inVector	= newInVector;
	}

	{
		GetCoordsForPoint( nx, ny, xmin, ymin, lastPos );

		idVec3 startPoint;
		GetPoint( nx, ny, startPoint );

		idVec3 temp = startPoint - lastPos;
		scale = temp.Normalize() * 0.125f;

		inVector[ 2 ] = 0.f;
		inVector.Normalize();
		inVector *= 0.2f;
		inVector += idVec3( 0.f, 0.f, 1.f );
		inVector.Normalize();

		GetEdgePoint( nx, ny, x, y, seed, 0, 0 );

		GetPoint( x, y, endPoint );
	}

	ymainaxis = abs( ny - y ) > abs( nx - x );

	if ( ymainaxis ) {
		loopPos		= ny;
		loopStart	= ny;
		loopDir		= ny > y ? -1 : 1;
		loopLen		= ny - y;
		loopEnd		= y;
	} else {
		loopPos		= nx;
		loopStart	= nx;
		loopDir		= nx > x ? -1 : 1;
		loopLen		= nx - x;
		loopEnd		= x;
	}

	outSpline.Clear();

	while ( loopPos != loopEnd ) {
		int currentPos[ 2 ];

		loopPos += loopDir;
		float frac = ( loopPos - loopStart ) / loopLen;

		if ( ymainaxis ) {
			currentPos[ 0 ] = nx + ( ( nx - x ) * frac );
			currentPos[ 1 ] = loopPos;
		} else {
			currentPos[ 0 ] = loopPos;
			currentPos[ 1 ] = ny + ( ( ny - y ) * frac );
		}

		idVec3 newPos;
		GetPointInternal( currentPos[ 0 ], currentPos[ 1 ], newPos );

		AddSection( lastPos, inVector, newPos, endPoint, loopPos != loopEnd, outSpline );
	}
}