#Week04_mouse_glScalef
1.下載freeglut,選lib,複製改成libglut32.a ///檔名不能有空格
#include <GL/glut.h>
void display()
{
glClearColor(1.0,1.0,0.9,1.0);///清背景的淡黃色
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);///清背景
glutSolidTeapot(0.3);
glutSwapBuffers();
}
int main(int argc,char*argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week04 mouse glScalef");
glutDisplayFunc(display);
glutMainLoop();
}
#include <GL/glut.h>
float angle=0;
void display()
{
glClearColor(1.0,0.0,0.9,1.0);///清背景的淡黃色
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);///清背景
glPushMatrix();
glRotatef(angle,0,0,1);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void motion(int x,int y) {
angle = x;
display();
}
int main(int argc,char*argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week04 mouse glScalef");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
#include <GL/glut.h>
///float angle=0;
float s = 1;
void display()
{
glClearColor(1.0,0.0,0.9,1.0);///清背景的淡黃色
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);///清背景
glPushMatrix();
///glRotatef(angle,0,0,1);
glScalef(s,s,s);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void motion(int x,int y) {
///angle = x;
s=1+(x-150)/150.0;
display();
}
int main(int argc,char*argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week04 mouse glScalef");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
###week04_keyboard_mouse_motio
1.File-New-porject, GLUT專案 week04_keyboard_mouse_motio
#include <GL/glut.h>
#include <stdio.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);///清背景
glPushMatrix();
glutSolidTeapot(0.3);
glutSwapBuffers();
}
void keyboard(unsigned char key,int x,int y){
printf("key:%c x:%d y:%d\n",key,x,y);
}
int main(int argc,char*argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week04 keyboard mouse motio");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
}
Keyboard點座標+mouse+motion選轉
#include <GL/glut.h>
#include <stdio.h>
float angle=0,oldX=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);///清背景
glPushMatrix();
glRotatef(angle,0,0,1);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void mouse(int button, int state,int x,int y){
oldX = x;
}
void motion(int x,int y){
angle +=(x-oldX);
oldX = x;
display();
}
void keyboard(unsigned char key,int x,int y){
printf("key:%c x:%d y:%d\n",key,x,y);
}
int main(int argc,char*argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week04 keyboard mouse motio");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
###下載書
自轉,公轉
轉動中的藍色車搬去右邊轉動的車子
File-New-porject, GLUT專案 week04_translate_rotate_scale
貼上前一個程式碼
#include <GL/glut.h>
#include <stdio.h>
float angle=0,oldX=0;
void display()
{
glClearColor(1.0,1.0,0.9,1.0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);///清背景
glPushMatrix();
glTranslatef(0.8,0,0);///放到右邊
glRotatef(angle++,0,0,1);///轉動中的
glScalef(0.3,0.3,0.3);///小小的
glColor3f(0,1,0);///綠色的
glutSolidTeapot(0.3);///茶壺
glPopMatrix();
glutSwapBuffers();
}
int main(int argc,char*argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow(" week04 translate rotate scale");
glutDisplayFunc(display);
glutIdleFunc(display);///加這行
glutMainLoop();
}
##交換程式碼
translate/rotate
整個<.......>全部轉動
複製程式碼
改變兩行
GlTranslatef()和
glRotatef()順序
沒有留言:
張貼留言