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 want
    
  • h0 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)的更多相关文章

  1. 3d世界是怎样呈现到屏幕上的

    要把一个3d物体呈现在屏幕上,要经过一系列的步骤. 描述3d世界 把3d世界绘制在二维屏幕上 如何描述一个3D世界? 数学家早就给出了3D世界的模型,我们日常最熟悉的3维坐标系就是一个欧几里得空间(线 ...

  2. IOS 特定于设备的开发:使用加速器启动屏幕上的对象

    借助一点编程工作,iPhone的机载加速计就可以使对象在屏幕上四处“移动”,实时响应用户倾斜手机的方式.下面的代码就是创建一个动画式的蝴蝶,用户可以使之快速移过屏幕. 使之工作的秘密在于:向程序中添加 ...

  3. [Xcode 实际操作]一、博主领进门-(2)第一个工程项目:将导入的图片显示到屏幕上

    目录:[Swift]Xcode实际操作 本文将演示创建第一个工程项目. 在项目导航区,鼠标右键[Assets.xcassets]资源文件夹. 隔壁右侧区域左下角点击[+],打开资源文件管理菜单-> ...

  4. 【Unity笔记】使物体(船)漂浮在水面上——浮力

    在官方论坛看到一个关于怎么使物体漂浮在水面上的讨论:https://forum.unity3d.com/threads/floating-a-object-on-water.31671/ 水动力系统 ...

  5. 【opengl】OpenGL中三维物体显示在二维屏幕上显示的变换过程

    转自:http://blog.sina.com.cn/s/blog_957b9fdb0100zesv.html 为了说明在三维物体到二维图象之间,需要经过什么样的变换,我们引入了相机(Camera)模 ...

  6. IOS UIView 01-View开始深入 绘制像素到屏幕上

    注:本人是翻译过来,并且加上本人的一点见解. 前言 一个像素是如何绘制到屏幕上去的?有很多种方式将一些东西映射到显示屏上,他们需要调用不同的框架.许多功能和方法的结合体.这里我们大概的看一下屏幕之后发 ...

  7. Unity3D之如何创建正确的像素比在屏幕上

    关于这篇文章的命名,实在不知道怎么命名好,大概功能就是:比如一张宽高为100x100的图片显示在屏幕上,那2D摄像头的Size值为多少时,屏幕上显示出来图片大小和图片的实际像素一致. 这里涉及到一个G ...

  8. UE4中如何使物体始终朝向摄像头?

    要使物体始终正面朝向摄像头需要用到一个关键节点:Find Look at Rotation 其中Start连接需要旋转的物体位置矢量,Target连接摄像头位置矢量 最后设置SetActorRotat ...

  9. iphone怎么投屏到电脑屏幕上

    随着苹果手机的更显换代,苹果手机的功能越来越强大,其中iphone手机更新了airplay镜像功能,所以想要手机投屏电脑的小伙伴就更加方便了,但是iphone怎么投屏到电脑呢?大家不用着急,下面即将为 ...

随机推荐

  1. android异步加载图片并缓存到本地实现方法

    图片过多造成内存溢出,这个是最不容易解决的,要想一些好的缓存策略,比如大图片使用LRU缓存策略或懒加载缓存策略.今天首先介绍一下本地缓存图片     在android项目中访问网络图片是非常普遍性的事 ...

  2. Andorid 编程 系统环境安装

    内网环境下安装: 1.配置源 :找到公司内部整理的源文件中的内容,将其内容拷贝到系统 源文件 中,并注释掉所有外网链接(如果公司支持内部环境配置,通常会有一个内部源文件)  2.安装jdk, ecli ...

  3. js编程-面相对象

    //js面相对象编程 //定义constructor构造方法 function myFn(name,sex){ this.name = name; this.sex = sex; } //用proto ...

  4. sp_sys_ERPTrigger_base

    USE [GalaxyPointDB24]GO/****** Object:  StoredProcedure [dbo].[sp_zy_Process_scrap]    Script Date: ...

  5. 如果在遨游浏览器里设置Bing(必应)搜索为默认搜索

    今天刚装了遨游浏览器,发现搜索引擎列表里没有Bing(必应)搜索的选项,就自己DIY了下. 步骤: 1. 在遨游搜索引擎列表管理里,添加一个新的搜索引擎项: Name:填写上”Bing(必应)“ (这 ...

  6. Reflection实现通用增删改

    新增 /// <summary> /// 通用新增方法 /// </summary> /// <param name="arr">一行数据封装的 ...

  7. 精通D3.js学习笔记(1)基础的函数

    买了本吕大师的d3可视化.最近来学习一下,做个笔记.   1.选择元素  select(第一元素) 和selectAll(全部的元素)      类似css的选择器.也可以是dom选中的. var i ...

  8. 2017年1月6日 星期五 --出埃及记 Exodus 21:32

    2017年1月6日 星期五 --出埃及记 Exodus 21:32 If the bull gores a male or female slave, the owner must pay thirt ...

  9. 2016年11月25日 星期五 --出埃及记 Exodus 20:16

    2016年11月25日 星期五 --出埃及记 Exodus 20:16 "You shall not give false testimony against your neighbor.不 ...

  10. flume ng之组件介绍

    1.channel 2.source 3.sink 4.直接读取文件Source,有哪两种方式? 5.Channel有几种方式? 6.Sink在设置存储数据时,数据较多,较少的情况下,该如何处理? F ...