如何定位摄像机,使物体在屏幕上始终具有相同的像素宽度和高度?(threes)
from How to position the camera so that the object always has the same pixel width and height on the screen?
in your case is more likely dependent on the smaller window size axis !!!
- because aspect ratio equations usually differs
- for width > height and width < height
- most renders have taken this behaviour from OpenGL
- so may be your code needs adding one if to be complete :)
- to be sure just resize your window to be bigger in height then width and see what happens
btw. the math behind is just simple triangle math

- one angle = 90 deg
second is atan (h1/z1) = atan (h0/z0)
h1/z1 = h0/z0 <- triangle similarity z1 = z0*h1/h0 <- this is what you wanth0 is your half size in control axis (x or y)
- h1 is half cube size
- z0 is near plane of your frustrum
- z1 is cube position (do not forget to add the offset to center of cube)
- so cube center position is: z1' = (z0*h1/h0)+h1
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
http://stackoverflow.com/questions/15331358/three-js-get-object-size-with-respect-to-camera-and-object-position-on-screen
I am newbie to 3D programming, I did started to explore the 3D world from WebGL with Three.JS.
I want to predetermine object size while i change the camera.position.z and object "Z" position.
For example: i have a cube mesh at size of 100x100x100.
cube = new THREE.Mesh(
new THREE.CubeGeometry(100, 100, 100, 1,1,1, materials),
new THREE.MeshFaceMaterial()
);
and cam with aspect ratio of 1.8311874
camera = new THREE.PerspectiveCamera( 45, aspect_ration, 1, 30000 );
I want to know size (2D width & height) of that cube object on screen when,
camera.position.z = 750;
cube.position.z = 500;
Is there is any way to find/predetermine it?
You can compute the visible height for a given distance from the camera using the formulas explained in Three.js - Width of view.
var vFOV = camera.fov * Math.PI / 180; // convert vertical fov to radians
var height = 2 * Math.tan( vFOV / 2 ) * dist; // visible height
In your case the camera FOV is 45 degrees, so
vFOV = PI/4.
(Note: in three.js the camera field-of-view FOV is the vertical one, not the horizontal one.)
The distance from the camera to the front face (important!) of the cube is 750 - 500 - 50 = 200. Therefore, the visible height in your case is
height = 2 * tan( PI/8 ) * 200 = 165.69.
Since the front face of the cube is 100 x 100, the fraction of the visible height represented by the cube is
fraction = 100 / 165.69 = 0.60.
So if you know the canvas height in pixels, then the height of the cube in pixels is 0.60 times that value.
The link I provided shows how to compute the visible width, so you can do that calculation in a similar fashion if you need it.
如何定位摄像机,使物体在屏幕上始终具有相同的像素宽度和高度?(threes)的更多相关文章
- 3d世界是怎样呈现到屏幕上的
要把一个3d物体呈现在屏幕上,要经过一系列的步骤. 描述3d世界 把3d世界绘制在二维屏幕上 如何描述一个3D世界? 数学家早就给出了3D世界的模型,我们日常最熟悉的3维坐标系就是一个欧几里得空间(线 ...
- IOS 特定于设备的开发:使用加速器启动屏幕上的对象
借助一点编程工作,iPhone的机载加速计就可以使对象在屏幕上四处“移动”,实时响应用户倾斜手机的方式.下面的代码就是创建一个动画式的蝴蝶,用户可以使之快速移过屏幕. 使之工作的秘密在于:向程序中添加 ...
- [Xcode 实际操作]一、博主领进门-(2)第一个工程项目:将导入的图片显示到屏幕上
目录:[Swift]Xcode实际操作 本文将演示创建第一个工程项目. 在项目导航区,鼠标右键[Assets.xcassets]资源文件夹. 隔壁右侧区域左下角点击[+],打开资源文件管理菜单-> ...
- 【Unity笔记】使物体(船)漂浮在水面上——浮力
在官方论坛看到一个关于怎么使物体漂浮在水面上的讨论:https://forum.unity3d.com/threads/floating-a-object-on-water.31671/ 水动力系统 ...
- 【opengl】OpenGL中三维物体显示在二维屏幕上显示的变换过程
转自:http://blog.sina.com.cn/s/blog_957b9fdb0100zesv.html 为了说明在三维物体到二维图象之间,需要经过什么样的变换,我们引入了相机(Camera)模 ...
- IOS UIView 01-View开始深入 绘制像素到屏幕上
注:本人是翻译过来,并且加上本人的一点见解. 前言 一个像素是如何绘制到屏幕上去的?有很多种方式将一些东西映射到显示屏上,他们需要调用不同的框架.许多功能和方法的结合体.这里我们大概的看一下屏幕之后发 ...
- Unity3D之如何创建正确的像素比在屏幕上
关于这篇文章的命名,实在不知道怎么命名好,大概功能就是:比如一张宽高为100x100的图片显示在屏幕上,那2D摄像头的Size值为多少时,屏幕上显示出来图片大小和图片的实际像素一致. 这里涉及到一个G ...
- UE4中如何使物体始终朝向摄像头?
要使物体始终正面朝向摄像头需要用到一个关键节点:Find Look at Rotation 其中Start连接需要旋转的物体位置矢量,Target连接摄像头位置矢量 最后设置SetActorRotat ...
- iphone怎么投屏到电脑屏幕上
随着苹果手机的更显换代,苹果手机的功能越来越强大,其中iphone手机更新了airplay镜像功能,所以想要手机投屏电脑的小伙伴就更加方便了,但是iphone怎么投屏到电脑呢?大家不用着急,下面即将为 ...
随机推荐
- HDU 4715:Difference Between Primes
Difference Between Primes Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Jav ...
- Winform知识点
Winform窗体常用的控件 1.按钮 Button 前缀:btn 2.文本框 TextBox 前缀:txt 3.单选按钮 RadioButton 前缀:rdo 4.复选按钮 CheckBox 前缀: ...
- Unity GUI内绘制贝塞尔曲线
用Handles可以直接在GUI下绘制贝塞尔 using UnityEditor; using UnityEngine; using System.Collections; public class ...
- Unity安卓上播放视频的问题,暂时无解记录一下
设备联想A7600m,好像是联发科的cpu 先用网上流传很广的这个Unity自带接口试验一下: Handheld.PlayFullScreenMovie(Path.Combine(Applicatio ...
- drivers/mfd/Mfd-core.c
mfd: multifunction device drivers---多功能设备驱动开发:A product or device that has multiple functions. An ex ...
- XMLHttpRequest 2.0与FileReader接口的方法
jsonpd的实现: var jsonp = function (options) { var url = options.url, params = options.params || {}, ca ...
- Android Handler Message总结
http://blog.csdn.net/caesardadi/article/details/8473777 当应用程序启动时,会开启一个主线程(也就是UI线程),由她来管理UI,监听用户点击,来响 ...
- ios沙盒路径
http://www.cnblogs.com/ios-wmm/p/3299695.html iOS沙盒路径的查看和使用 NSString *path = NSHomeDirectory();//主目录 ...
- Java——再看IO
一.编码问题 utf-8编码中,一个中文占3个字节,一个英文占1个字节:gbk编码中,一个中文占2个字节,一个英文占1个字节. Java是双字节编码,为utf-16be编码,是说一个字符(无论中文还是 ...
- 超强vim配置
在网上找vim的配置,自己配置的特别丑 安装起来也超级方便. #!/bin/bash echo "安装将花费一定时间,请耐心等待直到安装完成^_^" if which apt-ge ...