2017年10月27日 星期五
Mengting計圖筆記Week07 - Mouse、Model、打光
主題: 用Mouse打光(lighting打光、shading光影)
1. 開啟GLUT專案
2. 增加一些函式,見程式碼。
3. 以下將針對部分程式碼補充介紹。
slice切幾刀、stack疊起來
1. 開啟GLUT專案
2. 增加一些函式,見程式碼。
3. 以下將針對部分程式碼補充介紹。
程式碼補充介紹
void key(unsigned char key, int x, int y)
透過鍵盤+和-改變圖形形狀及密度。slice切幾刀、stack疊起來
static void resize(int width, int height)
使圖形大小不會受視窗縮放所影響。static void display(void)
t隨時間改變角度。
void motion(int x, int y)
改變光線位置。
glutMotionFunc(motion)
偵測滑鼠移動時的座標。Demo
2017年10月26日 星期四
田蜜Week07
Mouse-Lighting
1.打開glut專案
找到idle函式與main中的lighting相關程式碼
2.light_position表示光的位址
glutMotionFunc(motion); 表示滑鼠的改變
將const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f }; 前面的const 刪去
即可改變light_position的變數
3.加上函式
void motion(int x, int y)
{
light_position[0]=(x-150*2)/150.0*2; //更變光源座標為滑鼠座標
light_position[1]=-(y-150)/150.0*2;
glLightfv(GL_LIGHT0,GL_POSITION,light_position); //重設光源
glutPostRedisplay(); //重畫
}
在main中加上glutMotionFunc(motion); //mouse motion函式
4.編譯執行
完成!
詠銓_Week07_Note
Class: Mouse-Lighting
1.這次的課程是要用滑鼠改變光源。首先打開glut專案,找到lighting相關的程式碼
2.其中light_position是表示光的位址,既然我們要用滑鼠位置代表光源,所以我們使用
glutMotionFunc(motion); 來表示滑鼠位置的改變。
Note:
motion副程式如下:
肯尼斯的學習筆記 Week 7
用滑鼠調光源
建立GLUT專案,然後加入滑鼠調光源功能
程式碼:
GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f }; //將const刪掉
void motion(int x, int y)
{
light_position[0] = (x - 150) / 150.0 *2;
light_position[1] = (y - 150) / 150.0 *2;
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glutPostRedisplay();
}
int main(int argc, char *argv[])
{
......
glutMotionFunc(motion); //在main加入mouse motion函式
}
Claire 的課堂作業 week7
計算機圖學 Computer Graphics
- 作業二展示、互評
- 主題:mouse, model, lighting ==> 用mouse調光源
- 主軸:lighting 打光/ shading 光影
滑鼠控制光緣變化
1. 今天的程式範例來自codeBlocks編輯器,在新增GLUT5專案的時候,所自動產生的程式碼,因為前幾篇有提到操作方式,所以這篇就不贅述囉!
2. 利用 motion 讀取滑鼠的位置,程式碼打在main函式之前
3. 完成後,執行。用滑鼠操作就可以看到光影的變化了 !
蒲立年的學習筆記 Week 07
一、用滑鼠打光源
1.首先我們先開啟openGL專案
2.將const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };的const 刪去,讓我們能更改light_position的變數,結果為 => GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };
3.再下方加上涵式
week07 林韋廷的學習筆記
Hello World_OpenGL_note_Week07
第七周
本周我們欣賞了大家的作品。謝謝老師讓我欣賞到大家的作品,學到很多!
今天我們學習光源。
步驟一: 在原本的程式碼上,加新的程式碼(即粉紅線的部分)
步驟二: 執行結果,注意藍色圈圈。
光點的改變是因為滑鼠移動。
本周我們欣賞了大家的作品。謝謝老師讓我欣賞到大家的作品,學到很多!
今天我們學習光源。
步驟一: 在原本的程式碼上,加新的程式碼(即粉紅線的部分)
步驟二: 執行結果,注意藍色圈圈。
光點的改變是因為滑鼠移動。
羅浩倫的學習筆記 Week07
本週學習重點
1.作業二展示、互評
2.主題: Mouse, Model, 打光
=> 用mouse調光源
3.主題: Lighting打光, Shading 光影
今天在原本新建專案後自動產生的main檔案裡面加上motion()來控制光源的位置
void motion(int x, int y) {
light_position[0] = (x-150)/150.0 * 10;
light_position[1] = -(y-150)/150.0 * 10;
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
idle();
}
在main()裡面記得要加上glutMotionFunc(motion);來註冊motion()
光源在右上方
光源在左下方
今天因為互相評分花了快兩節課,所以程式碼的進度比較少。
李柏徹的計算機圖學學習紀錄07
1.將IDLE中的
const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f }; 的const刪掉
2.新增motion函式
void motion(int x, int y)
{
light_position[0]= (x-150)/150.0;
light_position[1]= (y-150)/150.0;
glLightfv(GL_LIGHT0,GL_POSITION,light_position);
glutPostRedisplay();
}
3.在main中新增glutMotionFunc(motion);
呼叫剛剛新增的函式
完整程式碼:
/*
* GLUT Shapes Demo
*
* Written by Nigel Stewart November 2003
*
* This program is test harness for the sphere, cone
* and torus shapes in GLUT.
*
* Spinning wireframe and smooth shaded shapes are
* displayed until the ESC or q key is pressed. The
* number of geometry stacks and slices can be adjusted
* using the + and - keys.
*/
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <stdlib.h>
static int slices = 16;
static int stacks = 16;
/* GLUT callback Handlers */
static void resize(int width, int height)
{
const float ar = (float) width / (float) height;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity() ;
}
static void display(void)
{
const double t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;
const double a = t*90.0;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3d(1,0,0);
glPushMatrix();
glTranslated(-2.4,1.2,-6);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();
glPushMatrix();
glTranslated(0,1.2,-6);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidCone(1,1,slices,stacks);
glPopMatrix();
glPushMatrix();
glTranslated(2.4,1.2,-6);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidTorus(0.2,0.8,slices,stacks);
glPopMatrix();
glPushMatrix();
glTranslated(-2.4,-1.2,-6);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutWireSphere(1,slices,stacks);
glPopMatrix();
glPushMatrix();
glTranslated(0,-1.2,-6);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutWireCone(1,1,slices,stacks);
glPopMatrix();
glPushMatrix();
glTranslated(2.4,-1.2,-6);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutWireTorus(0.2,0.8,slices,stacks);
glPopMatrix();
glutSwapBuffers();
}
static void key(unsigned char key, int x, int y)
{
switch (key)
{
case 27 :
case 'q':
exit(0);
break;
case '+':
slices++;
stacks++;
break;
case '-':
if (slices>3 && stacks>3)
{
slices--;
stacks--;
}
break;
}
glutPostRedisplay();
}
static void idle(void)
{
glutPostRedisplay();
}
const GLfloat light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };
const GLfloat mat_ambient[] = { 0.7f, 0.7f, 0.7f, 1.0f };
const GLfloat mat_diffuse[] = { 0.8f, 0.8f, 0.8f, 1.0f };
const GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat high_shininess[] = { 100.0f };
/* Program entry point */
void motion(int x, int y)
{
light_position[0]= (x-150)/150.0;
light_position[1]= (y-150)/150.0;
glLightfv(GL_LIGHT0,GL_POSITION,light_position);
glutPostRedisplay();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitWindowSize(640,480);
glutInitWindowPosition(10,10);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("GLUT Shapes");
glutReshapeFunc(resize);
glutDisplayFunc(display);
glutKeyboardFunc(key);
glutMotionFunc(motion);
glutIdleFunc(idle);
glClearColor(1,1,1,1);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
glutMainLoop();
return EXIT_SUCCESS;
}
const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f }; 的const刪掉
2.新增motion函式
void motion(int x, int y)
{
light_position[0]= (x-150)/150.0;
light_position[1]= (y-150)/150.0;
glLightfv(GL_LIGHT0,GL_POSITION,light_position);
glutPostRedisplay();
}
3.在main中新增glutMotionFunc(motion);
呼叫剛剛新增的函式
完整程式碼:
/*
* GLUT Shapes Demo
*
* Written by Nigel Stewart November 2003
*
* This program is test harness for the sphere, cone
* and torus shapes in GLUT.
*
* Spinning wireframe and smooth shaded shapes are
* displayed until the ESC or q key is pressed. The
* number of geometry stacks and slices can be adjusted
* using the + and - keys.
*/
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <stdlib.h>
static int slices = 16;
static int stacks = 16;
/* GLUT callback Handlers */
static void resize(int width, int height)
{
const float ar = (float) width / (float) height;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity() ;
}
static void display(void)
{
const double t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;
const double a = t*90.0;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3d(1,0,0);
glPushMatrix();
glTranslated(-2.4,1.2,-6);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();
glPushMatrix();
glTranslated(0,1.2,-6);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidCone(1,1,slices,stacks);
glPopMatrix();
glPushMatrix();
glTranslated(2.4,1.2,-6);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidTorus(0.2,0.8,slices,stacks);
glPopMatrix();
glPushMatrix();
glTranslated(-2.4,-1.2,-6);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutWireSphere(1,slices,stacks);
glPopMatrix();
glPushMatrix();
glTranslated(0,-1.2,-6);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutWireCone(1,1,slices,stacks);
glPopMatrix();
glPushMatrix();
glTranslated(2.4,-1.2,-6);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutWireTorus(0.2,0.8,slices,stacks);
glPopMatrix();
glutSwapBuffers();
}
static void key(unsigned char key, int x, int y)
{
switch (key)
{
case 27 :
case 'q':
exit(0);
break;
case '+':
slices++;
stacks++;
break;
case '-':
if (slices>3 && stacks>3)
{
slices--;
stacks--;
}
break;
}
glutPostRedisplay();
}
static void idle(void)
{
glutPostRedisplay();
}
const GLfloat light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };
const GLfloat mat_ambient[] = { 0.7f, 0.7f, 0.7f, 1.0f };
const GLfloat mat_diffuse[] = { 0.8f, 0.8f, 0.8f, 1.0f };
const GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat high_shininess[] = { 100.0f };
/* Program entry point */
void motion(int x, int y)
{
light_position[0]= (x-150)/150.0;
light_position[1]= (y-150)/150.0;
glLightfv(GL_LIGHT0,GL_POSITION,light_position);
glutPostRedisplay();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitWindowSize(640,480);
glutInitWindowPosition(10,10);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("GLUT Shapes");
glutReshapeFunc(resize);
glutDisplayFunc(display);
glutKeyboardFunc(key);
glutMotionFunc(motion);
glutIdleFunc(idle);
glClearColor(1,1,1,1);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
glutMainLoop();
return EXIT_SUCCESS;
}
柴宇恆 week07
最上方的那一行
GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };
是改變光的位置 ,分別是光往左右,上下,以及前後
接下來要試著用滑鼠讓光源可以自己隨意操控
void motion(int x,int y)
{
light_position[0]=(x-150)/150.0*2; 改變X座標
light_position[1]=-(y-150)/150.0*2; 改變Y座標
glLightfv(GL_LIGHT0, GL_POSITION, light_position); 打光用
glutPostRedisplay();隨時改變畫面
}
光源在左上
GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };
是改變光的位置 ,分別是光往左右,上下,以及前後
接下來要試著用滑鼠讓光源可以自己隨意操控
void motion(int x,int y)
{
light_position[0]=(x-150)/150.0*2; 改變X座標
light_position[1]=-(y-150)/150.0*2; 改變Y座標
glLightfv(GL_LIGHT0, GL_POSITION, light_position); 打光用
glutPostRedisplay();隨時改變畫面
}
光源在左上
光源在右下
周承翰_計圖學習筆記_Week07
Week07 光源
主題(1) : Mouse Model 打光 --> Mouse調整光源
使用函式 :
光隨 mouse motion
GLFloat light_position[]={.......}
void motion(int x , int y)
{
light_position[0]=(x-150)/150*2;
light_position[1]=(y-150)/150*2;
glLightfv(GL_LIGHT0,GL_LIGHT_POSITION,light_position);
glutPostRedisplay();
}
用滑鼠拖曳便可改變光源
用滑鼠拖曳便可改變光源
主題(2) : Lighting打光 Shading 光源
Leo 學習筆記 Week07
圖學筆記Week07
Lightening&Shading(光影)
今日函式:
light_position[]={2.0f, 5.0f, 5.0f, 0.0f} ->內建程式碼,打光位置。
void Motion(int x,int y)
{
light_position[0]=(x-150)/150.0*50; //改變X座標位置
light_position[1]=-(y-150)/150.0*50; //改變Y座標位置
glLightfv(GL_LIGHT0, GL_POSITION, light_position); //在main函式有 ,需呼叫才會打光
glutPostRedisplay();
}
訂閱:
文章 (Atom)