物件的边缘高亮(Entity edge highlight)

本文探讨了在游戏中实现NPC边缘高亮显示的技术方案,以便玩家能清晰地识别并选择目标NPC。通过调整绘制顺序及深度写入状态,能够简单有效地达到预期效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原文出处:http://www.cppblog.com/lai3d/archive/2007/11/18/36899.html

在游戏里面鼠标与某个npc相交了后,就让npc的边缘高亮显示或者怎么处理下,让玩家很明确地知道他点下去就能选中此npc。《卓越之剑》有这效果。google了下没找到相关资料。

我在gamedev上的提问:
when the cursor is over an entity, I want to highlight it's edge so that a player can immediately know he can pick this entity after he click the mouse left button. for example, there are many monsters around the main character in the game, it is not easy to pick one monster. I googled this, but found nothing. who can give me some suggestion?


老外的回答:
The simplest method is to draw the object colored in the highlight color, with some scaling to make it larger than the original object. Do this drawing with depth writes turned off. Then, after this, draw the object as usual, with depth writes on again. There are more complex methods, depending on your application - depending on what is your bottleneck, depending on complexity of your monster models etc etc. but the method above is simple to implement and should work for most cases.

### 实现 Cesium 中 Entity Model 的高亮显示 为了实现在 Cesium 中选中实体模型后的高亮效果,可以采用两种主要方法: #### 方法一:通过修改模型颜色实现高亮 当用户点击或选择特定的 `Entity` 对象时,可以通过改变该对象的颜色来进行视觉上的强调。这通常涉及到获取目标 `Entity` 并调整其 `model.color` 属性。 ```javascript // 假设已有一个 viewer 和被点击的对象 pickedObject if (Cesium.defined(pickedObject.id)) { let entity = pickedObject.id; if (entity && entity.model) { // 设置新的颜色用于高亮 entity.model.color = Cesium.Color.YELLOW.withAlpha(0.8); } } ``` 要恢复原始状态,则需重置此属性至默认透明度或其他初始设定[^2]。 #### 方法二:利用材质叠加技术增强表现力 另一种更灵活的方式是在原有基础上增加额外的一层半透明色彩作为覆盖物,而不是直接更改模型本身的色调。这种方法能够保留原貌的同时提供清晰可见的选择指示。 ```javascript function highlightModel(entity, color=Cesium.Color.RED.withAlpha(0.5)){ var originalColor = entity.model.color.clone(); function restoreOriginal(){ entity.model.color = originalColor; } // 添加一个回调函数以便稍后移除高亮 setTimeout(function(){restoreOriginal()}, 3000); // 应用新颜色进行短暂时间内的高亮展示 entity.model.color = color; } highlightModel(selectedEntity); ``` 上述代码片段展示了如何定义并应用临时性的高亮样式,并设置了三秒延迟自动撤销的功能[^1]。 对于希望进一步优化用户体验的应用程序来说,还可以考虑结合其他交互特性如工具提示、边框加粗等手段共同作用于所选元素之上。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值