Create Wall 3D math oriented away from camera











up vote
0
down vote

favorite












I have 2 Points which has x,y,z let's say from and to I am drawing wall between them using ARkit ios



To draw wall I use static height let's say 5 Meters



    node.position = SCNVector3(from.x + (to.x - from.x) * 0.5,
from.y + height * 0.5,
from.z + (to.z - from.z) * 0.5)


now I use following code to set angles



       // orientation of the wall is fairly simple. we only need to orient it around the y axis,
// and the angle is calculated with 2d math.. now this calculation does not factor in the position of the
// camera, and so if you move the cursor right relative to the starting position the
// wall will be oriented away from the camera (in this app the wall material is set as double sided so you will not notice)
// - obviously if you want to render something on the walls, this issue will need to be resolved.

node.eulerAngles = SCNVector3(0,
-atan2(to.x - node.position.x, from.z - node.position.z) - Float.pi * 0.5,
0)


And I am rendering video into the wall.



Issue is If I draw from point1 to point2 (drag to right) Video is perfectly fine. But I start from point2 to point1 video is flipped because ofeulerAngles is different in both case




Angle point1 to point2 --> (0.000000 -1.000000 0.000000 3.735537)



Angle point2 to point1 -- > (0.000000 -1.000000 0.000000 0.478615)




Here is uploaded images of result



https://stackoverflow.com/questions/53282351/arkit-add-2d-video-flipped-by-x



Any help would be appreciated.










