Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
107 lines (97 sloc) 3.22 KB
package nape.phys;
$(import);
!!/**
!! * FluidProperties providing shared parameters for fluid interaction.
!! */
@:final class FluidProperties {
FeatureMix(FluidProperties,fluidProperties)
!!/**
!! * Construct a new FluidProperties objects.
!! *
!! * @param density The density of the fluid in g/px/px. (default 1)
!! * @param viscosity The viscosity of the fluid for drag computations in kg/px/s
!! * (default 1)
!! * @return The constructed FluidProperties object.
!! */
public function new(density:Float=1,viscosity:Float=1) {
Get(PR(FluidProperties), pr(inner));
pr(inner).outer = this;
this.density = density;
this.viscosity = viscosity;
}
!!/**
!! * Produce a copy of this FluidProperties object.
!! * <br/><br/>
!! * The copied object will be identical in all properties with the the
!! * copied userData being assigned the same fields as 'this' Shape with the
!! * same values copied over by reference for object types.
!! *
!! * @return The copied FluidProperties.
!! */
keep public function copy() {
var ret = new FluidProperties(density,viscosity);
if (pr(inner).userData != null)
ret.pr(inner).userData = Reflect.copy(pr(inner).userData);
ret.gravity = this.gravity;
return ret;
}
$(mixin prop(n)
property(n,Float, {
return pr(inner).n * ($str(n)=="density" ? 1000 : 1);
}, {
if(n!=this.n) {
DEBUG(
if(isNaN(n)) throw "Error: FluidProperties::"+$str(n)+" cannot be NaN";
if($str(n)!="density" && n<0) throw "Error: FluidProperties::"+$str(n)+" ("+n+") must be >= 0";
)
pr(inner).n = n / ($str(n)=="density" ? 1000 : 1);
pr(inner).invalidate();
}
})
);
!!/**
!! * Density of fluid.
!! * <br/><br/>
!! * This value, like Material density is of g/pixel/pixel.
!! * @default 1
!! */
prop(density)
!!/**
!! * Viscosity of fluid.
!! * <br/><br/>
!! * This value is used in drag comutations, the higher the viscosity the
!! * more quickly objects will come to rest in the fluid.
!! * @default 1
!! */
prop(viscosity)
!!/**
!! * Local gravity for buoyancy computations.
!! * <br/><br/>
!! * When this value is not null, it will be used in place of the Space gravity
!! * when performing buoyancy computations.
!! */
property(gravity,Null<Vec2>, {
return pr(inner).wrap_gravity;
}, {
if(gravity==null) {
if(pr(inner).wrap_gravity!=null) {
pr(inner).wrap_gravity.pr(inner)._inuse = false;
pr(inner).wrap_gravity.dispose();
pr(inner).wrap_gravity = null;
}
}else {
Disposed(gravity,Vec2);
if(pr(inner).wrap_gravity==null) pr(inner).getgravity();
this.gravity.set(gravity);
}
})
!!/**
!! * @private
!! */
@:$keep public function toString() {
return "{ density: "+density
+" viscosity: "+viscosity
+" gravity: "+gravity
+" }";
}
}
You can’t perform that action at this time.