Files |  Tutorials |  Articles |  Links |  Home |  Team |  Forum |  Wiki |  Impressum

Aktuelle Zeit: Fr Jul 18, 2025 08:07

Foren-Übersicht » Programmierung » OpenGL
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 8 Beiträge ] 
Autor Nachricht
BeitragVerfasst: Di Dez 08, 2009 08:06 
Offline
DGL Member

Registriert: Fr Dez 04, 2009 15:56
Beiträge: 6
Hallo,

es ist zwar ein Delphi-OpenGL-Forum und ich soll in C++ coden, aber ich werde die Frage trotzdem mal stellen, da die Sprachen ja so verschieden auch nicht sind.

a.)
Die Lichtquelle GL_LIGHT0 soll paralleles Licht erzeugen. Das Licht soll im ambienten, im diffusen und im sepcularen Teil weiß sein. Das Licht soll ferne aus der Richtung (1.0 1.0 1.0)^T scheinen. Implementieren Sie dieses Lichtquelleneinstellungen.
Code:
  1.  
  2. void setLightSource()
  3. {
  4.     // Set light properties
  5.     // TO...
  6.     GLfloat LAmbient[4] = {1.0F, 1.0F, 1.0F, 1.0F};
  7.     GLfloat LDiffuse[4] = {1.0F, 1.0F, 1.0F, 1.0F};
  8.     GLfloat LSpecular[4] = {1.0F, 1.0F, 1.0F, 1.0F};
  9.  
  10.     GLfloat LPosition[4] = {1.0F,1.0F,1.0F,0.0F};
  11.  
  12.     glEnable(GL_LIGHTING);
  13.     glEnable(GL_LIGHT0);
  14.  
  15.     glLightfv(GL_LIGHT0, GL_AMBIENT, &LAmbient[0]);
  16.     glLightfv(GL_LIGHT0, GL_DIFFUSE, &LDiffuse[0]);
  17.     glLightfv(GL_LIGHT0, GL_SPECULAR, &LSpecular[0]);
  18.  
  19.     glLightfv(GL_LIGHT0, GL_POSITION, &LPosition[0]);
  20.     // ...DO
  21. }
  22.  


b.)
Erzeugen Sie folgende Materialeigenschaften: Der Ambiente-Teil soll (x/7,0,0) betragen, der Diffuse-Teil soll (y/4,0,0) betragen, der Specular-Teil soll ((y*5+x+15)/30,(y*5+x+15)/30,(y*5+x+15)/30) betragen und die Shininess soll (110*(y*5+x))/15 + 18 betragen. Hier sollen x uny y den Schleifenvariablen aus dem Code entsprechen.
Code:
  1.  
  2. void drawSpheres()
  3. {
  4.     glMatrixMode(GL_MODELVIEW);
  5.     glPushMatrix();
  6.     glTranslatef(-8.0, 4.0, 1.0);
  7.     for(unsigned int y = 0; y<3; y++)
  8.     {
  9.         glPushMatrix();
  10.         for(unsigned int x = 0; x < 5; x++)
  11.         {
  12.             GLfloat amb = x/7;
  13.             GLfloat dif = y/4;
  14.             GLfloat spe = (y*5+x+15)/30;
  15.  
  16.             GLfloat MAmbient[4] = {amb, 0.0F, 0.0F, 1.0F};
  17.             GLfloat MDiffuse[4] = {dif, 0.0F, 0.0F, 1.0F};
  18.             GLfloat MSpecular[4] = {spe, spe, spe, 1.0F};
  19.            
  20.             GLfloat MShininess = ((110*(y*5+x))/15) + 18;
  21.  
  22.             glMaterialfv(GL_FRONT, GL_AMBIENT, &MAmbient[0]);
  23.             glMaterialfv(GL_FRONT, GL_DIFFUSE, &MDiffuse[0]);
  24.             glMaterialfv(GL_FRONT, GL_SPECULAR, &MSpecular[0]);
  25.  
  26.             glMaterialf (GL_FRONT, GL_SHININESS, MShininess);
  27.  
  28.             glColor3f(1.0, 1.0, 1.0);
  29.             // ...DO
  30.  
  31.             SubDivSphere Sphere;
  32.             Sphere.DrawSphere(5);
  33.             glTranslatef(4.0, 0.0, 0.0);
  34.         }
  35.         glPopMatrix();
  36.         glTranslatef(0.0, -4.0, 0.0);
  37.     }
  38.     glPopMatrix();
  39. }
  40.  


