Print at Dec 16, 2025, 2:27:02 PM
Posts: 13   Pages: 2   [ Previous Page | 1 2 ]
View all posts in this thread on one page
Posted by shmuelzon at Jan 13, 2024, 8:00:55 PM
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...

Posted by Daniels118 at Jan 13, 2024, 11:20:36 PM
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.

Posted by shmuelzon at Jan 15, 2024, 5:59:32 PM
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)
));


Posts: 13   Pages: 2   [ Previous Page | 1 2 ]