I am working on a game project where I am using both 2D and 3D objects in the game scene, but I am unable to map 2D coordinates with 3D coordinates. How to convert 3D spaceNode to 2D spaceNode, in addition how can we get width and height of the 3D object, So I can manage the 2D sprites accordingly?
Thanks.
This question is a bit confusing, 3D is basically 2D with an extra dimension (Z-axis), there’s no conversion necessary? All 2D assets should of a Z value of 0. Assuming 3D projection.
For width and height, try creating a bounding box and getting the width and height of that.
It’s a bit more complicated than just the Z-axis. I’m assuming Bhavya wants to know how to map the 3d objects against the 2D plane, taking into account the frustum perspective (or the other way round), i.e. this sort of thing http://www.scratchapixel.com/lessons/3d-basic-rendering/computing-pixel-coordinates-of-3d-point
Matrices do my head in though, and I haven’t tried cocos2d-x v3 yet, so can’t really help much more than try and help clarify the question…
When We position a Sprite3D in cocos2dx with ZPosition = 0 then the visibility of Sprite3D is really small in that case. we come up a solution to make it large we get the zEye co-ordinate and place the 3D object in the Scene. So the Zposition changes all values for xPosition , yPosition and Height and Width visually not practically. just want to know that what zPosition will make the 2D and 3D look same.
Ahh I know what you mean now. Yes I imagine it would be something like reverse the effects of 3D projection and then apply 2D projection. Or something like that. There is probably a few good tutorials online.
3D->2D
camera->project()/camera->projectGL. This can project a world position to screen position (screen space or OpenGL space).
When z of Sprite3D is 0 and you are using default camera. The position XY is screen position and sprite3d->getBoundingBox is the correct 2D bounding box.
2D->3D
camera->unProject/unProjectGL. You should specify the z. As you know that you can get multiple 3D position given a 2D position.