| 46 | |
| 47 | |
| 48 | class Light: |
| 49 | def __init__(self, type, position, target, color): |
| 50 | self.enabled = True |
| 51 | self.type = type |
| 52 | self.position = rl.ffi.new("struct Vector3 *",position) |
| 53 | self.target = target |
| 54 | self.color = color |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | def configure(self, id, shader): |
| 60 | self.shader = shader |
| 61 | #// TODO: Below code doesn't look good to me, |
| 62 | #// it assumes a specific shader naming and structure |
| 63 | #// Probably this implementation could be improved |
| 64 | self.enabledName = f"lights[{id}].enabled" |
| 65 | self.typeName = f"lights[{id}].type" |
| 66 | self.posName = f"lights[{id}].position" |
| 67 | self.targetName = f"lights[{id}].target" |
| 68 | self.colorName = f"lights[{id}].color" |
| 69 | |
| 70 | self.enabledLoc = rl.GetShaderLocation(shader, self.enabledName.encode('utf-8')) |
| 71 | self.typeLoc = rl.GetShaderLocation(shader, self.typeName.encode('utf-8')) |
| 72 | self.posLoc = rl.GetShaderLocation(shader, self.posName.encode('utf-8')) |
| 73 | self.targetLoc = rl.GetShaderLocation(shader, self.targetName.encode('utf-8')) |
| 74 | self.colorLoc = rl.GetShaderLocation(shader, self.colorName.encode('utf-8')) |
| 75 | |
| 76 | self.UpdateLightValues() |
| 77 | |
| 78 | |
| 79 | #// Send light properties to shader |
| 80 | #// NOTE: Light shader locations should be available |
| 81 | def UpdateLightValues(self): |
| 82 | #// Send to shader light enabled state and type |
| 83 | rl.SetShaderValue(self.shader, self.enabledLoc, rl.ffi.new("int *",self.enabled), rl.SHADER_UNIFORM_INT) |
| 84 | rl.SetShaderValue(self.shader, self.typeLoc, rl.ffi.new("int *",self.type), rl.SHADER_UNIFORM_INT) |
| 85 | |
| 86 | #// Send to shader light position values |
| 87 | position = [ self.position.x, self.position.y, self.position.z] |
| 88 | rl.SetShaderValue(self.shader, self.posLoc, rl.ffi.new("struct Vector3 *",position), rl.SHADER_UNIFORM_VEC3) |
| 89 | |
| 90 | #// Send to shader light target position values |
| 91 | target =[ self.target.x, self.target.y, self.target.z ] |
| 92 | rl.SetShaderValue(self.shader, self.targetLoc, rl.ffi.new("struct Vector3 *",target), rl.SHADER_UNIFORM_VEC3) |
| 93 | |
| 94 | #// Send to shader light color values |
| 95 | color = [self.color[0]/255.0, self.color[1]/255.0, self.color[2]/255.0, self.color[3]/255.0] |
| 96 | rl.SetShaderValue(self.shader, self.colorLoc, rl.ffi.new("struct Vector4 *",color), rl.SHADER_UNIFORM_VEC4) |
| 97 | |
| 98 | |
| 99 |
no outgoing calls
no test coverage detected