WoW Model Viewer
Your premiere tool for viewing, equipping and animating World of Warcraft models.
Loading...
Searching...
No Matches
ModelLight.cpp
Go to the documentation of this file.
1#include "ModelLight.h"
2
3#include <glm/gtc/type_ptr.hpp>
4
5#include "wow_enums.h"
6#include "Logger.h"
7
8void ModelLight::init(GameFile* f, ModelLightDef& mld, std::vector<uint32>& global)
9{
10 tpos = pos = mld.pos;
11 tdir = dir = glm::vec3(0, 1, 0); // no idea
12 type = mld.type;
13 parent = mld.bone;
14 ambColor.init(mld.ambientColor, f, global);
15 ambIntensity.init(mld.ambientIntensity, f, global);
16 diffColor.init(mld.diffuseColor, f, global);
17 diffIntensity.init(mld.diffuseIntensity, f, global);
18 AttenStart.init(mld.attenuationStart, f, global);
19 AttenEnd.init(mld.attenuationEnd, f, global);
20 UseAttenuation.init(mld.useAttenuation, f, global);
21}
22
23void ModelLight::setup(size_t time, GLuint l)
24{
25 glm::vec4 ambcol(ambColor.getValue(0, time) * ambIntensity.getValue(0, time), 1.0f);
26 glm::vec4 diffcol(diffColor.getValue(0, time) * diffIntensity.getValue(0, time), 1.0f);
27 glm::vec4 p;
29 {
30 // directional
31 p = glm::vec4(tdir, 0.0f);
32 }
33 else if (type == MODELLIGHT_POINT)
34 {
35 // point
36 p = glm::vec4(tpos, 1.0f);
37 }
38 else
39 {
40 p = glm::vec4(tpos, 1.0f);
41 LOG_ERROR << "Light type" << type << "is unknown.";
42 }
43 //gLog("Light %d (%f,%f,%f) (%f,%f,%f) [%f,%f,%f]\n", l-GL_LIGHT4, ambcol.x, ambcol.y, ambcol.z, diffcol.x, diffcol.y, diffcol.z, p.x, p.y, p.z);
44 glLightfv(l, GL_POSITION, glm::value_ptr(p));
45 glLightfv(l, GL_DIFFUSE, glm::value_ptr(diffcol));
46 glLightfv(l, GL_AMBIENT, glm::value_ptr(ambcol));
47 glEnable(l);
48}
#define LOG_ERROR
Definition Logger.h:11
T getValue(ssize_t anim, size_t time)
Definition animated.h:178
void init(AnimationBlock &b, GameFile *f, std::vector< uint32 > &gs)
Definition animated.h:264
Abstract base class representing a file within the game data archive.
Definition GameFile.h:12
AnimationBlock useAttenuation
glm::vec3 pos
AnimationBlock ambientIntensity
AnimationBlock ambientColor
AnimationBlock diffuseIntensity
AnimationBlock diffuseColor
AnimationBlock attenuationStart
AnimationBlock attenuationEnd
Animated< float > diffIntensity
Definition ModelLight.h:24
ssize_t parent
Parent bone index (-1 if none).
Definition ModelLight.h:21
Animated< float > ambIntensity
Definition ModelLight.h:24
glm::vec3 tpos
Definition ModelLight.h:22
Animated< float > AttenStart
Definition ModelLight.h:24
void setup(size_t time, GLuint l)
Set up the OpenGL light for rendering.
Animated< int > UseAttenuation
Whether attenuation is enabled.
Definition ModelLight.h:25
glm::vec3 dir
Definition ModelLight.h:22
ssize_t type
Light type: 0 = directional, 1 = point.
Definition ModelLight.h:20
glm::vec3 pos
Definition ModelLight.h:22
void init(GameFile *f, ModelLightDef &mld, std::vector< uint32 > &global)
Initialise from an M2 light definition block.
Definition ModelLight.cpp:8
Animated< glm::vec3 > diffColor
Definition ModelLight.h:23
Animated< float > AttenEnd
Intensity and attenuation tracks.
Definition ModelLight.h:24
Animated< glm::vec3 > ambColor
Diffuse and ambient colour tracks.
Definition ModelLight.h:23
glm::vec3 tdir
Position, transformed position, direction, transformed direction.
Definition ModelLight.h:22
@ MODELLIGHT_DIRECTIONAL
Definition wow_enums.h:267
@ MODELLIGHT_POINT
Definition wow_enums.h:268