14 Replies Latest reply on May 11, 2006 9:41 AM by Michaelcov

    capturing the view from a second camera

    dsdsdsdsd Level 1
      hello;

      if I add a new camera to my world how do I capture what it sees;

      thanks
      dsdsdsdsd
        • 1. Re: capturing the view from a second camera
          James Newton, ACP Level 3
          Look up addCamera() and rect (camera). You must set the rect of an added camera to something other than the default rect(0, 0, 1 ,1)
          • 2. capturing the view from a second camera
            dsdsdsdsd Level 1
            hello openspark; thanks for responding;

            does this seem reasonable if I am trying to get an image from a camera in a 3D cast member to a texture?
            I believe my problem is in the copypixel line;


            -----------------------------------------------------------------------------
            lvo_junk = the_member.newcamera("junk")
            sprite(1).addcamera ( lvo_junk , 2 )
            lvo_junk.rect = rect ( 0 , 0 , 50 , 50 )

            image_object = image ( 50 , 50 , 32 , 0 )
            image_object .fill ( image_object.rect , rgb(255,255,255) )
            image_object .copypixels ( lvo_junk , image_object.rect , lvo_junk.rect )

            my_texture = the_world.newtexture( "junk_texture" , #fromimageobject , image_object )
            the_world.shader("srf_v_g").texturelist [1] = my_texture
            the_world.shader("srf_v_g").texturemodelist[1] = #wrapplanar
            ----------------------------------------------------------------------------------------


            any thoughts;
            thanks
            Shannon Burnett
            • 3. Re: capturing the view from a second camera
              dsdsdsdsd Level 1
              let me explain what I wish to do:

              I wish to put a new camera "behind" a mirror (model with shader and texture ) and to show the camera's view on the surface of the mirror;

              does this seem reasonable?

              thanks
              Shannon Burnett
              • 4. Re: capturing the view from a second camera
                James Newton, ACP Level 3
                Here's a behavior that you can drop on an empty 3D sprite. It creates a cube in front of the main camera and a sphere behind. It creats a second 'rear-view mirrir" camera to look backwards, and display the sphere.

                on beginSprite(me)
                tSprite = sprite(me.spriteNum)
                tMember = tSprite.member
                tMember.resetWorld()

                tCamera = tMember.newCamera("Rear-view mirror")
                -- Add to the list of cameras for the sprite
                tSprite.addCamera(tCamera, 2)

                -- Give the insert a different background color
                tCamera.colorBuffer.clearValue = rgb(51, 51, 51)
                -- Place insert at center of top of sprite
                tCamera.rect = rect(80, 10, 240, 50)

                -- Move this camera with the main camera...
                tSprite.camera.addChild(tCamera, #preserveParent)
                tCamera.rotate(0, 180, 0) -- ... but facing in the reverse direction

                -- Create a model in front of the main camera...
                tResource = tMember.newModelResource("Box", #box)
                tModel = tMember.newModel("Box", tResource) -- at center of world

                -- ... and another model behind the main camera
                tResource = tMember.newModelResource("Sphere", #sphere)
                tModel = tMember.newModel("Sphere", tResource)
                tModel.worldPosition = vector(0, 0, 500)
                end

                Is this the sort of thing that you are trying to do?

                To create the effect of a mirror, you should place the mirror camera at the position where the main camera would appear reflected in the mirror. You should also change the mirror camera's projectionAngle depending on the distance the main camera is from the mirror: the closer it is to the mirror, the wider the angle should be, so that the camera frustrum includes all the objects that the main camera would see in the mirror.

                An interesting project.
                • 5. Re: capturing the view from a second camera
                  Necromanthus Level 2
                  quote:

                  Originally posted by: Shannon Burnett
                  I wish to put a new camera "behind" a mirror (model with shader and texture ) and to show the camera's view on the surface of the mirror;

                  does this seem reasonable?


                  Hi Shannon,
                  Just create the second camera and tune up its position, rotation and FOV.
                  Also you have to change the rect of the W3D member (default : rect(0,0,320,200)) according to your needed texture size (64x64, 128x128, etc).
                  After that, at runtime, all you have to do is to switch the camera and to create a new texture #fromCastMember, using the W3D member as source.
                  At the end, restore the default camera.

                  But keep in mind: this kind of runtime created textures are frame rate killers !
                  So if you need my advice: no mirrors in shockwave !
                  LOL

                  • 6. Re: capturing the view from a second camera
                    dsdsdsdsd Level 1
                    openspark, thanks for your response;

                    however this is not quite right; imagine that I 'capture' the Rear-view mirror's view and transfer that view to a texture residing on a model;


                    necromanthus, thanks for your response also;
                    I thought that I was correct using
                    image_object = copypixel( new_camera , (a,b,c,d) , new_camera.rect )
                    then
                    my_texture = the_world.newtexture( ... , #fromimageobject , image_object )


                    any thoughts,
                    Shannon Burnett
                    • 7. Re: capturing the view from a second camera
                      Necromanthus Level 2
                      quote:

                      Originally posted by: Shannon Burnett
                      necromanthus, thanks for your response also;
                      I thought that I was correct using
                      image_object = copypixel( new_camera , (a,b,c,d) , new_camera.rect )
                      then
                      my_texture = the_world.newtexture( ... , #fromimageobject , image_object )


                      Avoid using copyPixels at runtime (because the frame rate is going down deeply).
                      The method I gave you works a little bit faster.
                      But obviously not enough faster for shockwave ...
                      Anyway, if you really want to emulate a mirror in SW3D (keeping a decent frame rate), use the algorithm I gave you.
                      Also, do NOTcreate textures bigger than 64x64 !
                      If you need badly a higher resolution, use a simple skip few frames routine and create a new texture after a sequence of (let's say) 5 frames.
                      Try to do your best.

                      • 8. Re: capturing the view from a second camera
                        dsdsdsdsd Level 1
                        necromanthus, thanks again;

                        unfortunately I am unable to make heads or tails of this;

                        but I do appreciate your time;

                        Shannon Burnett
                        • 9. Re: capturing the view from a second camera
                          Necromanthus Level 2
                          quote:

                          Originally posted by: Shannon Burnett
                          necromanthus, thanks again;
                          unfortunately I am unable to make heads or tails of this


                          I see ... is not so simple to transpose an algorithm into LINGO, isn't it ?
                          But because you're a nice person, download and study this example:
                          http://necromanthus.com/Games/ShockWave/tutorials/Mirror.html
                          note: the tricky part is that you don't need the second camera !

                          • 10. Re: capturing the view from a second camera
                            Level 7
                            necromanthus wrote:

                            > But because you're a nice person, download and study this example:
                            > http://necromanthus.com/Games/ShockWave/tutorials/Mirror.html
                            > note: the tricky part is that you don't need the second camera !

                            Nice. Do you intend to keep that page up long term. I've already downloaded the
                            file for future reference perhaps for my students. Can I link to your site? Will
                            you be increasing the amount of demos?

                            regards
                            Dean

                            Director Lecturer / Consultant
                            http://www.fbe.unsw.edu.au/learning/director
                            http://www.multimediacreative.com.au

                            • 11. Re: capturing the view from a second camera
                              Necromanthus Level 2
                              quote:

                              Originally posted by: Dean Utian
                              Nice. Do you intend to keep that page up long term. I've already downloaded the
                              file for future reference perhaps for my students. Can I link to your site? Will
                              you be increasing the amount of demos?


                              Hi Dean,
                              Yes. That's a permanent link (like this one: http://necromanthus.com/Games/ShockWave/tutorials/PanCamera.html )
                              Feel free to link to http://necromanthus.com (you may use this button: http://necromanthus.com/Images/necro_88x31.gif )
                              As I said some time ago, I intend to open a ShockWave subdomain on my site (containing many interesting SW examples and tutorials).
                              But I need a reason to do that.
                              And here is the reason: Adobe MUST update (and improve) the SW3D engine.
                              Otherwise, I can't waste my time for nothing.
                              So ... it's up to Adobe !

                              p.s.
                              Someone told me about the increased number of machine guns in australian schools.
                              ha ha ha


                              best regards
                              • 12. Re: capturing the view from a second camera
                                Michaelcov
                                Hi necromanthus.

                                I am interesting in the mirror script you have uploaded and have attempted to add it to my game code. I have added an object called mirror but I get the error message
                                object expected
                                for this line
                                w.newTexture("mir",#fromCastMember,member("3D"))

                                3D is the name of my 3D sprite.

                                Have I missed something very obvious lol?

                                Thanks

                                Michael
                                • 13. Re: capturing the view from a second camera
                                  Necromanthus Level 2
                                  quote:

                                  Originally posted by: Michaelcov
                                  I am interesting in the mirror script you have uploaded and have attempted to add it to my game code. I have added an object called mirror but I get the error message
                                  object expected
                                  for this line
                                  w.newTexture("mir",#fromCastMember,member("3D"))

                                  3D is the name of my 3D sprite.

                                  Have I missed something very obvious lol?


                                  Hi Michael,
                                  Don't forget to declare the global ' w' variable in the MovieScript ' init' !
                                  p.s.
                                  But don't waste your time anymore.
                                  As I said before: this kind of runtime created textures are frame rate killers.
                                  This example is for didactical purposes only.
                                  Can't be used in a serious project (containing a bunch of polygons and tons of LINGO).
                                  cheers

                                  • 14. Re: capturing the view from a second camera
                                    Michaelcov Level 1
                                    Ok, I won't try mirrors. Advice taken

                                    Michael