Derzeit erhalte ich
Bild

aber ich soll
Bild
erhalten.

Vielleicht kann ja jemand einen Blick drauf werfen und mir sagen, wo der wahrscheinlich kleine Fehler liegt. Danke.


Nach oben
 Profil  
Mit Zitat antworten  
BeitragVerfasst: Di Dez 08, 2009 10:08 
Offline
DGL Member

Registriert: Do Mai 30, 2002 18:48
Beiträge: 1617
Das mit Delphi nimmt hier schon lange niemand mehr so ganz ernst :-) ... Also die Kugeln sind schwarz.. Hast Du denn setLightSource() in deinem Programm irgendwo aufgerufen?

Code:
  1. SubDivSphere Sphere;
  2. Sphere.DrawSphere(5);

Setzt DrawSphere() Normalen und wenn ja, ist SubDivSphere eine klasse? Sieht nämlich irgendwie so aus, als wäre da der Konstruktor nicht aufgerufen - in diesem Fall gehört die Defintion von Sphere aber auch aus draw Spheres entfernt, sonst kann dir beim Rendern schnell der Speicher ausgehen.


Nach oben
 Profil  
Mit Zitat antworten  
BeitragVerfasst: Di Dez 08, 2009 10:21 
Offline
Guitar Hero
Benutzeravatar

Registriert: Do Sep 25, 2003 15:56
Beiträge: 7810
Wohnort: Sachsen - ERZ / C
Programmiersprache: Java (, Pascal)
Genau. Also das Thema "Normalen" kam mir auch als erstes in den Sinn.
Das du dein Objekt scheinbar nicht wieder freigibst, könnte später auch mal Probleme machen. (In Java hättest du einen GC 8) )

Ein Blick in den "DrawSphere" Methode könnte helfen.

_________________
Blog: kevin-fleischer.de und fbaingermany.com


Nach oben
 Profil  
Mit Zitat antworten  
BeitragVerfasst: Di Dez 08, 2009 10:23 
Offline
DGL Member

Registriert: Fr Dez 04, 2009 15:56
Beiträge: 6
Hallo.

Hier mal der komplette Code für spheres.cpp:

