Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Get the effect the light should apply to a given location
- *
- * @param x The x coordinate of the location being considered for lighting
- * @param y The y coordinate of the location being considered for lighting
- * @param colouredLights True if we're supporting coloured lights
- *
- * @return The effect on a given location of the light in terms of colour components (all
- * the same if we don't support coloured lights)
- */
- public float[] getEffectAt(float x, float y, boolean colouredLights) {
- // first work out what propotion of the strength distance the light
- // is from the point. This is a value from 0-1 where 1 is the centre of the
- // light (i.e. full brightness) and 0 is the very edge (or outside) the lights
- // range
- float dx = (x - xpos);
- float dy = (y - ypos);
- float distance2 = (dx*dx)+(dy*dy);
- float effect = 1 - (distance2 / (strength*strength));
- if (effect < 0) {
- effect = 0;
- }
- // if we doing coloured lights then multiple the colour of the light
- // by the effect. Otherwise just use the effect for all components to
- // give white light
- if (colouredLights) {
- return new float[] {col.r * effect, col.g * effect, col.b * effect};
- } else {
- return new float[] {effect,effect,effect};
- }
- }
Add Comment
Please, Sign In to add comment