CariDotMy

 Forgot password?
 Register

ADVERTISEMENT

View: 2286|Reply: 6

#include<glut.h>

[Copy link]
Post time 18-9-2008 11:46 PM | Show all posts |Read mode
salam all,

Lama x memposting, ak  bru blaja Computer Grafik so nak tya skit.

-Macamana nak buat 2 objek (cthnya 2 polygon) tp berbeza pergerakan apabila key ditekan.
Cthnya petak1 apabila tekan key"A" dia bergerak ke kiri, petak 2 apabila tekan "S" ia bergerak ke kanan.
Main point " pergerakan lain pada objek berlainan apabila key ditekan".

-Problem ke 2 plak, pada slot create objek, bla ak aku open "glTranslated" objek trus x kuar bla compile,...  stressful toll..

ni coding yg ak maksudkan
------------------------------------------------------------------------------------------------------------------------------------------------------
#include <GL/glut.h>

char rotAxis='n';
double rotX=0.0, rotY=0.0, rotZ=0.0,
       vertical=0.0,
       horizontal=0.0;

void init()
{      
        glClearColor(0.0,0.0,1.0,0.0);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(-5.0,5.0,-5.0,5.0,-5.0,5.0);
}

void reset_value(void)
{
     rotAxis='n',
     rotX=0,rotZ=0,rotY=0,
     vertical=0.0,
     horizontal=0.0,
     init();
}

void testpower()
{
        glClear(GL_COLOR_BUFFER_BIT);
        
        glColor3f(1.0,0.5,1.5);
        //glTranslated(-1,0,0);                            <<<-----------------------aku tutup sbb x kuar gambar bla compile
        glBegin(GL_POLYGON);
             glVertex2f(0.5,0.5);
             glVertex2f(-0.5,0.5);
             glVertex2f(-0.5,-0.5);
             glVertex2f(0.5,-0.5);
        glEnd();
        
        /*glColor3f(0.0,0.0,0.0);
        glTranslated(2,0,0);
        glBegin(GL_POLYGON);
             glVertex2f(0.5,0.5);
             glVertex2f(-0.5,0.5);
             glVertex2f(-0.5,-0.5);
             glVertex2f(0.5,-0.5);
        glEnd();*/
        glFlush();

}

void animation()
{
     if (rotAxis=='x')
        rotX=0.5;
        
     else if (rotAxis=='y')
        rotY=0.5;
        
     else if (rotAxis=='z')
        rotZ=0.5;
        
     glRotated(rotX,1.0,0.0,0.0);
     glRotated(rotY,0.0,1.0,0.0);
     glRotated(rotZ,0.0,0.0,1.0);
     glutSwapBuffers();
     glutPostRedisplay();
     
}

void myKeyboard(unsigned char key, int x, int y)
{

     if (key == 27)
     exit(0);
     
     else if (key == '0')
     reset_value();
     
     else if (key == 'x')
     rotAxis = 'x';
     
     else if (key == 'y')
     rotAxis = 'y';
     
     else if (key == 'z')
     rotAxis = 'z';
}

void mySpecial(int key, int x, int y)
{
     vertical=0.0;
     horizontal=0.0;
     
     if (key==GLUT_KEY_UP)
     vertical+=0.2;
     
     else if (key==GLUT_KEY_DOWN)
     vertical-=0.2;
     
     else if (key==GLUT_KEY_LEFT)
     horizontal-=0.2;
     
     else if (key==GLUT_KEY_RIGHT)
     horizontal+=0.2;
     
     glTranslated(horizontal,vertical,0);
}

int main (int argc,char**argv)
{
        glutInit(&argc,argv);
        glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
        glutInitWindowSize(600,600);
        glutInitWindowPosition(0,0);
        glutCreateWindow("Testing");
        glutDisplayFunc(testpower);
        glutKeyboardFunc(myKeyboard);
        glutSpecialFunc(mySpecial);
        glutIdleFunc(animation);
        init();
        glutMainLoop();
}
Reply

Use magic Report


ADVERTISEMENT


 Author| Post time 18-9-2008 11:52 PM | Show all posts
Reply

Use magic Report

Post time 19-9-2008 09:05 PM | Show all posts
pergi masuk putera.com dan sifoo.com.ramai otai kat situ.posting nko pung x kemas!
Reply

Use magic Report

 Author| Post time 20-9-2008 02:32 AM | Show all posts

Balas #3 JohnDeSouza\ catat

oooooo... kat cni xda ke? nvm la...

xkemas hurm... ak tak tahu memposting sebenarnya..
Reply

Use magic Report

Post time 22-9-2008 01:12 AM | Show all posts
dulu aku penah bantu budak MMU buat menda nih.. huh.. wat design klcc lg.. kekkkekeke teringat zaman dulu2..
Reply

Use magic Report

 Author| Post time 22-9-2008 01:26 AM | Show all posts

Balas #5 liverpoolfctv\ catat

aisehhh, bangga ah tu... hahaha...
bagus2...

tp lagi bagus kalau ko dapat membantu solve problem ak ni...
Reply

Use magic Report

Follow Us
Post time 22-9-2008 09:00 AM | Show all posts
Originally posted by liverpoolfctv at 22-9-2008 01:12 AM
dulu aku penah bantu budak MMU buat menda nih.. huh.. wat design klcc lg.. kekkkekeke teringat zaman dulu2..


ha;ah...ko dah pernah buat prog mcm nih..ko bantulah tuan tanah nih..kesian dia...
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

 

ADVERTISEMENT


Forum Hot Topic

 

ADVERTISEMENT


 


ADVERTISEMENT
Follow Us

ADVERTISEMENT


Mobile|Archiver|Mobile*default|About Us|CariDotMy

24-1-2025 04:04 PM GMT+8 , Processed in 0.153096 second(s), 20 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

Quick Reply To Top Return to the list