Code:
  1.  
  2. #include <cstdlib>
  3. #ifdef WIN32
  4. #define _USE_MATH_DEFINES
  5. #include <windows.h>
  6. #endif
  7. #include <cmath>
  8. #include <GL/glew.h>
  9. #include <GL/glut.h>
  10. #include <iostream>
  11.  
  12. #include "SubDivSphere.hh"
  13.  
  14. #include "CameraSteering.hh"
  15.  
  16. using namespace std;
  17.  
  18. //**** Predeclarationen ****
  19. //GL
  20. void initGL();
  21. void clearBuffers();
  22.  
  23. //Glut
  24. void initGlut(int* argc, char* argv[]);
  25. void display();
  26. void KeyPressed(unsigned char key, int x, int y);
  27. void MouseClicked(int button, int state, int x, int y);
  28. void MouseMoves(int x, int y);
  29. void animate();
  30.  
  31. // Excercise
  32. void setLightSource();
  33. void setProjection();
  34.  
  35. //**** Predeclarationen end ****
  36.  
  37. // *** GLOBALS
  38. float fovy = 30;
  39. int window_width = 800;
  40. int window_height = 450;
  41. int window_posx = 200;
  42. int window_posy = 200;
  43. int sleeptime = 3000;
  44.  
  45. //camera control
  46. CameraSteering camera(0, 0, -30);
  47. float nearClippingPlane = 1;
  48. float farClippingPlane = 100.0;
  49.  
  50. // mouse control
  51. bool rotating = false;
  52. bool movingLight = false;
  53. int old_x, old_y;
  54.  
  55. // shadows
  56. bool perspectiveMode = false;
  57. float shadowProjectionMatrix[16];
  58. float shadowLightPosition[] = {0.0 , 0.0, 5.0, 1.0};
  59.  
  60. // *** GLOBALS END
  61.  
  62. //**** GL
  63. void initGL(){
  64.     glEnable(GL_DEPTH_TEST);
  65.     glDepthFunc(GL_LESS);
  66.     glEnable(GL_CULL_FACE);
  67.     glEnable(GL_NORMALIZE);
  68.     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  69.     cout<<"GL Error: "<<gluErrorString(glGetError())<<endl;
  70. }
  71.  
  72. void clearBuffers()
  73. {
  74.     glClearColor(0.4, 0.6, 0.9, 0.0);
  75.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
  76. }
  77. //**** GL END
  78.  
  79. void setLightSource()
  80. {
  81.     // Set light properties
  82.     // TO...
  83.     GLfloat LAmbient[4] = {1.0F, 1.0F, 1.0F, 1.0F};
  84.     GLfloat LDiffuse[4] = {1.0F, 1.0F, 1.0F, 1.0F};
  85.     GLfloat LSpecular[4] = {1.0F, 1.0F, 1.0F, 1.0F};
  86.  
  87.     GLfloat LPosition[4] = {1.0F,1.0F,1.0F,0.0F};
  88.  
  89.     glEnable(GL_LIGHTING);
  90.     glEnable(GL_LIGHT0);
  91.  
  92.     glLightfv(GL_LIGHT0, GL_AMBIENT, &LAmbient[0]);
  93.     glLightfv(GL_LIGHT0, GL_DIFFUSE, &LDiffuse[0]);
  94.     glLightfv(GL_LIGHT0, GL_SPECULAR, &LSpecular[0]);
  95.  
  96.     glLightfv(GL_LIGHT0, GL_POSITION, &LPosition[0]);
  97.     // ...DO
  98. }
  99.  
  100. void drawSpheres()
  101. {
  102.     glMatrixMode(GL_MODELVIEW);
  103.     glPushMatrix();
  104.     glTranslatef(-8.0, 4.0, 1.0);
  105.     for(unsigned int y = 0; y<3; y++)
  106.     {
  107.         glPushMatrix();
  108.         for(unsigned int x = 0; x < 5; x++)
  109.         {
  110.             GLfloat amb = x/7;
  111.             GLfloat dif = y/4;
  112.             GLfloat spe = (y*5+x+15)/30;
  113.  
  114.             GLfloat MAmbient[4] = {amb, 0.0F, 0.0F, 1.0F};
  115.             GLfloat MDiffuse[4] = {dif, 0.0F, 0.0F, 1.0F};
  116.             GLfloat MSpecular[4] = {spe, spe, spe, 1.0F};
  117.            
  118.             GLfloat MShininess = ((110*(y*5+x))/15) + 18;
  119.  
  120.             glMaterialfv(GL_FRONT, GL_AMBIENT, &MAmbient[0]);
  121.             glMaterialfv(GL_FRONT, GL_DIFFUSE, &MDiffuse[0]);
  122.             glMaterialfv(GL_FRONT, GL_SPECULAR, &MSpecular[0]);
  123.  
  124.             glMaterialf (GL_FRONT, GL_SHININESS, MShininess);
  125.  
  126.             glColor3f(1.0, 1.0, 1.0);
  127.             // ...DO
  128.  
  129.             SubDivSphere Sphere;
  130.             Sphere.DrawSphere(5);
  131.             glTranslatef(4.0, 0.0, 0.0);
  132.         }
  133.         glPopMatrix();
  134.         glTranslatef(0.0, -4.0, 0.0);
  135.     }
  136.     glPopMatrix();
  137. }
  138.  
  139. void drawGround()
  140. {
  141.     glMatrixMode(GL_MODELVIEW);
  142.     glPushMatrix();
  143.     glTranslatef(0.0, 0.0, 0.0);
  144.  
  145.     glDisable(GL_LIGHTING);
  146.     glColor3f(0.4, 0.6, 0.0);
  147.     glBegin(GL_QUADS);
  148.     glNormal3f(0.0, 0.0, 1.0);
  149.     glVertex3f(-10.0, -10.0, 0.0);
  150.     glVertex3f( 10.0, -10.0, 0.0);
  151.     glVertex3f( 10.0,  10.0, 0.0);
  152.     glVertex3f(-10.0,  10.0, 0.0);
  153.     glEnd();
  154.     glEnable(GL_CULL_FACE);
  155.     glPopMatrix();
  156. }
  157.  
  158. void setShadowProjectionMatrix()
  159. {
  160.     //load identity into shadowprojection matrix
  161.     for(unsigned int i=0; i<16; i++){
  162.         shadowProjectionMatrix[i]=0;
  163.     }
  164.     shadowProjectionMatrix[0] = 1.0f;
  165.     shadowProjectionMatrix[5] = 1.0f;
  166.     shadowProjectionMatrix[10] = 1.0f;
  167.     shadowProjectionMatrix[15] = 1.0f;
  168.  
  169.     // make projektion
  170.     shadowProjectionMatrix[11] = -1.0 / shadowLightPosition[2];
  171.     shadowProjectionMatrix[15] = 0.0;
  172. }
  173.  
  174. void setViewProjection()
  175. {
  176.     if (!perspectiveMode)
  177.     {
  178.         glMatrixMode(GL_MODELVIEW);
  179.         glLoadIdentity();
  180.         glTranslatef(0, 0, -5);
  181.  
  182.         glMatrixMode(GL_PROJECTION);
  183.         glLoadIdentity();
  184.         glOrtho(-10.0, 10.0, -6.0, 6.0, nearClippingPlane, farClippingPlane);
  185.     }
  186.     else
  187.     {
  188.         glMatrixMode(GL_MODELVIEW);
  189.         glLoadIdentity();
  190.         camera.ApplyCameraTransformation();
  191.  
  192.         glMatrixMode(GL_PROJECTION);
  193.         glLoadIdentity();
  194.         gluPerspective(fovy, (float)window_width/(float)window_height,
  195.             nearClippingPlane, farClippingPlane );
  196.     }
  197. }
  198.  
  199.  
  200. void display()
  201. {
  202.     clearBuffers();
  203.     setViewProjection();
  204.     setLightSource();
  205.  
  206.     if (!perspectiveMode)
  207.     {
  208.         drawSpheres();
  209.         drawGround();
  210.     }
  211.     else
  212.     {
  213.         setShadowProjectionMatrix();
  214.        
  215.         // Draw with shadow
  216.         // TO...
  217.         drawSpheres();
  218.         drawGround();
  219.         // ...DO
  220.     }
  221.  
  222.     glutSwapBuffers();
  223. }
  224.  
  225. void KeyPressed(unsigned char key, int x, int y)
  226. {
  227.     const float step = 0.25;
  228.  
  229.     switch(key)
  230.     {
  231.     case 27:
  232.     case 'q':
  233.     case 'Q':
  234.         exit(0);
  235.         break;
  236.     case 'w':
  237.         camera.MoveCameraForward(step);
  238.         glutPostRedisplay();
  239.         break;
  240.     case 's':
  241.         camera.MoveCameraForward(-step);
  242.         glutPostRedisplay();
  243.         break; 
  244.     case 'd':
  245.         camera.MoveCameraRightwards(step);
  246.         glutPostRedisplay();
  247.         break;
  248.     case 'a':
  249.         camera.MoveCameraRightwards(-step);
  250.         glutPostRedisplay();
  251.         break; 
  252.     case 'r':
  253.         camera.MoveCameraUpwards(step);
  254.         glutPostRedisplay();
  255.         break;
  256.     case 'f':
  257.         camera.MoveCameraUpwards(-step);
  258.         glutPostRedisplay();
  259.         break;
  260.     case 'c':
  261.         perspectiveMode = !perspectiveMode;
  262.         glutPostRedisplay();
  263.         break;
  264.  
  265.     }
  266. }
  267.  
  268. void MouseClicked(int button, int state, int x, int y){
  269.     rotating = false;
  270.     movingLight = false;
  271.     if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
  272.     {
  273.         old_x = x;
  274.         old_y = y;
  275.         rotating = true;
  276.     }
  277.     else if(button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN)
  278.     {
  279.         old_x = x;
  280.         old_y = y;
  281.         movingLight = true;
  282.     }
  283. }
  284.  
  285. void MouseMoves(int x, int y){
  286.     if(rotating && perspectiveMode){
  287.         if(x<window_width && x>=0 && y<window_height && y>=0){
  288.  
  289.             camera.RotateCamera(y - old_y, x - old_x);
  290.  
  291.             old_x = x;
  292.             old_y = y;
  293.             glutPostRedisplay();
  294.         }
  295.     }
  296.     if(movingLight && perspectiveMode){
  297.         shadowLightPosition[0] += (x - old_x);
  298.         shadowLightPosition[1] -= (y - old_y);
  299.         old_x = x;
  300.         old_y = y;
  301.         glutPostRedisplay();
  302.     }
  303. }
  304.  
  305. void WindowReshape(int w, int h)
  306. {
  307.     window_width = w;
  308.     window_height = h;
  309.  
  310.     glViewport(0,0,window_width, window_height);
  311.     glutPostRedisplay();
  312. }
  313.  
  314. void initGlut(int* argc, char* argv[])
  315. {
  316.     glutInit(argc, argv);
  317.     glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_STENCIL);
  318.  
  319.     glutInitWindowSize(window_width, window_height);
  320.     glutInitWindowPosition(window_posx, window_posy);
  321.     glutCreateWindow("Spheres - Stencil - Shadow");
  322.  
  323.     //registering callbacks
  324.     glutKeyboardFunc(KeyPressed);
  325.     glutDisplayFunc(display);
  326.  
  327.     glutMouseFunc(MouseClicked);
  328.     glutMotionFunc(MouseMoves);
  329.     glutReshapeFunc(WindowReshape);
  330.  
  331. }
  332. //**** Glut
  333.  
  334. int main(int argc, char* argv[])
  335. {
  336.     initGlut(&argc, argv);
  337.     initGL();
  338.  
  339.     clearBuffers();
  340.  
  341.     int depthBits;
  342.     glGetIntegerv(GL_DEPTH_BITS, &depthBits);
  343.     cout<<"Depth resolution = "<<depthBits<<endl;
  344.  
  345.     glutMainLoop();
  346.     return 0;
  347. }
  348.  


