~gimaker/peekabot/multi-connect

« back to all changes in this revision

Viewing changes to src/renderer/primitives/AxisTripod.cc

  • Committer: Staffan Gimåker
  • Date: 2008-07-31 13:37:36 UTC
  • Revision ID: staffan_gimker_staffan_at_gimaker.se-20080731133736-u3gs51w6f9mswj18
Fixed a rendering bug where the size of axis tripods (for selected objects)
was not rendered correctly when the near plane was set to anything but 1 m.

In the process, a few helper methods was introduced for often used calculations 
(such as calculating the height of the viewport in meters).

Show diffs side-by-side

added added

removed removed

Lines of Context:
173
173
 
174
174
    const Vector4f &wp = get_parent()->get_world_pos();
175
175
 
 
176
    // v = The tripods position relative the camera used to render it
176
177
    Vector3r v = wp-cam->get_viewer_world_pos();
 
178
    // u = Camera viewing vector
177
179
    Vector3r u = cam->get_view_vector();
 
180
 
 
181
    // Overwrite v with the projection of v on u.
 
182
    // |v| is now the distance to the tripod along the view vector
178
183
    v = (u*v) * u;
179
 
    float sz = v.norm()*64*tanf(cam->get_fov_rad()/2)*cam->get_near_plane()/(cam->get_viewport_height()/2.0f);
180
184
 
 
185
    // We can calculate how big the tripod should be by:
 
186
    // 1) calculating how big (in meters) it should be to be rendered as 64 
 
187
    //    pixels if it was situated at depth x=near
 
188
    // 2) use similarity and the result from 1 to calculate how big it has to
 
189
    //    be given its depth of x=|v|
 
190
    float sz = (
 
191
        64/cam->get_pixels_per_meter() * // 1 
 
192
        v.norm()/cam->get_near_plane()); // 2!
 
193
    
181
194
    context.get_batch(0).render_line(
182
195
        wp, wp + get_parent()->get_mtow()(0)*sz,
183
196
        RGBColor(1,0,0));