Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8217472: Add attenuation for PointLight #43

Open
wants to merge 11 commits into
base: master
from
@@ -33,83 +33,83 @@
public class NGPointLight extends NGLightBase {

/** Constant attenuation factor default value */
private static final double DEFAULT_CA = 1;
private static final float DEFAULT_CA = 1;
/** Linear attenuation factor default value */
private static final double DEFAULT_LA = 0;
private static final float DEFAULT_LA = 0;
/** Quadratic attenuation factor default value */
private static final double DEFAULT_QA = 0;
private static final float DEFAULT_QA = 0;
/** Max range default value */
private static final double DEFAULT_MAX_RANGE = Double.POSITIVE_INFINITY;
private static final float DEFAULT_MAX_RANGE = Float.POSITIVE_INFINITY;

This conversation was marked as resolved by kevinrushforth

This comment has been minimized.

Copy link
@arapte

arapte Jan 3, 2020

Will it be a good idea to move these constants to PointLight class?
However they look good here too.

This comment has been minimized.

Copy link
@nlisker

nlisker Jan 3, 2020

Author Contributor

If they are in PointLight it will be difficult for the peer to access them (will need to do through the accessor). Also, the parent NGLightBase holds the defaults for color and lightOn.

public NGPointLight() {
}

public static double getDefaultCa() {
public static float getDefaultCa() {
return DEFAULT_CA;
}

public static double getDefaultLa() {
public static float getDefaultLa() {
return DEFAULT_LA;
}

public static double getDefaultQa() {
public static float getDefaultQa() {
return DEFAULT_QA;
}

public static double getDefaultMaxRange() {
public static float getDefaultMaxRange() {
return DEFAULT_MAX_RANGE;
}


private double ca = DEFAULT_CA;
private float ca = DEFAULT_CA;

public double getCa() {
public float getCa() {
return ca;
}

public void setCa(double ca) {
public void setCa(float ca) {
if (this.ca != ca) {
this.ca = ca;
visualsChanged();
}
}


private double la = DEFAULT_LA;
private float la = DEFAULT_LA;

public double getLa() {
public float getLa() {
return la;
}

public void setLa(double la) {
public void setLa(float la) {
if (this.la != la) {
this.la = la;
visualsChanged();
}
}


private double qa = DEFAULT_QA;
private float qa = DEFAULT_QA;

public double getQa() {
public float getQa() {
return qa;
}

public void setQa(double qa) {
public void setQa(float qa) {
if (this.qa != qa) {
this.qa = qa;
visualsChanged();
}
}


private double maxRange = DEFAULT_MAX_RANGE;
private float maxRange = DEFAULT_MAX_RANGE;

public double getMaxRange() {
public float getMaxRange() {
return maxRange;
}

public void setMaxRange(double maxRange) {
public void setMaxRange(float maxRange) {
if (this.maxRange != maxRange) {
this.maxRange = maxRange < 0 ? 0 : maxRange;
visualsChanged();
@@ -117,10 +117,10 @@ private void renderMeshView(Graphics g) {
(float)cameraPos.y,
(float)cameraPos.z,
1.0f, 1.0f, 1.0f, 1.0f,
(float) NGPointLight.getDefaultCa(),
(float) NGPointLight.getDefaultLa(),
(float) NGPointLight.getDefaultQa(),
(float) NGPointLight.getDefaultMaxRange());
NGPointLight.getDefaultCa(),
NGPointLight.getDefaultLa(),
NGPointLight.getDefaultQa(),
NGPointLight.getDefaultMaxRange());
} else {
float ambientRed = 0.0f;
float ambientBlue = 0.0f;
@@ -160,10 +160,10 @@ private void renderMeshView(Graphics g) {
(float)lightWT.getMyt(),
(float)lightWT.getMzt(),
rL, gL, bL, 1.0f,
(float) light.getCa(),
(float) light.getLa(),
(float) light.getQa(),
(float) light.getMaxRange());
light.getCa(),
light.getLa(),
light.getQa(),
light.getMaxRange());
}
} else if (lightBase instanceof NGAmbientLight) {
// Accumulate ambient lights
@@ -223,10 +223,10 @@ private NGNode doCreatePeer() {
private void doUpdatePeer() {
if (isDirty(DirtyBits.NODE_LIGHT)) {
NGPointLight peer = getPeer();
peer.setCa(getConstantAttenuation());
peer.setLa(getLinearAttenuation());
peer.setQa(getQuadraticAttenuation());
peer.setMaxRange(getMaxRange());
peer.setCa((float) getConstantAttenuation());
peer.setLa((float) getLinearAttenuation());
peer.setQa((float) getQuadraticAttenuation());
peer.setMaxRange((float) getMaxRange());
}
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.