share|cite|improve this question




























    up vote
    0
    down vote

    favorite












    I have 2 Points which has x,y,z let's say from and to I am drawing wall between them using ARkit ios



    To draw wall I use static height let's say 5 Meters



        node.position = SCNVector3(from.x + (to.x - from.x) * 0.5,
    from.y + height * 0.5,
    from.z + (to.z - from.z) * 0.5)


    now I use following code to set angles



           // orientation of the wall is fairly simple. we only need to orient it around the y axis,
    // and the angle is calculated with 2d math.. now this calculation does not factor in the position of the
    // camera, and so if you move the cursor right relative to the starting position the
    // wall will be oriented away from the camera (in this app the wall material is set as double sided so you will not notice)
    // - obviously if you want to render something on the walls, this issue will need to be resolved.

    node.eulerAngles = SCNVector3(0,
    -atan2(to.x - node.position.x, from.z - node.position.z) - Float.pi * 0.5,
    0)


    And I am rendering video into the wall.



    Issue is If I draw from point1 to point2 (drag to right) Video is perfectly fine. But I start from point2 to point1 video is flipped because ofeulerAngles is different in both case




    Angle point1 to point2 --> (0.000000 -1.000000 0.000000 3.735537)



    Angle point2 to point1 -- > (0.000000 -1.000000 0.000000 0.478615)




    Here is uploaded images of result



    https://stackoverflow.com/questions/53282351/arkit-add-2d-video-flipped-by-x



    Any help would be appreciated.










    share|cite|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have 2 Points which has x,y,z let's say from and to I am drawing wall between them using ARkit ios



      To draw wall I use static height let's say 5 Meters



          node.position = SCNVector3(from.x + (to.x - from.x) * 0.5,
      from.y + height * 0.5,
      from.z + (to.z - from.z) * 0.5)


      now I use following code to set angles



             // orientation of the wall is fairly simple. we only need to orient it around the y axis,
      // and the angle is calculated with 2d math.. now this calculation does not factor in the position of the
      // camera, and so if you move the cursor right relative to the starting position the
      // wall will be oriented away from the camera (in this app the wall material is set as double sided so you will not notice)
      // - obviously if you want to render something on the walls, this issue will need to be resolved.

      node.eulerAngles = SCNVector3(0,
      -atan2(to.x - node.position.x, from.z - node.position.z) - Float.pi * 0.5,
      0)


      And I am rendering video into the wall.



      Issue is If I draw from point1 to point2 (drag to right) Video is perfectly fine. But I start from point2 to point1 video is flipped because ofeulerAngles is different in both case




      Angle point1 to point2 --> (0.000000 -1.000000 0.000000 3.735537)



      Angle point2 to point1 -- > (0.000000 -1.000000 0.000000 0.478615)




      Here is uploaded images of result



      https://stackoverflow.com/questions/53282351/arkit-add-2d-video-flipped-by-x



      Any help would be appreciated.










      share|cite|improve this question















      I have 2 Points which has x,y,z let's say from and to I am drawing wall between them using ARkit ios



      To draw wall I use static height let's say 5 Meters



          node.position = SCNVector3(from.x + (to.x - from.x) * 0.5,
      from.y + height * 0.5,
      from.z + (to.z - from.z) * 0.5)


      now I use following code to set angles



             // orientation of the wall is fairly simple. we only need to orient it around the y axis,
      // and the angle is calculated with 2d math.. now this calculation does not factor in the position of the
      // camera, and so if you move the cursor right relative to the starting position the
      // wall will be oriented away from the camera (in this app the wall material is set as double sided so you will not notice)
      // - obviously if you want to render something on the walls, this issue will need to be resolved.

      node.eulerAngles = SCNVector3(0,
      -atan2(to.x - node.position.x, from.z - node.position.z) - Float.pi * 0.5,
      0)


      And I am rendering video into the wall.



      Issue is If I draw from point1 to point2 (drag to right) Video is perfectly fine. But I start from point2 to point1 video is flipped because ofeulerAngles is different in both case




      Angle point1 to point2 --> (0.000000 -1.000000 0.000000 3.735537)



      Angle point2 to point1 -- > (0.000000 -1.000000 0.000000 0.478615)




      Here is uploaded images of result



      https://stackoverflow.com/questions/53282351/arkit-add-2d-video-flipped-by-x



      Any help would be appreciated.







      matrices 3d rotations orientation computer-vision






      share|cite|improve this question















      share|cite|improve this question













      share|cite|improve this question




      share|cite|improve this question








      edited Nov 14 at 14:43









      Widawensen

      4,34121444




      4,34121444










      asked Nov 14 at 5:34









      Prashant Tukadiya

      1013




      1013






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          I have fixed issue with temporary solution still looking for a better one



          Issue is of wall. wall is flipped other side of camera when draw from right to left direction. I have figure it out by setting isDoubleSided = false and by applying a image as diffuse contents which has text and I can see that image is flipped itself.



          I have tried many things but this one helps me




          1. Normalize vector

          2. Find the cross between to SCNVectors

          3. If y > 0 I just swapped from and to Value


          Code



              let normalizedTO = to.normalized()
          let normalizedFrom = from.normalized()
          let angleBetweenTwoVectors = normalizedTO.cross(normalizedFrom)

          var from = from
          var to = to
          if angleBetweenTwoVectors.y > 0 {
          let temp = from
          from = to
          to = temp
          }

          // Inside extension of SCNVector3
          func normalized() -> SCNVector3 {
          if self.length() == 0 {
          return self
          }

          return self / self.length()
          }

          func cross(_ vec: SCNVector3) -> SCNVector3 {
          return SCNVector3(self.y * vec.z - self.z * vec.y, self.z * vec.x - self.x * vec.z, self.x * vec.y - self.y * vec.x)
          }


          Hope it is helpful. If anyone know better solution please answer it.






          share|cite|improve this answer





















            Your Answer





            StackExchange.ifUsing("editor", function () {
            return StackExchange.using("mathjaxEditing", function () {
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
            });
            });
            }, "mathjax-editing");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "69"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            noCode: true, onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2997836%2fcreate-wall-3d-math-oriented-away-from-camera%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            I have fixed issue with temporary solution still looking for a better one



            Issue is of wall. wall is flipped other side of camera when draw from right to left direction. I have figure it out by setting isDoubleSided = false and by applying a image as diffuse contents which has text and I can see that image is flipped itself.



            I have tried many things but this one helps me




            1. Normalize vector

            2. Find the cross between to SCNVectors

            3. If y > 0 I just swapped from and to Value


            Code



                let normalizedTO = to.normalized()
            let normalizedFrom = from.normalized()
            let angleBetweenTwoVectors = normalizedTO.cross(normalizedFrom)

            var from = from
            var to = to
            if angleBetweenTwoVectors.y > 0 {
            let temp = from
            from = to
            to = temp
            }

            // Inside extension of SCNVector3
            func normalized() -> SCNVector3 {
            if self.length() == 0 {
            return self
            }

            return self / self.length()
            }

            func cross(_ vec: SCNVector3) -> SCNVector3 {
            return SCNVector3(self.y * vec.z - self.z * vec.y, self.z * vec.x - self.x * vec.z, self.x * vec.y - self.y * vec.x)
            }


            Hope it is helpful. If anyone know better solution please answer it.






            share|cite|improve this answer

























              up vote
              0
              down vote













              I have fixed issue with temporary solution still looking for a better one



              Issue is of wall. wall is flipped other side of camera when draw from right to left direction. I have figure it out by setting isDoubleSided = false and by applying a image as diffuse contents which has text and I can see that image is flipped itself.



              I have tried many things but this one helps me




              1. Normalize vector

              2. Find the cross between to SCNVectors

              3. If y > 0 I just swapped from and to Value


              Code



                  let normalizedTO = to.normalized()
              let normalizedFrom = from.normalized()
              let angleBetweenTwoVectors = normalizedTO.cross(normalizedFrom)

              var from = from
              var to = to
              if angleBetweenTwoVectors.y > 0 {
              let temp = from
              from = to
              to = temp
              }

              // Inside extension of SCNVector3
              func normalized() -> SCNVector3 {
              if self.length() == 0 {
              return self
              }

              return self / self.length()
              }

              func cross(_ vec: SCNVector3) -> SCNVector3 {
              return SCNVector3(self.y * vec.z - self.z * vec.y, self.z * vec.x - self.x * vec.z, self.x * vec.y - self.y * vec.x)
              }


              Hope it is helpful. If anyone know better solution please answer it.






              share|cite|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                I have fixed issue with temporary solution still looking for a better one



                Issue is of wall. wall is flipped other side of camera when draw from right to left direction. I have figure it out by setting isDoubleSided = false and by applying a image as diffuse contents which has text and I can see that image is flipped itself.



                I have tried many things but this one helps me




                1. Normalize vector

                2. Find the cross between to SCNVectors

                3. If y > 0 I just swapped from and to Value


                Code



                    let normalizedTO = to.normalized()
                let normalizedFrom = from.normalized()
                let angleBetweenTwoVectors = normalizedTO.cross(normalizedFrom)

                var from = from
                var to = to
                if angleBetweenTwoVectors.y > 0 {
                let temp = from
                from = to
                to = temp
                }

                // Inside extension of SCNVector3
                func normalized() -> SCNVector3 {
                if self.length() == 0 {
                return self
                }

                return self / self.length()
                }

                func cross(_ vec: SCNVector3) -> SCNVector3 {
                return SCNVector3(self.y * vec.z - self.z * vec.y, self.z * vec.x - self.x * vec.z, self.x * vec.y - self.y * vec.x)
                }


                Hope it is helpful. If anyone know better solution please answer it.






                share|cite|improve this answer












                I have fixed issue with temporary solution still looking for a better one



                Issue is of wall. wall is flipped other side of camera when draw from right to left direction. I have figure it out by setting isDoubleSided = false and by applying a image as diffuse contents which has text and I can see that image is flipped itself.



                I have tried many things but this one helps me




                1. Normalize vector

                2. Find the cross between to SCNVectors

                3. If y > 0 I just swapped from and to Value


                Code



                    let normalizedTO = to.normalized()
                let normalizedFrom = from.normalized()
                let angleBetweenTwoVectors = normalizedTO.cross(normalizedFrom)

                var from = from
                var to = to
                if angleBetweenTwoVectors.y > 0 {
                let temp = from
                from = to
                to = temp
                }

                // Inside extension of SCNVector3
                func normalized() -> SCNVector3 {
                if self.length() == 0 {
                return self
                }

                return self / self.length()
                }

                func cross(_ vec: SCNVector3) -> SCNVector3 {
                return SCNVector3(self.y * vec.z - self.z * vec.y, self.z * vec.x - self.x * vec.z, self.x * vec.y - self.y * vec.x)
                }


                Hope it is helpful. If anyone know better solution please answer it.







                share|cite|improve this answer












                share|cite|improve this answer



                share|cite|improve this answer










                answered 2 days ago









                Prashant Tukadiya

                1013




                1013






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2997836%2fcreate-wall-3d-math-oriented-away-from-camera%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    AnyDesk - Fatal Program Failure

                    How to calibrate 16:9 built-in touch-screen to a 4:3 resolution?

                    QoS: MAC-Priority for clients behind a repeater