-Subproject commit 03a7d614b7e7e7c57c87b022b9bf76b09c5242fb
+Subproject commit ed7b81207b13b87a3a9097b9e25ebd06aa814d97
in.Skip(Token::EQUALS);
if (prop_name == "root") {
model.RootPart().Read(in, tex_index, shapes);
+ } else if (prop_name == "eyes") {
+ model.SetEyes(in.GetULong());
} else {
while (in.HasMore() && in.Peek().type != Token::SEMICOLON) {
in.Next();
save.Write(master.GetWorldConf());
}
res.Load(master.GetEnv().loader, "default");
+ if (res.models.size() < 1) {
+ throw std::runtime_error("need at least one model to run");
+ }
+ res.models[0].Instantiate(player.GetEntity().GetModel());
sounds.Load(master.GetEnv().loader, res.snd_index);
interface.SetInventorySlots(res.block_types.size() - 1);
chunk_renderer.LoadTextures(master.GetEnv().loader, res.tex_index);
const glm::mat4 &Projection() const noexcept { return projection; }
const glm::mat4 &View() const noexcept { return view; }
- void View(const glm::mat4 &v) noexcept { view = v; }
+ void View(const glm::mat4 &v) noexcept;
private:
void UpdateProjection() noexcept;
UpdateProjection();
}
+void Camera::View(const glm::mat4 &v) noexcept {
+ view = v;
+}
void Camera::UpdateProjection() noexcept {
projection = glm::perspective(fov, aspect, near, far);
void Viewport::WorldPosition(const glm::mat4 &t) noexcept {
- cam.View(glm::inverse(t));
+ const glm::vec3 offset(0.0f, 0.0f, 0.0f);
+ //const glm::vec3 offset(0.0f, 0.0f, -5.0f);
+ cam.View(glm::translate(glm::inverse(t), glm::vec3(t * glm::vec4(offset, 0.0f))));
ChunkProgram().SetView(cam.View());
sky_prog.Activate();
SkyBoxProgram().SetView(cam.View());
operator bool() const noexcept { return model; }
const Model &GetModel() const noexcept { return *model; }
+ glm::mat4 EyesTransform() const noexcept;
+
void Render(const glm::mat4 &, DirectionalLighting &);
private:
Part &GetPart(std::size_t i) noexcept { return *part[i]; }
const Part &GetPart(std::size_t i) const noexcept { return *part[i]; }
+ void SetEyes(std::uint16_t id) { eyes_id = id; }
+
+ const Part &GetEyesPart() const noexcept { return GetPart(eyes_id); }
+
void Enumerate();
void Instantiate(Instance &) const;
std::uint32_t id;
Part root;
std::vector<Part *> part;
+ std::uint16_t eyes_id;
};
}
+glm::mat4 Instance::EyesTransform() const noexcept {
+ return model->GetEyesPart().GlobalTransform(*this);
+}
+
void Instance::Render(const glm::mat4 &M, DirectionalLighting &prog) {
model->RootPart().Render(M, *this, prog);
}
Model::Model()
: id(0)
, root()
-, part() {
+, part()
+, eyes_id(0) {
}
if (res.models.size() < 2) {
throw std::runtime_error("need at least two models to run");
}
+ res.models[0].Instantiate(player.GetEntity().GetModel());
sounds.Load(env.loader, res.snd_index);
- spawner.LimitModels(0, res.models.size());
+ spawner.LimitModels(1, res.models.size());
interface.SetInventorySlots(res.block_types.size() - 1);
generator.LoadTypes(res.block_types);
chunk_renderer.LoadTextures(env.loader, res.tex_index);
}
void MasterState::Render(Viewport &viewport) {
- viewport.WorldPosition(player.GetEntity().Transform(player.GetEntity().ChunkCoords()));
+ viewport.WorldPosition(
+ player.GetEntity().Transform(player.GetEntity().ChunkCoords())
+ * player.GetEntity().GetModel().EyesTransform());
if (config.video.world) {
chunk_renderer.Render(viewport);
world.Render(viewport);
const glm::quat &Orientation() const noexcept { return state.orient; }
void Orientation(const glm::quat &o) noexcept { state.orient = o; }
- glm::mat4 Transform(const glm::ivec3 &reference) const noexcept {
- return state.Transform(reference);
- }
+ /// get a transform for this entity's coordinate space
+ glm::mat4 Transform(const glm::ivec3 &reference) const noexcept;
+ /// get a transform for this entity's view space
+ glm::mat4 ViewTransform(const glm::ivec3 &reference) const noexcept;
+ /// get a ray in entity's face direction originating from center of vision
Ray Aim(const Chunk::Pos &chunk_offset) const noexcept;
void SetState(const EntityState &s) noexcept { state = s; }
state.AdjustPosition();
}
+glm::mat4 Entity::Transform(const glm::ivec3 &reference) const noexcept {
+ return state.Transform(reference);
+}
+
+glm::mat4 Entity::ViewTransform(const glm::ivec3 &reference) const noexcept {
+ glm::mat4 transform = Transform(reference);
+ if (model) {
+ transform *= model.EyesTransform();
+ }
+ return transform;
+}
+
Ray Entity::Aim(const Chunk::Pos &chunk_offset) const noexcept {
- glm::mat4 transform = Transform(chunk_offset);
+ glm::mat4 transform = ViewTransform(chunk_offset);
glm::vec4 from = transform * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
from /= from.w;
glm::vec4 to = transform * glm::vec4(0.0f, 0.0f, -1.0f, 1.0f);