2022年3月9日 星期三

今天天氣晴 3/9WEEK03


1.week03-2 滑鼠移動控制 與 利用滑鼠找座標

 Transformation

  1. 至https://jsyeh.org/3dcg10 下載data , win32
  2. windows.zip解壓縮 >> windows / transformation.exe
  3. data.zip解壓縮 >> windows / data / 模型obj
  4. 把data檔案放進windows >> 執行transformation.exe


 1.滑鼠移動控制
(1) 先建一個GLUT專案,程式碼如下


#include <GL/glut.h>
float mouseX=0, mouseY=0;
void myTeapot(float x, float y)
{
glPushMatrix();///備份矩陣 (備份舊的地址)
glTranslatef(x,y,0);
glColor3f(1,1,0);///黃色
glutSolidTeapot(0.3);///茶壺
glPopMatrix();///還原矩陣(還原舊地址)
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
myTeapot( (mouseX-150)/150.0,-(mouseY-150)/150.0 );
glutSwapBuffers();
}
void mouse(int button, int state, int x,int y)
{
mouseX=x; mouseY=y;
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week03-1");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();



}

2.利用滑鼠找座標 1.程式碼如下 #include<GL/glut.h> #include<stdio.h>///印東西用的 float mouseX=0,mouseY=0; void myTeapot(float x,float y) { glPushMatrix();///備份矩陣 (備份舊的地址) glTranslatef(x,y,0); glColor3f(1,1,0);///黃色 glutSolidTeapot(0.1); ///茶壺 glPopMatrix();///還原矩陣(還原舊地址) } void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); ///清空 myTeapot((mouseX-150)/150.0,(mouseY-150)/150.0); glutSwapBuffers(); } void mouse(int button,int state,int x,int y) { printf("%d %d %d %d\n" , button ,state,x,y); mouseX=x;mouseY=y; } int main(int argc ,char** argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH); glutCreateWindow("08160545 week03"); glutDisplayFunc(display); glutMouseFunc(mouse); glutMainLoop(); }



沒有留言:

張貼留言

VERY BEAUTIFUL, VERY POWERFUL

一.     一樣先安裝且設定好freeglut,OpecCV, 開啟CodeBlocks建立新專案 week11_gundam,                 把 MyGundam.zip下載解壓縮後的data資料夾放到freeglut/bin裡面 把week09_openc...