Class: Quake::Renderer::GLBrushModel

Inherits:
Object
  • Object
show all
Defined in:
lib/quake/renderer/gl_brush_model.rb

Overview

Renders BSP sub-models (brush entities like doors, buttons, platforms). Each brush entity references a model in the BSP models array (models, [2], etc.) and has a position/angle from its entity definition.

Constant Summary collapse

BACKFACE_EPSILON =
0.01

Instance Method Summary collapse

Constructor Details

#initialize(level, texture_manager, lightmap) ⇒ GLBrushModel

Returns a new instance of GLBrushModel.



13
14
15
16
17
18
19
20
21
# File 'lib/quake/renderer/gl_brush_model.rb', line 13

def initialize(level, texture_manager, lightmap)
  @level = level
  @texture_manager = texture_manager
  @lightmap = lightmap

  # Precompute surfaces for each sub-model (model index 1+)
  @model_surfaces = {}
  precompute_all_submodels
end

Instance Method Details

#render(entities, view_origin: Math::Vec3::ORIGIN, time: 0.0, frustum: nil) ⇒ Object

Render all brush entities at their current positions. entities: array of Entity objects that have model_index set



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/quake/renderer/gl_brush_model.rb', line 25

def render(entities, view_origin: Math::Vec3::ORIGIN, time: 0.0, frustum: nil)
  GL.Enable(GL::TEXTURE_2D)
  GL.Color3f(1.0, 1.0, 1.0)

  entities.each do |ent|
    next unless ent.brush_entity?
    next if ent.removed?
    surfaces = @model_surfaces[ent.model_index]
    next unless surfaces
    next if frustum && culled_by_frustum?(ent, frustum)

    GL.PushMatrix
    GL.Translatef(ent.position.x, ent.position.y, ent.position.z)

    if brush_model_rotated?(ent)
      GL.Rotatef(ent.angles.y, 0.0, 0.0, 1.0)
      # Net +pitch: R_DrawBrushModel negates pitch before
      # R_RotateForEntity's -pitch rotation ("stupid quake bug")
      GL.Rotatef(ent.angles.x, 0.0, 1.0, 0.0)
      GL.Rotatef(ent.angles.z, 1.0, 0.0, 0.0)
    end

    modelorg = brush_model_modelorg(view_origin, ent)
    render_model_surfaces(surfaces, modelorg, time: time, alternate: ent.frame.to_i.positive?)

    GL.PopMatrix
  end
end