jiankang.yao Posted February 21, 2011 Share Posted February 21, 2011 our screen resolusion is 1280*768, when our charactor be placed in the center of the camera view everything seem to be ok, and the charactor face right(show as picture 1),but when we place the charactor to left view of the camera,it seem that the charactor face screen out(show as picture 2), there seem to be too much perspective. when we try to call camera.setPerspective(perspective(50.0f, 768.0f/1280.0f, 1.0f, 10000.0f)) the result look like this show as picture 3, why the aspect must set to be 1.0f buf not screenHeight/screenWidth. meanwhile this is our's fighter game demo.(https://developer.unigine.com/forum/topic/347-fighter-game-demo/) Link to comment
binstream Posted February 21, 2011 Share Posted February 21, 2011 camera.setPerspective(perspective(50.0f, 768.0f/1280.0f, 1.0f, 10000.0f)) I guess that you use the wrong aspect ratio, height/width instead of width/height, the correct version is: camera.setPerspective(perspective(50.0f, 1280.0f/768.0f, 1.0f, 10000.0f)) Link to comment
jiankang.yao Posted February 22, 2011 Author Share Posted February 22, 2011 if use camera.setPerspective(perspective(50.0f, 1280.0f/768.0f, 1.0f, 10000.0f)).the result will be like this. Link to comment
jiankang.yao Posted February 22, 2011 Author Share Posted February 22, 2011 it's seems that aspect must be 1.0f, if the appWidth/appHeight is 1.0, there is nothing wrong , but if not that will result in too much perspective,the big the value is the more perspective it will be. Link to comment
frustum Posted February 22, 2011 Share Posted February 22, 2011 Aspect ratio of projection matrix should be equal to 1.0f always. Render will scale projection matrix in depends of current viewport size. In case when you need some math based on projection matrix you should scale m00 component manually. This is a code from Unigine::getPlayerMouseDirection() function: float aspect = float(engine.app.getWidth()) / engine.app.getHeight(); float x = -(float(engine.app.getMouseX()) / engine.app.getWidth() * 2.0f - 1.0f) / projection.m00 * aspect; float y = (float(engine.app.getMouseY()) / engine.app.getHeight() * 2.0f - 1.0f) / projection.m11; Link to comment
jiankang.yao Posted February 23, 2011 Author Share Posted February 23, 2011 Aspect ratio of projection matrix should be equal to 1.0f always.Render will scale projection matrix in depends of current viewport size. thanks!but how could I resolve the problem of too much perspective under resolusion 1280 * 768. Link to comment
frustum Posted February 23, 2011 Share Posted February 23, 2011 We can't hide such artefacts entirely. We can reduce them by using more appropriate field of view. Your case is very specific and quality of picture is very important. So there is another way to reduce perspective distortion: Use WidgetSpriteViewport to render scene with size bigger than screen size. And after that this sprite should be rendered on main window with special post-processing shader which will compensate perspective distortion. Or you can play with projection matrix. Link to comment
Recommended Posts