当前位置:网站首页>Three Solution to the problem of inaccuracy in radiographic testing under the condition of non full screen canvas of JS
Three Solution to the problem of inaccuracy in radiographic testing under the condition of non full screen canvas of JS
2022-06-24 00:01:00 【Zmikoo's growth path】
The radiographic detection function in the case of full screen is generally written as follows :
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(" detected ==", 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;
}
}
When canvas Non full screen writing :
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(" detected ==", 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;
}
}
边栏推荐
- Interpreting the "four thoughts" of Wal Mart China President on the transformation and upgrading of physical retail
- Total number of combinations ii[each element can only be solved by + once]
- How to use data warehouse to create time series
- [bug] the element in C iqueryable cannot change its value
- Embedded interface review materials
- 合成大西瓜小游戏微信小程序源码/微信游戏小程序源码
- Six complete open source projects, learning enough at a time
- [interview experience package] summary of experience of being hanged during interview (I)
- Notepad++实用功能分享(正则行尾行首替换常用方法、文本比对功能等)
- Unity Text组件空格换行问题
猜你喜欢

PMP考试相关计算公式汇总!考前必看

Digital property management has become a trend. How can traditional property companies achieve digital butterfly change through transformation?

Complete open source project poetry bar app

医疗是什么?AI医疗概念解析AI

This high imitation millet mall project is amazing

为实现“双碳”目标,应如何实现节能、合理的照明管控

电子元器件行业B2B交易管理系统:提升数据化驱动能力,促进企业销售业绩增长

Niuke.com: the double pointer problem of receiving rainwater

老龄化下背景下,综合能效管理平台为医院保驾护航

Inftnews | where should the future of the creator economy go in the Web3 world?
随机推荐
Six complete open source projects, learning enough at a time
log Network Execution Time
Quelques fonctions d'outils couramment utilisées au travail
Application of acrel-3000web power management system in Duba Expressway
被同事坑到周末加班, 没见过把Redis用成这个鬼样子的。。。
APP性能优化之启动流程分析
Restore IP address [standard backtracking + standard pruning]
Facebook open source shimmer effect
Chaos engineering, learn about it
Thinking (87): Protocol encryption and compression
[technical grass planting] use the shared image function to realize the offline switching from CVM to LH
What is the same origin policy?
Generative countermeasure networks (Gans) and variants
重载(Overload)和重写(Override)的区别?
合成大西瓜小游戏微信小程序源码/微信游戏小程序源码
不同物体使用同一材质,有不同的表现
解决项目依赖报红问题
GBASE观察:扩展分析型数据库
Don't miss | Huawei's internal data - Successful Project Management PPT (page 123)
Setting method of bar code local segment data variable