Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by mbhdra · Jul 24, 2019 at 01:27 PM · vrworldspacescreenspaceworldtoscreenpoint

WorldToScreenPoint does not work as expected!

Hello,

I get world positions of gaze points that are tracked by Tobii Pro VR Eye Tracker. I assign these positions to a game object called sphere (blue circles on the screenshots). After that I get screen positions of these world points by WorldToScreenPoint method. I screenshot of current frame by ScreenCapture.CaptureScreenshot method. Finally, I want to mark these gaze points on my screenshot by using the x and y pixel positions that I got from WorldToScreenPoint method (white circles on the screenshots). However, as you can see in the screenshots attached, I am not able to mark blue spheres by white spheres. They don't overlap. They tend to overlap when blue sphere is near to the center. But as it goes to the up, down, right or left, white sphere does not slip as much as the blue sphere does. I tried it with the camera in both perpective and orthographic modes Screen width is 1512 and screen height is 1680 and they are same with the VR height and width. I have been in stuck at that point for days. I look forward you to help me. Related screenshots are attached.

Screenshots: https://imgur.com/SESpUnc https://imgur.com/nzSTzQ0 https://imgur.com/4D9meJm https://imgur.com/EGIKuTn https://imgur.com/Bynbrzs

Code part to convert world position to screen position:

 _spherePos = _sphere.transform.position;
 x3 = _spherePos.x;
  y3 = _spherePos.y;
 z3 = _spherePos.z;                    
 Vector3 _gazePos = cam.WorldToScreenPoint(_spherePos, Camera.MonoOrStereoscopicEye.Right);
 x2 = _gazePos.x;
 y2 = _gazePos.y;
 z2 = _gazePos.z;

Code part to take screenshot and mark white points:

 Texture2D texture = new Texture2D(1512, 1680);
 texture = ScreenCapture.CaptureScreenshotAsTexture(ScreenCapture.StereoScreenCaptureMode.RightEye);
 Circle(texture, (int)Mathf.Ceil(x2), (int)Mathf.Ceil(y2), 15, Color.white);
 _bytes = texture.EncodeToJPG();
 System.IO.File.WriteAllBytes("screenshots\\" + cc.ToString() + "asd" + x1.ToString() + "_" + y1.ToString() + "_" + z1.ToString() + "_" + x3.ToString() + "_" + y3.ToString() + "_" + z3.ToString() + "_.jpg", _bytes);

Circle method to draw the white circle:

 void Circle(Texture2D tex, int cx, int cy, int r, Color col)
         {
             int x, y, px, nx, py, ny, d;
 
             for (x = 0; x <= r; x++)
             {
                 d = (int)Mathf.Ceil(Mathf.Sqrt(r * r - x * x));
                 for (y = 0; y <= d; y++)
                 {
                     px = cx + x;
                     nx = cx - x;
                     py = cy + y;
                     ny = cy - y;
 
                     tex.SetPixel(px, py, col);
                     tex.SetPixel(nx, py, col);
 
                     tex.SetPixel(px, ny, col);
                     tex.SetPixel(nx, ny, col);
 
                 }
             }
         }
 

Thanks.

alt text

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

206 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to convert the world co-ordinate to the co-ordinates that I can use on screen? 2 Answers

What is the matrix equivalent to Camera.WorldToScreenPoint? 1 Answer

c# RTS style snapping of game objects 0 Answers

Take XYZ of GameObject and convert that to canvas co-ordinates? 0 Answers

draw canvas/2D space Box Colliders on top of 3D objects that are located in world space? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges