2018年1月5日 星期五

吳映廷 計算機圖學 week17

本週的主題是製作期末作品。
這週的進度是將基本的HUD(分數,血量)加入
以及敵人的生成.。
以下是分數和血量的部分程式碼。
    public void Score()
    {
        bonusHealthText.SetActive(false);
        stick_man_combo += 1;
        if (stick_man_combo % 5 == 0)
        {
            stick_man_health += 10;
            bonusHealthText.SetActive(true);
            healthText.text = "Health: " + stick_man_health.ToString();
        }
        comboText.text = "Combo: " + stick_man_combo.ToString();
        stick_man_score += stick_man_combo * 10;
        scoreText.text = "Score: " + stick_man_score.ToString();
    }
    public void Hurt()
    {
        stick_man_combo = 0;
        comboText.text = "Combo: " + stick_man_combo.ToString();
        stick_man_health -= 10;
        healthText.text = "Health: " + stick_man_health.ToString();
        if (stick_man_health <= 0)
        {
            gameoverText.SetActive(true);
            gameover = true;
        }

    }

以下是敵人經過時間隨機生成的程式碼。
if (gameover == false)
        {
            System.Random rnd = new System.Random();
            GenTime = rnd.Next(1, 50);
            GenTime2 = rnd.Next(1, 50);
        }
        if (enemyGenCounter > GenTime)
        {
            GameObject.Instantiate(enemy);
            enemyGenCounter = 0;
        }
        if (enemyGenCounter > GenTime2)
        {
            GameObject.Instantiate(enemy_R);
            enemyGenCounter2 = 0;
        }

2018年1月4日 星期四

LBH的計圖學習筆記_week 17

一 、 上課內容

1. 期末專題製作

魏建新的第九週學題單

  1. 上週Texture 貼圖、詳解
  2. 多重貼圖
  3. Bump Mapping

在MOODLE的上課軟體下載processing-3.3.6-windows64.zip打開

程式碼:
先RUN網友的程式碼:https://www.openprocessing.org/sketch/249457
把網路的程式碼COPY到processing

PImage img=loadImage("doraemon.jpeg"); 注載入圖片用 doraemon.jpeg為你要用的圖片名
size(600, 600);
image(img, 0,0, 600,600);

PImage img; 注用來呈現中BUG的圖片
void setup(){
  size(1280, 800);
  img=loadImage("error.jpg");
}

void draw(){
  //rect(mouseX, mouseY, 50, 50);  <- 用來畫正方形的碼
  image(img, mouseX,mouseY, 400,250);
}

魏建新的第七週學題單

(1)作業二展示,互評(2)主題: Mouse,Model,打光 ->用mouse調光源(3)主題: Lighting打光,Shading光影




程式碼: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);
    glutPostOverlayRedisplay();
}

GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };  注:剛孕const 

圖例:


Arthus week8

week8

Texture 貼圖
OPen CV的安裝,讀圖
open GL的貼圖設定
EX:轉動地球

http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/下載data、windows、glut32、source把date和glut32.dll放入windows資料夾裡
到moodle中下載OpenCV-2.1.0-win32-vs2008.exe
安裝過程中選第3個選項
打開codeblocks開專案檔console application複製貼上
#include <opencv/highgui.h>
int main()
{
IplImage * img=cvLoadImage("earth.jpg");
cvNamedWindow("hello");
cvShowImage("hello", img);
cvWaitKey(0);
return 0;
}
codeblocks設定中改成->Build options->Search directories
Search directories->Compiler->Add directory : c:\opencv2.1\include
Search directories->Linker->Add directory : c:\opencv2.1\lib
Linker setting->Add library : cv210 
Linker setting->Add library : cxcore210 
Linker setting->Add library : highgui210
下載圖檔並放到專案檔中

2018年1月2日 星期二

abcqq week07

1.打光程式碼

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();
}
glutMotionFunc(motion);

從左邊打光


從右邊打光

abcqq week 06

1.打光

相關程式碼:

glutCreateWindow(...); //開視窗

glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING); //打光程式1
glEnable(GL_LIGHT0); //打光程式2
glLightfv(GL_LIGHT0, GPOSITION, pos); 


keyboard 副程式

void keyboard(unsigned char key, int x, int y)
{
    printf("now: %c (%d %d)\n", key, x,y);
    if(key=='1') rotateX++;
    if(key=='2') rotateY++;
    if(key=='3') rotateZ++;
    glutPostRedisplay(); //畫面重新 re-display
}

滑鼠控制  

void mouse(int button, int state, int x, int y)
{   printf("button:%d state:%d (%d %d)\n", button, state, x, y);
    
    if(state==GLUT_DOWN) 
    {
        oldX=x; oldY=y;
    }
}

滑鼠拖曳
void motion(int x, int y)
{
    rotateY +=   -(x-oldX);
    rotateX +=   -(y-oldY);
    oldX=x; oldY=y;
    glutPostRedisplay();
}