Hỏi đáp
Chia sẻ kiến thức, cùng nhau phát triển
chào các bác! e có 1 đoạn code như trên. giờ e muốn gán con trỏ vào nguồn sáng, để duy chuyển nguồn sáng thì e phải làm ntn ạ? mong các bác chỉ giáo và giúp đỡ. e xin chân thành cảm ơn ! xD
#include <gl/glut.h>
#include <math.h> // For math routines (such as sqrt & trig).
GLfloat xRotated, yRotated, zRotated;
GLdouble radius = 2;
GLfloat qaBlack[] = { 0.0, 0.0, 0.0, 1.0 }; //Black Color
GLfloat qaGreen[] = { 0.0, 1.0, 0.0, 0.0 }; //Green Color
GLfloat qaWhite[] = { 1.0, 1.0, 1.0, 1.0 }; //White Color
GLfloat qaRed[] = { 1.0, 0.0, 0.0, 1.0 }; //Red Color
// Set lighting intensity and color
GLfloat qaAmbientLight[] = { 0.1, 0.1, 0.1, 1.0 };
GLfloat qaDiffuseLight[] = { 1, 1, 1, 1.0 };
GLfloat qaSpecularLight[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat emitLight[] = { 0.9, 0.9, 0.9, 0.01 };
GLfloat Noemit[] = { 0.0, 0.0, 0.0, 1.0 };
// Light source position
GLfloat qaLightPosition[] = { 0, 0, 0, 1 };
void display(void);
void reshape(int x, int y);
void idleFunc(void)
{
if (zRotated > 360.0) {
zRotated -= 360.0*floor(zRotated / 360.0); // Don't allow overflow
}
if (yRotated > 360.0) {
yRotated -= 360.0*floor(yRotated / 360.0); // Don't allow overflow
}
zRotated += 0.01;
yRotated += 0.01;
display();
}
void initLighting()
{
// Enable lighting
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
// Set lighting intensity and color
glLightfv(GL_LIGHT0, GL_AMBIENT, qaAmbientLight);
glLightfv(GL_LIGHT0, GL_DIFFUSE, qaDiffuseLight);
glLightfv(GL_LIGHT0, GL_SPECULAR, qaSpecularLight);
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(350, 350);
glutCreateWindow("Nhóm 7");
initLighting();
xRotated = yRotated = zRotated = 0.0;
glutIdleFunc(idleFunc);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
void display(void)
{
glMatrixMode(GL_MODELVIEW);
// clear the drawing buffer.
glClear(GL_COLOR_BUFFER_BIT);
// clear the identity matrix.
glLoadIdentity();
glTranslatef(0.0, 0.0, -20.0);
//
glPushMatrix();
glTranslatef(0.0, 0.0, 0);
// Set material properties
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, qaRed);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, qaRed);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, qaWhite);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0.2);
glutSolidSphere(radius, 25, 25);
glPopMatrix();
glPushMatrix();
glRotatef(yRotated, 0.0, 0.0, 1.0);
glTranslatef(5.0, 0.0, 0.0);
// Set the light position
glLightfv(GL_LIGHT0, GL_POSITION, qaLightPosition);
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, emitLight); // Make sphere glow (emissive)
glutSolidSphere(radius / 6, 25, 25);
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, Noemit);
glPopMatrix();
glFlush();
glutSwapBuffers();
}
void reshape(int x, int y)
{
if (y == 0 || x == 0) return;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(39.0, (GLdouble)x / (GLdouble)y, 0.6, 40.0);
glMatrixMode(GL_MODELVIEW);
glViewport(0, 0, x, y); //Use the whole window for rendering
}
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
chào các bác! e có 1 đoạn code như trên. giờ e muốn gán con trỏ vào nguồn sáng, để duy chuyển nguồn sáng thì e phải làm ntn ạ? mong các bác chỉ giáo và giúp đỡ. e xin chân thành cảm ơn ! xD
Để sử dụng tính năng này, Bạn cần đăng nhập bằng tài khoản Howkteam.
Đăng nhập
Để xem được nội dung và giúp Kteam duy trì hoạt động.
Bạn vui lòng tắt Adblock trên website howkteam.vn nhé!
http://nehe.gamedev.net/tutorial/shadows/16010/
mong cái này giúp được bạn phần nào @@
https://www.opengl.org/sdk/docs/tutorials/ClockworkCoders/lighting.php
Khó quá. gặp ca này không biết đỡ sao luôn @@