3D City v-1.0
Computer Graphics Project
pointLight.h
Go to the documentation of this file.
1#pragma once
2
3#include "core.h"
4#include "node.h"
5#include "drawable.h"
9struct pointLight : public node {
10 private:
14
15 public:
16 float intensity;
17
18 float constant = 1;
19 float linear = 0.09;
20 float quadratic = 0.032;
21 // float constant = 0.85;
22 // float linear = 1.0;
23 // float quadratic = 0.06;
24
25 pointLight(const vec3 &pos, const float &intensity, Mesh *mesh = nullptr, const color &diffcol = color(255)) : position(pos), diffuseColor(diffcol), intensity(intensity), ambientColor(diffcol) {
26 if (mesh) {
27 meshes.emplace_back(mesh);
28 node::setpos(pos);
29 mesh->doLightCalculations = false;
30 }
31 }
32
33 void delpos(const vec3 &delta) {
34 position += delta;
35 node::delpos(delta);
36 }
37
38 void setpos(const vec3 &newPos) {
39 position = newPos;
40 node::setpos(newPos);
41 }
42
43 // void setmodel(node *model_in) {
44 // model = model_in;
45 // model->setpos(position);
46 // if (!model->meshes.empty()){
47 // model->meshes[0]->doLightCalculations=false;
48 // }
49 // }
50
51 void setdiffColor(const color &color) {
53 for (auto &mesh : node::meshes) {
54 mesh->material.diffuseColor = color;
55 mesh->material.specularColor = color;
56 }
57 }
58
59 void setColor(const vec3 &col) {
60 ambientColor = color(col);
62 }
63
64 [[nodiscard]] inline const vec3 &getpos() const { return position; }
65 [[nodiscard]] inline const color &get_diffuse_color() const { return diffuseColor; }
66 [[nodiscard]] inline const color &get_ambient_color() const { return ambientColor; }
67};
class that holds color with 8 bits per channel with 4 channels rgba.
Definition: core.h:165
this class represents all drawable entities that has a material and vertices
Definition: drawable.h:12
anything that can be transformed( has modelmatrix )
Definition: node.h:14
void setpos(const vec3 &position)
Definition: node.cpp:11
std::vector< drawable< Vertex > * > meshes
Definition: node.h:16
void delpos(const vec3 &delta)
Definition: node.cpp:6
pointlight
Definition: pointLight.h:9
void setdiffColor(const color &color)
Definition: pointLight.h:51
const vec3 & getpos() const
Definition: pointLight.h:64
vec3 position
Definition: pointLight.h:11
const color & get_ambient_color() const
Definition: pointLight.h:66
void setColor(const vec3 &col)
Definition: pointLight.h:59
color ambientColor
Definition: pointLight.h:13
float intensity
Definition: pointLight.h:16
const color & get_diffuse_color() const
Definition: pointLight.h:65
color diffuseColor
Definition: pointLight.h:12
float quadratic
Definition: pointLight.h:20
void delpos(const vec3 &delta)
Definition: pointLight.h:33
pointLight(const vec3 &pos, const float &intensity, Mesh *mesh=nullptr, const color &diffcol=color(255))
Definition: pointLight.h:25
float linear
Definition: pointLight.h:19
float constant
Definition: pointLight.h:18
void setpos(const vec3 &newPos)
Definition: pointLight.h:38