예제 #1
0
CPLErr TerragenDataset::SetProjection( const char * pszNewProjection )
{
    // Terragen files aren't really georeferenced, but 
    // we should get the projection's linear units so 
    // that we can scale elevations correctly.

    //m_dSCAL = 30.0; // default

    OGRSpatialReference oSRS( pszNewProjection );

/* -------------------------------------------------------------------- */
/*      Linear units.                                                   */
/* -------------------------------------------------------------------- */
    m_bIsGeo = (oSRS.IsGeographic() != FALSE);
    if(m_bIsGeo)
    {
        // The caller is using degrees. We need to convert 
        // to meters, otherwise we can't derive a SCAL
        // value to scale elevations with.
        m_bIsGeo = true;
    }
    else
    {
        double dfLinear = oSRS.GetLinearUnits();

        if( approx_equal(dfLinear, 0.3048))
            m_dMetersPerGroundUnit = 0.3048;
        else if( approx_equal(dfLinear, atof(SRS_UL_US_FOOT_CONV)) )
            m_dMetersPerGroundUnit = atof(SRS_UL_US_FOOT_CONV);
        else
            m_dMetersPerGroundUnit = 1.0;
    }

    return CE_None;
}
예제 #2
0
파일: game.cpp 프로젝트: ref2401/SPARKi
void game_system::update()
{
	camera_.prev_position = camera_.position;
	camera_.prev_target = camera_.target;
	camera_.prev_up = camera_.prev_up;

	if (!approx_equal(camera_.roll_angles, float2::zero)) {
		const float dist = len(camera_.target - camera_.position);
		
		float3 fwd = normalize(camera_.target - camera_.position);
		float3 ox = cross(fwd, camera_.up);
		ox.y = 0.0f; // ox is always parallel the world's OX.
		ox = normalize(ox);

		if (!approx_equal(0.0f, camera_.roll_angles.y)) {
			const quat q = from_axis_angle_rotation(float3::unit_y, camera_.roll_angles.y);
			camera_.position = dist * normalize(rotate(q, camera_.position));

			ox = rotate(q, ox);
			ox.y = 0.0f;
			ox = normalize(ox);
		}

		if (!approx_equal(0.0f, camera_.roll_angles.x)) {
			const quat q = from_axis_angle_rotation(ox, camera_.roll_angles.x);
			camera_.position = dist * normalize(rotate(q, camera_.position));
		}

		fwd = normalize(camera_.target - camera_.position);
		camera_.up = normalize(cross(ox, fwd));
	}

	camera_.roll_angles = float2::zero;
}
예제 #3
0
파일: game.cpp 프로젝트: ref2401/SPARKi
void game_system::on_mouse_move()
{
	const float2 curr_pos(float(input_state_.mouse_position.x), float(input_state_.mouse_position.y));
	const float2 diff = curr_pos - camera_.mouse_position_prev;
	camera_.mouse_position_prev = curr_pos;

	if (!is_mouse_middle_down(input_state_) || approx_equal(diff, float2::zero)) return;

	// mouse offset by x means rotation around OY (yaw)
	const bool x_offset_sufficient = !approx_equal(diff.x, 0.0f, 0.01f);
	if (x_offset_sufficient)
		camera_.roll_angles.y += (diff.x > 0.0f) ? -pi_128 : pi_128;

	// mouse offset by x means rotation around OX (pitch)
	const bool y_offset_sufficient = !approx_equal(diff.y, 0.0f, 0.01f);
	if (y_offset_sufficient)
		camera_.roll_angles.x += (diff.y > 0.0f) ? pi_128 : -pi_128;
}
예제 #4
0
void test_float(char * label, float actual, float expected, float tolerance)
{
    if (approx_equal(expected, actual, tolerance))
    {
        printf("Pass: %s: %f ~= %f\n", label, expected, actual);
        tests_passed++;
    }
    else
    {
        printf("Fail: %s: expected %f, got %f\n", label, expected, actual);
    }
    tests_run++;
}
예제 #5
0
void satisfied_guide_cns(SPDesktop const &desktop,
                         std::vector<Inkscape::SnapCandidatePoint> const &snappoints,
                         std::vector<SPGuideConstraint> &cns)
{
    SPNamedView const &nv = *sp_desktop_namedview(&desktop);
    for (GSList const *l = nv.guides; l != NULL; l = l->next) {
        SPGuide &g = *SP_GUIDE(l->data);
        for (unsigned int i = 0; i < snappoints.size(); ++i) {
            if (approx_equal( g.getDistanceFrom(snappoints[i].getPoint()), 0) ) {
                cns.push_back(SPGuideConstraint(&g, i));
            }
        }
    }
}
예제 #6
0
const measurement_unit* LevellerDataset::get_uom(double dM) const
{
    for(size_t i = kFirstLinearMeasureIdx; i < array_size(kUnits); i++)
    {
		if(dM >= 1.0e-4)
		{
			if(approx_equal(dM, kUnits[i].dScale))
				return &kUnits[i];
		}
		else if(dM == kUnits[i].dScale)
			return &kUnits[i];
    }
    CPLError( CE_Failure, CPLE_AppDefined, 
              "Unknown measurement conversion factor: %f", dM );
    return NULL;
}
예제 #7
0
파일: value.cpp 프로젝트: Ehnonymoose/MSE
/// compare script values for equallity
bool equal(const ScriptValueP& a, const ScriptValueP& b) {
	if (a == b) return true;
	ScriptType at = a->type(), bt = b->type();
	if (at == bt && at == SCRIPT_INT) {
		return a->toInt() == b->toInt();
	} else if (at == bt && at == SCRIPT_BOOL) {
		return a->toBool() == b->toBool();
	} else if ((at == SCRIPT_INT || at == SCRIPT_DOUBLE) &&
	           (bt == SCRIPT_INT || bt == SCRIPT_DOUBLE)) {
		return approx_equal( a->toDouble(), b->toDouble());
	} else if (at == SCRIPT_COLLECTION && bt == SCRIPT_COLLECTION) {
		// compare each element
		if (a->itemCount() != b->itemCount()) return false;
		ScriptValueP a_it = a->makeIterator();
		ScriptValueP b_it = b->makeIterator();
		while (true) {
			ScriptValueP a_v = a_it->next();
			ScriptValueP b_v = b_it->next();
			if (!a_v || !b_v) return a_v == b_v;
			if (!equal(a_v, b_v)) return false;
		}
	} else {
		String      as,  bs;
		const void* ap, *bp;
		CompareWhat aw = a->compareAs(as, ap);
		CompareWhat bw = b->compareAs(bs, bp);
		// compare pointers or strings
		if (aw == COMPARE_AS_STRING || bw == COMPARE_AS_STRING) {
			return as == bs;
		} else if (aw == COMPARE_AS_POINTER || bw == COMPARE_AS_POINTER) {
			return ap == bp;
		} else {
			return false;
		}
	}
}