首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在libgdx中设置观看三维模型的动态摄像机位置?

如何在libgdx中设置观看三维模型的动态摄像机位置?
EN

Stack Overflow用户
提问于 2016-01-15 07:08:48
回答 1查看 543关注 0票数 0

目前,我正试图在libgdx中制作简单的3d模型查看器。我只是好奇,如果我可以改变相机,以正确地查看三维模型。

//--三维模型部分

代码语言:javascript
复制
 Model smallCar= assets.get("data/small_car.obj", Model.class);//<--dynamic model
 ModelInstance smallCarInstance = new ModelInstance(smallCar);

我可以设定相机的静态位置,但我想根据汽车型号的大小来设置摄像机的位置,如下所示:

代码语言:javascript
复制
cam.position.set(1f, 1f, smallCar.getWidth()* 2f); //<--isn't available
cam.lookAt(0,0,0); 

相机的位置应该是动态的,这样它的位置就不会影响三维模型的视图。谢谢,

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-01-15 08:30:02

代码语言:javascript
复制
BoundingBox boundingBox = smallCarInstance.calculateBoundingBox(new BoundingBox());
float maxDistance = Float.max(Float.max(boundingBox.getWidth(), boundingBox.getHeight()), boundingBox.getDepth());
cam.position.set(0f, 0f, maxDistance * 2f);
cam.lookAt(0f, 0f, 0f);
cam.rotateAround(Vector3.Zero, Vector3.X, -30f);
cam.update();
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34805910

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档