Download

Online

Gallery

Blog

  Index  | Recent Threads  | List Attachments  | Search
 Welcome Guest  |  Register  |  Login
Login Name  Password
 

Sweet Home 3D Forum



No member browsing this thread
Thread Status: Active
Total posts in this thread: 13
Posts: 13   Pages: 2   [ Previous Page | 1 2 ]
[ Jump to Last Post ]
Post new Thread
Author
Previous Thread This topic has been viewed 829 times and has 12 replies Next Thread
shmuelzon
Newbie



Israel
Joined: Dec 24, 2023
Post Count: 7
Status: Offline
Reply to this Post  Reply with Quote 
Re: Mapping Floor Plan Coordinates to Render/3DView Coordiantes

If I'm not mistaken, that code is only the transformation part, i.e., move the target object to the coordinate system of the camera, but the projection itself is done as a part of the renderer's internal code as SH3D provides the lens type, FOV, aspect ratio, etc.
I didn't see the perspective projection part in both renderers but maybe I missed it...
[Jan 13, 2024, 8:00:55 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Daniels118
Advanced Member
Member's Avatar

Italy
Joined: Nov 17, 2021
Post Count: 407
Status: Offline
Reply to this Post  Reply with Quote 
Re: Mapping Floor Plan Coordinates to Render/3DView Coordiantes

Whops, seems you're right... this tells how to compute the projection matrix:
https://gamedev.stackexchange.com/questions/1...atrix-look-like-in-opengl
But you don't need to do it by hand, because Java3D has a ready made mathod for this:
https://download.java.net/media/java3d/javado...ouble,%20double,%20double)
Java3D is embedded in SH3D installation, so you just need to add it to your build path, you don't need to embed it in your plugin.
[Jan 13, 2024, 11:20:36 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
shmuelzon
Newbie



Israel
Joined: Dec 24, 2023
Post Count: 7
Status: Offline
Reply to this Post  Reply with Quote 
Re: Mapping Floor Plan Coordinates to Render/3DView Coordiantes

I finally got it to work, thanks Daniele!

For future reference, if anyone will stumble upon this post, here's what I ended up with:
int renderWidth = 1024;
int renderHeight = 576;

/* Set up */
Camera camera = getHome().getCamera();
cameraPosition = new Vector4d(camera.getX(), camera.getZ(), camera.getY(), 0);

Transform3D yawRotation = new Transform3D();
yawRotation.rotY(camera.getYaw());

Transform3D pitchRotation = new Transform3D();
pitchRotation.rotX(-camera.getPitch());

Transform3D perspectiveTransform = new Transform3D();
perspectiveTransform.perspective(camera.getFieldOfView(), (double)renderWidth / renderHeight, 0.1, 100);
perspectiveTransform.mul(pitchRotation);
perspectiveTransform.mul(yawRotation);

HomePieceOfFurniture furniture = /* Get some furniture... */;
Vector4d objectPosition = new Vector4d(furniture.getX(), furniture.getElevation(), furniture.getY(), 0);

objectPosition.sub(cameraPosition);
perspectiveTransform.transform(objectPosition);
objectPosition.scale(1 / objectPosition.w);

System.out.println(String.format("Projected pixel: (%d, %d)",
(int)((objectPosition.x * 0.5 + 0.5) * renderWidth),
(int)((objectPosition.y * 0.5 + 0.5) * renderHeight)
));

[Jan 15, 2024, 5:59:32 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Posts: 13   Pages: 2   [ Previous Page | 1 2 ]
[ Jump to Last Post ]
Show Printable Version of Thread  Post new Thread

    Get Sweet Home 3D at SourceForge.net. Fast, secure and Free Open Source software downloads
   
© Copyright 2006-2024 eTeks - All rights reserved