当前位置:网站首页>微信小程序中three.js的canvas非全屏情况下射线检测不准确问题解决方案
微信小程序中three.js的canvas非全屏情况下射线检测不准确问题解决方案
2022-06-23 22:18:00 【Zmikoo成长之路】
全屏情况下的射线检测函数一般是这样写的:
function onTouchstart(event) {
var touch = event.touches[0];
if (!touch) return;
let mousePosition = new THREE.Vector2();
mousePosition.x = (touch.x / wx.getSystemInfoSync().windowWidth) * 2 - 1;
mousePosition.y = -(touch.y / wx.getSystemInfoSync().windowHeight) * 2 + 1;
var raycaster = new THREE.Raycaster();
raycaster.setFromCamera(mousePosition, camera);
let intersects = raycaster.intersectObjects(scene.children,true);
if (intersects.length > 0) {
console.log("检测到 ==", intersects[0].object);
if (INTERSECTED != intersects[0].object) {
if (INTERSECTED) INTERSECTED = intersects[0].object;
return intersects[0].object;
}
} else {
if (INTERSECTED)
INTERSECTED.material.emissive.setHex(INTERSECTED.currentHex);
INTERSECTED = null;
}
}
当canvas非全屏时写法:
var canvasInfo;
let query = wx.createSelectorQuery();
query.select('#webgl').boundingClientRect((res) => {
canvasInfo = res;
}).exec();
function onTouchstart(event) {
var touch = event.touches[0];
if (!touch) return;
let mousePosition = new THREE.Vector2();
mousePosition.x = (touch.x / canvasInfo.width) * 2 - 1;
mousePosition.y = -(touch.y / canvasInfo.height) * 2 + 1;
var raycaster = new THREE.Raycaster();
raycaster.setFromCamera(mousePosition, camera);
let intersects = raycaster.intersectObjects(scene.children, true);
if (intersects.length > 0) {
console.log("检测到 ==", intersects[0].object.userData.name);
if (INTERSECTED != intersects[0].object) {
if (INTERSECTED) INTERSECTED = intersects[0].object;
return intersects[0].object;
}
} else {
if (INTERSECTED)
INTERSECTED.material.emissive.setHex(INTERSECTED.currentHex);
INTERSECTED = null;
}
}
边栏推荐
- [things about gbase] gbase 8s high availability technology and case analysis (issue 02)
- 7、STM32——LCD
- Loop caused by add of sublist in list
- docker redis集群配置
- Three types of transactions in EF core (saveChanges, dbcontexttransaction, transactionscope)
- 2018/GAN:Self-Attention Generative Adversarial Networks自我注意生成对抗网络
- Flux in three dimensional vector field
- 点乘和叉乘
- 《德阳市餐饮服务业油烟污染防治管理办法(征求意见稿)》之创新油烟监管
- 2022 information security engineer examination knowledge point: access control
猜你喜欢

2022山东健博会,济南国际大健康产业博览会,中国营养健康展

Generative countermeasure networks (Gans) and variants
![复原IP地址[标准回溯+标准剪枝]](/img/e6/5f9d2a5af973b6c7051ed434a4b93d.png)
复原IP地址[标准回溯+标准剪枝]
![组合总数II[每个元素只能用一次 + 去重复解集]](/img/06/a40e28a1882a4278883202bc9c72d3.png)
组合总数II[每个元素只能用一次 + 去重复解集]

docker redis集群配置

一个人竟然撸了一个网易云音乐云村

生成所有可能的二叉搜索树

数字物业管理成趋势,传统物业公司如何通过转型实现数字化蝶变?

Gbase observation: extended analytical database

Goodbye, 2020, this bowl of poisonous chicken soup, I'll dry it first
随机推荐
docker redis集群配置
A person even ran a Weibo app
[proteus simulation] example of T6963C driving pg12864 (with Chinese and English display)
AUTOCAD——总结CAD画圆角的三种方式
Setting method of bar code local segment data variable
Cvpr2019/ image translation: transgaga: geometry aware unsupervised image to image translation
Tupu software intelligent wind power: operation and maintenance of digital twin 3D wind turbine intelligent equipment
牛客网:接雨水的双指针问题
冶金行业数字化供应链管理系统:平台精益化企业管理,助力产业高质量发展
Different objects use the same material and have different performances
Revit API:明细表 ViewSchedule
Stm32----- timer
2022 information security engineer examination knowledge point: access control
BroadcastReciver 和LocalBroadcastManager区别
WPF效果之Expander+ListBox
Restore IP address [standard backtracking + standard pruning]
Quelques fonctions d'outils couramment utilisées au travail
《德阳市餐饮服务业油烟污染防治管理办法(征求意见稿)》之创新油烟监管
How to take the PMP Exam agile on June 25? Share your troubles
Golang type assertion