und der anderen beiden Dateien:

Code:
  1.  
  2. #include "CameraSteering.hh"
  3.  
  4. #include <GL/glew.h>
  5. #include <iostream>
  6.  
  7. using namespace std;
  8.  
  9. CameraSteering::
  10. CameraSteering(const float initPosX,
  11.            const  float initPosY,
  12.            const float initPosZ)
  13. {
  14.   float val = 1.0;
  15.  
  16.  
  17.   tiltMatrix_[0]=val;
  18.   panTranslateMatrix_[0]=val;
  19.  
  20.   unsigned int n=5;
  21.   for(unsigned int i=1; i<16; i++){
  22.     if(i%n==0) {
  23.       val = 1.0;
  24.       n+=5;
  25.     }
  26.     else val = 0.0;
  27.  
  28.     tiltMatrix_[i]=val;
  29.     panTranslateMatrix_[i]=val;
  30.  
  31.   }
  32.   panTranslateMatrix_[12]=initPosX;
  33.   panTranslateMatrix_[13]=initPosY;
  34.   panTranslateMatrix_[14]=initPosZ;
  35.  
  36. }
  37.  
  38.  
  39. void printMatrix4x4(float* matrix)
  40. {
  41.  for(unsigned int i=0; i<16; i++) {
  42.     if(i%4==0) cout<<endl;
  43.     cout<<matrix[i]<<"\t";
  44.   }
  45.   cout<<endl;
  46. }
  47.  
  48. void CameraSteering::
  49. PrintMatrices()
  50. {
  51.   cout<<"nick matrix:\n";
  52.   printMatrix4x4(tiltMatrix_);
  53.   cout<<"pan-translate matrix:\n";
  54.   printMatrix4x4(panTranslateMatrix_);
  55.  //  cout<<"full matrix:\n";
  56. //   printMatrix4x4(fullCameraTransform_);
  57. }
  58.  
  59. void CameraSteering::
  60. TranslateCamera_(const float x, const float y, const float z)
  61. {
  62.   glPushAttrib(GL_TRANSFORM_BIT);
  63.   glMatrixMode(GL_MODELVIEW);
  64.   glPushMatrix();
  65.   // >>>
  66.   glLoadIdentity();
  67.   glTranslatef(x, y, z);
  68.   glMultMatrixf(panTranslateMatrix_);
  69.   glGetFloatv(GL_MODELVIEW_MATRIX, panTranslateMatrix_);
  70.   // <<<
  71.   glPopMatrix();
  72.   glPopAttrib();
  73. }
  74.  
  75. /** Positive distance moves camera forwards, negative distance moves it
  76.  *  backwards.
  77.  */
  78. void CameraSteering::
  79. MoveCameraForward(const float distance)
  80. {
  81.   TranslateCamera_(0.0, 0.0, distance);
  82. }
  83.  
  84. void CameraSteering::
  85. MoveCameraRightwards(const float distance)
  86. {
  87.   TranslateCamera_(-distance, 0.0, 0.0);
  88. }
  89.  
  90. void CameraSteering::
  91. MoveCameraUpwards(const float distance)
  92. {
  93.   TranslateCamera_(0.0, -distance, 0.0);
  94. }
  95.  
  96. void CameraSteering::
  97. RotateCamera(const float rotXDeg, const float rotYDeg)
  98. {
  99.   glPushAttrib(GL_TRANSFORM_BIT);
  100.   glMatrixMode(GL_MODELVIEW);
  101.   glPushMatrix();
  102.   // >>>
  103.   glLoadIdentity();
  104.   glRotatef(rotYDeg, 0.0, 1.0, 0.0);
  105.   glMultMatrixf(panTranslateMatrix_);
  106.   glGetFloatv(GL_MODELVIEW_MATRIX, panTranslateMatrix_);
  107.  
  108.   glLoadIdentity();
  109.   glRotatef(rotXDeg, 1.0, 0.0, 0.0);
  110.   glMultMatrixf(tiltMatrix_);
  111.   glGetFloatv(GL_MODELVIEW_MATRIX, tiltMatrix_);
  112.   // <<<
  113.   glPopMatrix();
  114.   glPopAttrib();
  115. }
  116.  
  117. void CameraSteering::
  118. ApplyCameraTransformation()
  119. {
  120.   glMatrixMode(GL_MODELVIEW);
  121.   glLoadMatrixf(tiltMatrix_);
  122.   glMultMatrixf(panTranslateMatrix_);  
  123. }
  124.  


