// a first attempt at interpolation for the SampleMatrix. should be viewed as temporary.
// needs to be fleshed out with different options...
TTErr TTSampleMatrix::peeki(const TTFloat64 index, const TTColumnID channel, TTSampleValue& value)
{
	// variables needed
    TTColumnID p_channel = channel;
	TTFloat64 indexIntegralPart = 0;
	TTFloat64 indexFractionalPart = modf(index, &indexIntegralPart); // before makeInBounds to get the right value!
	TTRowID indexThisInteger = TTRowID(indexIntegralPart);
	
	TTBoolean weAreNotInBounds = makeInBounds(indexThisInteger, p_channel);  // out of range values are wrapped
	
	if (weAreNotInBounds)
	{
		// no reason to interpolate, just use the first or last value
		get2d(indexThisInteger, p_channel, value);
		return kTTErrOutOfBounds; // and report an error (is that what we want?)
	} else {
		TTRowID indexNextInteger = indexThisInteger + 1;
		makeRowIDInBounds(indexNextInteger); //does not allow interpolation between first and last sample
			//  (is that what we want? if not, insert outOfBoundsWrap)

		TTSampleValue valueThisInteger, valueNextInteger;
	
		get2d(indexThisInteger, p_channel, valueThisInteger);
		get2d(indexNextInteger, p_channel, valueNextInteger);
	
		// simple linear interpolation adapted from TTDelay
		value = TTInterpolateLinear(valueThisInteger, valueNextInteger, indexFractionalPart);
	
		return kTTErrNone;
	}
}
Example #2
0
double FractalNoise::getTriplanar(double detail, const Vector3 &location, const Vector3 &normal) const {
    double noiseXY = get2d(detail, location.x, location.y);
    double noiseXZ = get2d(detail, location.x, location.z);
    double noiseYZ = get2d(detail, location.y, location.z);

    double mXY = fabs(normal.z);
    double mXZ = fabs(normal.y);
    double mYZ = fabs(normal.x);
    double total = 1.0 / (mXY + mXZ + mYZ);
    mXY *= total;
    mXZ *= total;
    mYZ *= total;

    return noiseXY * mXY + noiseXZ * mXZ + noiseYZ * mYZ;
}
Example #3
0
// a first attempt at interpolation for the SampleMatrix. should be viewed as temporary.
// needs to be fleshed out with different options...
TTErr TTSampleMatrix::peeki(const TTFloat64 index, const TTUInt16 channel, TTSampleValue& value)
{
	
	// variables needed
	TTUInt64 indexThisInteger = TTUInt64(index);
	TTUInt64 indexNextInteger = indexThisInteger + 1;
	TTFloat64 indexFractionalPart = index - indexThisInteger;
	
	TTSampleValue valueThisInteger, valueNextInteger;
	
	// TODO: perhaps we should range check the input here first...
	get2d(indexThisInteger, channel, valueThisInteger);
	get2d(indexNextInteger, channel, valueNextInteger);
	
	// simple linear interpolation adapted from TTDelay
	value = (valueNextInteger * (1.0 - indexFractionalPart)) + (valueThisInteger * indexFractionalPart);
	
	return kTTErrNone;
	
}
bool VegetationPresenceDefinition::collectInstances(vector<VegetationInstance> *result,
                                                    const VegetationModelDefinition &model, double xmin, double zmin,
                                                    double xmax, double zmax, bool outcomers) const {
    if (outcomers) {
        // Expand the area to include outcoming instances
        double max_radius = getMaxHeight();
        xmin -= max_radius;
        zmin -= max_radius;
        xmax += max_radius;
        zmax += max_radius;
    }

    int added = 0;

    auto generator = noise->getGenerator();
    double interval_value = interval->getValue();

    double xstart = xmin - fmod(xmin, interval_value);
    double zstart = zmin - fmod(zmin, interval_value);
    for (double x = xstart; x < xmax; x += interval_value) {
        for (double z = zstart; z < zmax; z += interval_value) {
            double detail = interval_value * 0.1;
            double noise_presence = generator->get2d(detail, x * 0.1, z * 0.1);
            if (noise_presence > 0.0) {
                double size =
                    0.1 + 0.2 * fabs(generator->get2d(detail, z * 10.0, x * 10.0)) * (noise_presence * 0.5 + 0.5);
                double angle = 3.0 * generator->get2d(detail, -x * 20.0, z * 20.0); // TODO balanced distribution
                double xo = x + fabs(generator->get2d(detail, x * 12.0, -z * 12.0));
                double zo = z + fabs(generator->get2d(detail, -x * 27.0, -z * 27.0));
                if (xo >= xmin and xo < xmax and zo >= zmin and zo < zmax) {
                    double y = getScenery()->getTerrain()->getInterpolatedHeight(xo, zo, true, true);
                    result->push_back(VegetationInstance(model, Vector3(xo, y, zo), size, angle));
                    added++;
                }
            }
        }
    }

    return added > 0;
}
TTErr TTSampleMatrix::peek(const TTRowID index, const TTColumnID channel, TTSampleValue& value)
{
	TTRowID p_index = index;
	TTColumnID p_channel = channel;
	
	TTBoolean weAreNotInBounds = makeInBounds(p_index, p_channel); // out of range values are wrapped
	get2d(p_index, p_channel, value);
	
	if (weAreNotInBounds)
	{
		return kTTErrOutOfBounds;
	} else {
		return kTTErrNone;
	}
}
Example #6
0
TTErr TTSampleMatrix::peek(const TTUInt64 index, const TTUInt16 channel, TTSampleValue& value)
{
	// TODO: perhaps we should range check the input here first...
	get2d(index, channel, value);
	return kTTErrNone;
}