sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Getting view near and far planes through ruby?

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 5 Posters 330 Views 5 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • PixeroP Offline
      Pixero
      last edited by

      Is there any way of getting the near and far planes of the view through ruby?

      http://www.sketchucation.com/forums/download/file.php?id=46930&sid=074f6f2e61c3b43ebeb285fbf57bc351

      1 Reply Last reply Reply Quote 0
      • Chris FullmerC Offline
        Chris Fullmer
        last edited by

        Not that I know of. Unless you can determine how to calculate them. I think you can check them against the data shown in that PC only camera stats window (I forget the command to call that up though). I wouldn't even being to know how to approach that though.

        Lately you've been tan, suspicious for the winter.
        All my Plugins I've written

        1 Reply Last reply Reply Quote 0
        • PixeroP Offline
          Pixero
          last edited by

          Ok, so ... does anyone know how to calculate them?

          1 Reply Last reply Reply Quote 0
          • C Offline
            Cleverbeans
            last edited by

            I haven't done much work with perspective projection, or the view object, but my first impression would be that the near plane would be normal to camera.direction and go through the point returned by camera.target, then the far plane would have the same normal and be translated in the direction of that vector by the distance returned by the camera.focal_length method. If that's correct, then the calculation should be straightforward.

            1 Reply Last reply Reply Quote 0
            • TIGT Offline
              TIG Moderator
              last edited by

              When you say 'plane' do you mean the actual plane defined by [point,vector] ?

              The near plane - the screen center can be found from
              point=model.active_view.camera.eye
              and
              vector=model.active_view.camera.target.vector_to(model.active_view.camera.eye)

              The far plane ? you could do something similar with the target point ??

              IF you want to find the 'corners' of the 'screen' that's a different matter... involving fov etc ???

              TIG

              1 Reply Last reply Reply Quote 0
              • AdamBA Offline
                AdamB
                last edited by

                If you want worldspace near and far plane distances, just project the Model bounding box onto the lookat vector

                lookat = Sketchup.active_model.active_view.camera.target - Sketchup.active_model.active_view.camera.eye

                then project each corner of the model bounding box on this line. So:

                for i in 0...8
                #enumerate all the corners
                x = i & 1 != 0 ? Sketchup.active_model.bounds.min[0] : Sketchup.active_model.bounds.max[0]
                y = i & 2 != 0 ? Sketchup.active_model.bounds.min[1] : Sketchup.active_model.bounds.max[1]
                z = i & 4 != 0 ? Sketchup.active_model.bounds.min[2] : Sketchup.active_model.bounds.max[2]

                build a corner point to test

                c = Geom::Point3d.new(x,y,z)

                how far a long the line of sight it is

                d = lookat.dot(c - Sketchup.active_model.active_view.camera.eye)

                track minimum and maximum value of d

                end

                Developer of LightUp Click for website

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                Buy SketchPlus
                Buy SUbD
                Buy WrapR
                Buy eBook
                Buy Modelur
                Buy Vertex Tools
                Buy SketchCuisine
                Buy FormFonts

                Advertisement