Code:
  1.  
  2. #include "SubDivSphere.hh"
  3. #include <cmath>
  4. #include <GL/glew.h>
  5.  
  6. using namespace std;
  7.  
  8. void SubDivSphere::
  9. DrawSphere(const int numSubDivs)
  10. {
  11.   float t0[] = {0.0, 0.0, 1.0}; //tip
  12.   float t1[] = {0.0, 0.942809, -0.333333}; //basetip
  13.   float t2[] = {-0.816497, -0.471405, -0.333333}; //base left
  14.   float t3[] = {0.816497, -0.471405, -0.333333}; //base right
  15.  
  16.   SubDivTriangle(t0, t1, t2, numSubDivs);
  17.   SubDivTriangle(t0, t3, t1, numSubDivs);
  18.   SubDivTriangle(t0, t2, t3, numSubDivs);
  19.   SubDivTriangle(t3, t2, t1, numSubDivs);
  20.  
  21. }
  22.  
  23. void SubDivSphere::
  24. DrawTriangle(const float* const p0,
  25.          const float* const p1,
  26.          const float* const p2)
  27. {
  28.   glBegin(GL_TRIANGLES);
  29.   glNormal3fv(p0);
  30.   glVertex3fv(p0);
  31.   glNormal3fv(p1);
  32.   glVertex3fv(p1);
  33.   glNormal3fv(p2);
  34.   glVertex3fv(p2);
  35.   glEnd();
  36. }
  37.  
  38. void SubDivSphere::
  39. Normalize(float* p)
  40. {
  41.   float normL2 = 0.0;
  42.   unsigned int i;
  43.   for(i=0; i<3; i++) normL2+=(p[i]*p[i]);
  44.   normL2 = sqrt(normL2);
  45.   if(normL2>0.0)
  46.     for(i=0; i<3; i++) p[i]/=normL2;
  47. }
  48.  
  49. void SubDivSphere::
  50. SubDivTriangle(const float* const p0,
  51.            const float* const p1,
  52.            const float* const p2,
  53.            const int SubDivs)
  54. {
  55.   if(SubDivs==0)
  56.     DrawTriangle(p0, p1, p2);
  57.   else {
  58.     float q0[3];
  59.     float q1[3];
  60.     float q2[3];
  61.     /*
  62.      *          p2
  63.      *          /\
  64.      *      q2 /__\ q1
  65.      *        /\  /\
  66.      *       /__\/__\
  67.      *      p0  q0   p1
  68.      */
  69.     for(unsigned int i=0; i<3; i++){
  70.       q0[i] = 0.5*(p0[i]+p1[i]);
  71.       q1[i] = 0.5*(p1[i]+p2[i]);
  72.       q2[i] = 0.5*(p0[i]+p2[i]);
  73.     }
  74.     Normalize(q0);
  75.     Normalize(q1);
  76.     Normalize(q2);
  77.     SubDivTriangle(p0, q0, q2, SubDivs-1);
  78.     SubDivTriangle(q0, p1, q1, SubDivs-1);
  79.     SubDivTriangle(q1, p2, q2, SubDivs-1);
  80.  
  81.     SubDivTriangle(q1, q2, q0, SubDivs-1);
  82.   }
  83. }
  84.  


