Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

creator 2.0.1 worldToScreen求解 #3296

Closed
caochao opened this issue Sep 20, 2018 · 5 comments
Closed

creator 2.0.1 worldToScreen求解 #3296

caochao opened this issue Sep 20, 2018 · 5 comments
Assignees

Comments

@caochao
Copy link

caochao commented Sep 20, 2018

我们游戏cocos2dx版本用到了Camera做透视投影的近大远小效果,也用到了projectGL来计算屏幕坐标。目前我把游戏用creator改写的过程中由于自带的cocos2dx-lite移除了Camera,导致遇到一系列问题。

而我之前也有发帖提到过,我修改了cccamera的beforeDraw方法实现了针对节点N做透视投影。这次我想把节点N里的坐标C转化为屏幕坐标。
看到render-engine.js里有个worldToScreen方法,是把一个世界坐标乘以摄像机的视图和投影矩阵最终变化到视口坐标,应该和cocos2dx Camera里的projectGL方法是同样的作用。但是我调用这个方法无论传入什么世界坐标返回结果一直在ui设计尺寸的中心点左右, 设计尺寸是750*1334,返回结果一直近似于(375,667)。麻烦指点一下。
相关代码如下:
image
BattleCamera用来渲染PanelBattle。_temp_vec2是PanelBattle里一个点。
image
image
@pandamicro @jareguo

@caochao caochao changed the title creator 2.0.1哪个api对应cocos2dx中的projectGL方法? creator 2.0.1 worldToScreen求解 Sep 20, 2018
@caochao
Copy link
Author

caochao commented Sep 21, 2018

@pandamicro 空闲的时候帮忙看看

@caochao
Copy link
Author

caochao commented Sep 21, 2018

我发现问题了,render-engine.js worldToScree方法里先用vec3.transformMat4把世界坐标乘以视图投影矩阵,这个方法里已经将x,y坐标除以w做了一次透视除法得到裁剪坐标(这一步似乎不用除w)
image

接下来又将x,y做了除w操作。x, y除了2次w后变得非常小,所以返回值一直近似于设计尺寸一半。
image

@caochao
Copy link
Author

caochao commented Sep 21, 2018

image
我把实现改了一下,使用了vec4.transformMat4(这个方法里没有将x,y除w),所以没有问题。而且我这个改法,和cocos2dx Camera中projectGL方法功能应该是一致的
image

@Ander456
Copy link

额 ,没懂。老哥 意思是 官方的代码 这个 worldToScreen是有bug的么?

@zhefengzhang
Copy link
Contributor

2.1.1 版本 worldToScreen 已经修改
图片

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants