当前位置: 首页 > news >正文

哇哈哈, 终于天上掉箱子了

基本步骤:

  1. 初始化SDK
  2. 创建场景, 设置重力
  3. 设置默认材质, 摩擦力系数之类的
  4. 创建一个地面
  5. 每次按Enter创建一个Box, 让它自己往下掉

主要的代码如下:

//------------------------------------------------------------------------------ void TestPhysXApp::OnProcessInput() { // TODO: add your input operation code here if (this->inputServer->GetDefaultKeyboard()->KeyDown(Input::Key::Return)) { NxBodyDesc bodyDesc; bodyDesc.angularDamping = 0.5f; NxBoxShapeDesc boxDesc; boxDesc.dimensions = NxVec3(0.5f, 0.5f, 0.5f); NxActorDesc actorDesc; actorDesc.shapes.pushBack(&boxDesc); actorDesc.body = &bodyDesc; actorDesc.density = 10.0f; actorDesc.globalPose.t = NxVec3(0.0f, 10.0f, 0.0f); this->colors.Append(this->GetRandomColor()); this->nxScene->createActor(actorDesc)->userData = (void*)(this->colors.Size() - 1); } ViewerApplication::OnProcessInput(); } //------------------------------------------------------------------------------ void TestPhysXApp::OnUpdateFrame() { // simulation float frameTime = (float)this->GetFrameTime(); this->nxScene->simulate(frameTime); float curTime = (float) this->GetTime(); // draw ground const float period = 3.0f; float now = float(curTime - int(curTime / period) * period - period * 0.5f); scalar s = n_abs(now / (period * 0.5f)); float4 color = float4::lerp(float4(1, 0, 0, 1), float4(0, 1, 0, 1), s); matrix44 transform = matrix44::identity(); transform.translate(float4(0, -1, 0, 0)); transform.scale(float4(100, 1, 100, 1)); DebugShapeRenderer::Instance()->DrawBox(transform, color); // draw boxes NxActor** actors = this->nxScene->getActors(); SizeT numActors = this->nxScene->getNbActors(); for (IndexT i = 1; i < numActors; ++i) { NxActor* actor = actors[i]; actor->getGlobalPose().getColumnMajor44((float*)&transform); IndexT colorIndex = (IndexT)actor->userData; DebugShapeRenderer::Instance()->DrawBox(transform, this->colors[colorIndex]); } ViewerApplication::OnUpdateFrame(); // fetch simulation results this->nxScene->flushStream(); this->nxScene->fetchResults(NX_RIGID_BODY_FINISHED, true); } //------------------------------------------------------------------------------ void TestPhysXApp::InitNx() { // intialize sdk NxPhysicsSDKDesc desc; this->nxSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, NULL, NULL, desc); this->nxSDK->setParameter(NX_SKIN_WIDTH, 0.05f); n_assert(NULL != this->nxSDK); // create scene NxSceneDesc sceneDesc; sceneDesc.gravity = NxVec3(0.0f, -9.8f, 0.0f); this->nxScene = this->nxSDK->createScene(sceneDesc); n_assert(NULL != this->nxScene); // set default material NxMaterial* defaultMaterial = this->nxScene->getMaterialFromIndex(0); defaultMaterial->setRestitution(0.0f); defaultMaterial->setStaticFriction(0.5f); defaultMaterial->setDynamicFriction(0.5f); // create ground plane NxPlaneShapeDesc planeDesc; NxActorDesc actorDesc; actorDesc.shapes.pushBack(&planeDesc); this->nxScene->createActor(actorDesc); } //------------------------------------------------------------------------------ float4 TestPhysXApp::GetRandomColor() const { float r = n_rand(0.0f, 1.0f); float g = n_rand(0.0f, 1.0f); float b = n_rand(0.0f, 1.0f); return float4(r, g, b, 1.0f); }

相关文章:

  • WEB常用iptables规则
  • 我常用的Linux设置
  • 免安装Oracle客户端使用PL/SQL连接Linux Oracle 注意事项
  • CLI PHP WebSocket服务器
  • Nginx 自带防盗链模块
  • 在MTK中添加TASK与常用函数分析
  • 大数据时代必不可少的大数据分析和制作工具大全
  • SubVersion服务器Windows安装指南
  • CentOS里ifcfg的device指的是什么?
  • SQLServer2005批量查询自定义对象脚本
  • 使用Let's encrypt保护你的网络通信
  • SQLServer中求两个字符串的交集
  • 139说客的优势和局限性
  • phpjm php加密的解密过程
  • 被遗忘的SQLServer比较运算符修饰词
  • [译]CSS 居中(Center)方法大合集
  • 【腾讯Bugly干货分享】从0到1打造直播 App
  • Android优雅地处理按钮重复点击
  • co模块的前端实现
  • gcc介绍及安装
  • java小心机(3)| 浅析finalize()
  • magento 货币换算
  • mysql innodb 索引使用指南
  • Spring Cloud Feign的两种使用姿势
  • Vue2 SSR 的优化之旅
  • 初识 beanstalkd
  • 从tcpdump抓包看TCP/IP协议
  • 聊聊sentinel的DegradeSlot
  • 前端js -- this指向总结。
  • 如何实现 font-size 的响应式
  • 如何选择开源的机器学习框架?
  • 通过获取异步加载JS文件进度实现一个canvas环形loading图
  • postgresql行列转换函数
  • 带你开发类似Pokemon Go的AR游戏
  • 你学不懂C语言,是因为不懂编写C程序的7个步骤 ...
  • ​queue --- 一个同步的队列类​
  • ​香农与信息论三大定律
  • #{}和${}的区别?
  • #1015 : KMP算法
  • #FPGA(基础知识)
  • #if和#ifdef区别
  • #常见电池型号介绍 常见电池尺寸是多少【详解】
  • $emit传递多个参数_PPC和MIPS指令集下二进制代码中函数参数个数的识别方法
  • (1)常见O(n^2)排序算法解析
  • (java版)排序算法----【冒泡,选择,插入,希尔,快速排序,归并排序,基数排序】超详细~~
  • (八)Flask之app.route装饰器函数的参数
  • (笔试题)合法字符串
  • (附源码)计算机毕业设计ssm本地美食推荐平台
  • (转)jQuery 基础
  • .NET Core引入性能分析引导优化
  • .NET MVC 验证码
  • .NET 设计模式—简单工厂(Simple Factory Pattern)
  • .NET/ASP.NETMVC 大型站点架构设计—迁移Model元数据设置项(自定义元数据提供程序)...
  • .NET文档生成工具ADB使用图文教程
  • @Async注解的坑,小心