Nach oben
 Profil  
Mit Zitat antworten  
BeitragVerfasst: Di Dez 08, 2009 14:27 
Offline
DGL Member

Registriert: Do Mai 30, 2002 18:48
Beiträge: 1617
soweit ich das auf die schnelle gesehen habe, schaltet DrawGround GL_LIGHTING ab und das attribut wird danach nicht zurückgesetzt. Schätze du musst das wieder irgendwo anschalten.


Nach oben
 Profil  
Mit Zitat antworten  
BeitragVerfasst: Di Dez 08, 2009 14:53 
Offline
DGL Member

Registriert: Fr Dez 04, 2009 15:56
Beiträge: 6
Hmmh. Das stimmt, aber die Methode setLightSource aktiviert die Beleuchtung. Es muss irgendetwas im Zusammenhang mit glMaterial sein, denn wenn man GL_DIFFUSE nicht aufruft, dann sind dei Kugeln grau und man kann einen Lichteinfall von rechts oben sehen.


Nach oben
 Profil  
Mit Zitat antworten  
BeitragVerfasst: Di Dez 08, 2009 15:26 
Offline
DGL Member

Registriert: Mo Nov 06, 2006 19:15
Beiträge: 172
So beim schief drauf Gucken merke ich, dass x und y vom Typ unsigned int sind und du durch Ganzzahlen teilst. Weißt schon was dabei passiert, oder? :mrgreen:

... und warum Delphi mit dem Operator div eine Unterscheidung zum / für ganzzahlige Division bereitstellt.


Nach oben
 Profil  
Mit Zitat antworten  
BeitragVerfasst: Mi Dez 09, 2009 11:13 
Offline
DGL Member

Registriert: Fr Dez 04, 2009 15:56
Beiträge: 6
Danke, dass war es tatsächlich mit dem Teilen von ganzen Zahlen...


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 8 Beiträge ] 
Foren-Übersicht » Programmierung » OpenGL


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 2 Gäste


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
  Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
[ Time : 0.009s | 16 Queries | GZIP : On ]