Пример #1
0
void vtRoute::_StringWires(long ll, vtHeightField3d *pHeightField)
{
	// pick pole numbers i and i-1 and string a wire between them
	long numiterations = NUM_WIRE_SEGMENTS;

	FPoint3 fp0, fp1;

	vtUtilNode *n0 = m_Nodes[ll-1];
	vtUtilNode *n1 = m_Nodes[ll];

	vtUtilStruct *st0 = n0->m_struct;
	vtUtilStruct *st1 = n1->m_struct;

	// safety check
	if (!st0 || !st1)
		return;

	DPoint2 p0 = n0->m_Point;
	DPoint2 p1 = n1->m_Point;

	pHeightField->ConvertEarthToSurfacePoint(p0, fp0);
	pHeightField->ConvertEarthToSurfacePoint(p1, fp1);

	FMatrix4 rot;
	rot.Identity();
	FPoint3 axisY(0, 1, 0);
	FPoint3 offset, wire0, wire1;

	vtMesh *pWireMesh;
	for (int j = 0; j < st1->m_iNumWires; j++)
	{
		pWireMesh = new vtMesh(osg::PrimitiveSet::LINE_STRIP, 0, numiterations+1);

		offset = st0->m_fpWireAtt1[j];
		rot.AxisAngle(axisY, n0->dRadAzimuth);
		rot.Transform(offset, wire0);
		FPoint3 wire_start = fp0 + wire0;

		pWireMesh->AddVertex(wire_start);

		offset = st1->m_fpWireAtt2[j];
		rot.AxisAngle(axisY, n1->dRadAzimuth);
		rot.Transform(offset, wire1);
		FPoint3 wire_end = fp1 + wire1;

		_DrawCat(wire_start, wire_end, vtGetTS()->m_fCatenaryFactor, numiterations, pWireMesh);

		pWireMesh->AddVertex(wire_end);

		pWireMesh->AddStrip2(numiterations+1, 0);
		m_pWireGeom->AddMesh(pWireMesh, m_mi_wire);
	}
}
Пример #2
0
void GlobePicker::Eval()
{
    FPoint3 pos, dir;

    vtGetScene()->CameraRay(m_pos, pos, dir);

    // test whether we hit the globe
    FSphere sphere(FPoint3(0.0f, 0.0f, 0.0f), (float)m_fRadius);
    FPoint3 akPoint[2];
    int riQuantity;

    m_bOnTerrain = RaySphereIntersection(pos, dir, sphere, riQuantity, akPoint);
    if (m_bOnTerrain)
    {
        // save result
        m_GroundPoint = akPoint[0];

        // apply global position to target (which is not a child of the globe)
        vtTransform *pTarget = (vtTransform *) GetTarget();
        if (pTarget)
        {
            pTarget->Identity();
            pTarget->SetTrans(m_GroundPoint);
            pTarget->PointTowards(m_GroundPoint * 2.0f);
            pTarget->Scale(m_fTargetScale);
        }

        if (m_pGlobe)
        {
            // rotate to find position relative to globe's rotation
            vtTransform *xform = m_pGlobe->GetTop();
            FMatrix4 rot;
            xform->GetTransform1(rot);
            FMatrix4 inverse;
            inverse.Invert(rot);
            FPoint3 newpoint;

            // work around SML bug: matrices flagged as identity but
            // will still transform by their components
            if (! inverse.IsIdentity())
            {
                inverse.Transform(m_GroundPoint, newpoint);
                m_GroundPoint = newpoint;
            }
        }

        // Find corresponding geographic coordinates
        xyz_to_geo(m_fRadius, m_GroundPoint, m_EarthPos);
    }
}