当前位置:网站首页>shader学习笔记(五)
shader学习笔记(五)
2022-08-09 22:05:00 【守着黎明看日出】
使物体动起来
1.移动角色
顶点着色器不修改网格数据,而是通过修改物体顶点将绘制到屏幕上的位置来移动物体。现使用按键的按下和抬起状态控制角色的移动和停止。
需要注意的是draw是执行渲染逻辑的地方,每一帧需要发生但与创建绘制没用直接关系的逻辑应该放在update函数中。
ofGetLastFrameTime()函数返回从上一帧开始到此帧所经过的时间量。
ofAPP.cpp代码
void ofApp::keyPressed(int key){
if (key == ofKey::OF_KEY_F5)
{
isMove = true;
}
}
void ofApp::keyReleased(int key){
if (key == ofKey::OF_KEY_F5)
{
isMove = false;
}
}
void ofApp::update(){
if (isMove) {
float speed = 0.4*ofGetLastFrameTime();
charPos += glm::vec3(speed,0,0);
}
}
void ofApp::draw(){
//该方法省略了其他代码,仅显示修改部分
spriteshader.begin();
spriteshader.setUniformTexture("alienTex", img, 1);
spriteshader.setUniform2f("offset", spriteFrame);
spriteshader.setUniform2f("size", spriteSize);
spriteshader.setUniform3f("walk", charPos);
quad.draw();
spriteshader.end();
边栏推荐
- MySQL——JDBC
- Transfer Learning & Kemin Initialization
- 华为云全流程护航《流浪方舟》破竹首发,打造口碑爆款
- CV复习:softmax代码实现
- 【技术分享】SLA(服务等级协议)原理与配置
- 关于ETL的两种架构(ETL架构和ELT架构)
- 反射机制篇
- leetcode brush questions diary Calculate the number of elements on the right that is less than the current element
- NodeJS使用JWT
- 【LaTex】 Font “FandolSong-Regular“ does not contain requested(fontspec)Script “CJK“.如何抑制此种警告?
猜你喜欢
十步以内,用小程序快速生成App!
Jinshanyun earthquake, the epicenter is in bytes?
每日一R「02」所有权与 Move 语义
CV复习:softmax代码实现
[Microservice~Nacos] Configuration Center of Nacos
(转)FreeType字体位图属性
Flask's routing (app.route) detailed
【TS技术课堂】时间序列预测
Liver all night to write a thirty thousand - word all the commands the SQL database, function, speaks clearly explain operators, content is rich, proposal collection + 3 even high praise!
阿里云架构师金云龙:基于云XR平台的视觉计算应用部署
随机推荐
Interviewer: How to deal with Redis big key?
数字与中文大写数字互转(5千万亿亿亿亿以上的数字也支持转换)
Sun Zhengyi lost 150 billion: it was expensive at the beginning
Tencent continues to wield the "big knife" to reduce costs and increase efficiency, and free catering benefits for outsourced employees have been cut
c:forEach varStatus属性
CV复习:softmax代码实现
One Pass 2074: [21CSPJ Popularization Group] Candy
2022-8-9 第六组 输入输出流
学习编程的第十二天
Qt 消息机制和事件
A. Common Prefixes
three.js镂空圆球拖拽变形js特效
信息系统项目管理师---第十一章项目风险管理历年考题
2022年中国第三方证券APP创新专题分析
leetcode brush questions diary Calculate the number of elements on the right that is less than the current element
Users should clearly know that quantitative trading is not a simple procedure
【软考 系统架构设计师】案例分析⑤ 质量属性和架构评估
leetcode:323. 无向图中连通分量的数目
Socket发送缓冲区接收缓冲区快问快答
[WeChat applet development (8)] Summary of audio background music playback problems