Skip to content

Commit

Permalink
Adding simple way to ignore attached fixtures
Browse files Browse the repository at this point in the history
Implementing libgdx#36
  • Loading branch information
rinold committed Dec 4, 2014
1 parent be5f849 commit b9bff07
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
18 changes: 17 additions & 1 deletion src/box2dLight/DirectionalLight.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void update () {
xAxelOffSet = 1;
yAxelOffSet = 1;
}

final float widthOffSet = sizeOfScreen * -sin;
final float heightOffSet = sizeOfScreen * cos;

Expand Down Expand Up @@ -238,5 +238,21 @@ public void setPosition (Vector2 position) {
@Override
public void setDistance(float dist) {
}

/** Not applicable for this light type **/
@Deprecated
@Override
public void setIgnoreAttachedBody(boolean flag) {
}

/** Not applicable for this light type
* <p>Always return {@code false}
**/
@Deprecated
@Override
public boolean getIgnoreAttachedBody() {
return false;
}


}
28 changes: 26 additions & 2 deletions src/box2dLight/Light.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public abstract class Light implements Disposable {
protected boolean staticLight = false;
protected boolean culled = false;
protected boolean dirty = true;
protected boolean ignoreBody = false;

protected int rayNum;
protected int vertexNum;
Expand Down Expand Up @@ -352,7 +353,25 @@ public float getDistance() {
public boolean contains(float x, float y) {
return false;
}


/**
* Sets if the attached body fixtures should be ignored during raycasting
*
* @param flag - if {@code true} all the fixtures of attached body
* will be ignored and will not create any shadows for this
* light. By default is set to {@code false}.
*/
public void setIgnoreAttachedBody(boolean flag) {
ignoreBody = flag;
}

/**
* @return if the attached body fixtures will be ignored during raycasting
*/
public boolean getIgnoreAttachedBody() {
return ignoreBody;
}

/**
* Internal method for mesh update depending on ray number
*/
Expand All @@ -376,11 +395,16 @@ void setRayNum(int rays) {
@Override
final public float reportRayFixture(Fixture fixture, Vector2 point,
Vector2 normal, float fraction) {

if ((filterA != null) && !contactFilter(fixture))
return -1;

if (ignoreBody && fixture.getBody() == getBody())
return -1;

// if (fixture.isSensor())
// return -1;

mx[m_index] = point.x;
my[m_index] = point.y;
f[m_index] = fraction;
Expand Down

0 comments on commit b9bff07

Please sign in to comment.