Модераторы: Rickert, Alexeis, BorisVorontsov
  

Поиск:

Ответ в темуСоздание новой темы Создание опроса
> *.3ds модель 
:(
    Опции темы
Shade2015
Дата 3.6.2015, 11:24 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 16
Регистрация: 26.4.2015

Репутация: нет
Всего: нет




Всем привет! Посмотрите, пожалуйста, в чем проблема, укажите на ошибки)))))хочу использовать модель 3ds в своем проекте- солнечная сиситема...загружает модель норм(т.к. отдельно от проекта- выводит), а вот, когда соединяю мой проект и модель...все ломается, выводит только планеты, а где же модель???( Вот главная функция

Код


void Init(void)
{
    time = 2.552f;
    timeSpeed = 0.1f;
    // reset controls
    controls.forward = false;
    controls.backward = false;
    controls.left = false;
    controls.right = false;
    controls.rollRight = false;
    controls.rollLeft = false;
    controls.pitchDown = false;
    controls.pitchUp = false;
    controls.yawLeft = false;
    controls.yawRight = false;
    
    User.Coord.x=0;
    User.Coord.z=0;
    User.Coord.y=0;
    User.Rotation.x=0;
    User.Rotation.y=0;
    User.Rotation.z=0;
}
void Inic(){
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glShadeModel(GL_SMOOTH);
    glEnable(GL_TEXTURE_2D);
    
    glEnable(GL_DEPTH_TEST); // We enable the depth test (also called z buffer)
    glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); // Polygon rasterization mode (polygon filled

    Load3DS (&object,"hst.3ds");

    object.id_texture=LoadBitmap("1.bmp"); // The Function LoadBitmap() return the current texture ID
    
    // If the last function returns -1 it means the file was not found so we exit from the program
    if (object.id_texture==-1)
    {
        MessageBox(NULL,"Image file: texture not found", "Zetadeck",MB_OK | MB_ICONERROR);
        exit (0);
    }
}
class ring_t
{
public:
    float r, g, b; //цвет
 
    float inner_radius, outer_radius; //внутренний и внешний радиусы
    float az, ax; //углы поворота кольца относительно осей z, x (исходная позиция - в плоскости xy) [град]
 
    ring_t(float r, float g, float b, float inner_radius, float outer_radius, float az, float ax):
        r(r), g(g), b(b), inner_radius(inner_radius), outer_radius(outer_radius), az(az), ax(ax)
    {}
 
    void render(void)
    {
        glPushMatrix();
        glRotatef(az, 0, 0, 1);
        GLUquadricObj *qu = gluNewQuadric();
        gluQuadricTexture(qu, GL_TRUE);
        gluQuadricDrawStyle(qu, GLU_FILL);
        glColor3f(r, g, b);
        gluDisk(qu, inner_radius, outer_radius, segments_count, segments_count);
        gluDeleteQuadric(qu);
        glPopMatrix();
        glutSwapBuffers();
    }
};

class planet_t;
static planet_t *core;
 
class planet_t
{
public:
    unsigned int texture;
    float planet_radius; //радиус планеты
    float orbit_radius; //радиус орбиты (окружность)
    float az, ax; //углы поворота орбиты относительно осей z, x (исходная позиция - в плоскости xy) [град]
    float T; //период обращения [с]
    float dT; //смещение [с]
 
    std::list<ring_t> rings; //кольца
    std::list<planet_t> sats; //спутники
 
    planet_t(  unsigned int texture, float planet_radius, float orbit_radius, float az, float ax, float T, float dT):
        texture(texture), planet_radius(planet_radius), orbit_radius(orbit_radius), az(az), ax(ax), T(T), dT(dT)
    {}

    void render(const float t)
    {
    glPushMatrix();
    glRotatef(az, 0, 0, 1);
        glRotatef(ax, 1, 0, 0);
        
if (orbit_radius > 0)
        {
            float tmp = t + dT; //время с учетом смещения
            int n = tmp / T; //кол-во оборотов
            tmp -= n * T; //время от начала оборота
            tmp *= 360.0 / T; //угол
glTranslatef(orbit_radius * cos(tmp * RAD_IN_DEG),orbit_radius * sin(tmp * RAD_IN_DEG),0);
}
else{glTranslatef(0,0,0);}
if (this == core)
        {
            float p0[4] = {0, 0, 1, 0};
         glLightfv(GL_LIGHT0,GL_POSITION, p0);
            render_planet();
            float p1[4] = {0, 0, 0, 1};
            glLightfv(GL_LIGHT0, GL_POSITION, p1);
            
        }
        else
        { 
        render_planet();
        }

        render_rings_and_sats(t);
        glPopMatrix(); 
        glFlush(); 
}
 void render_planet(void)
    {   GLUquadricObj *q = gluNewQuadric();
        glEnable(GL_TEXTURE_2D);
        gluQuadricTexture(q, GL_TRUE);
        gluQuadricDrawStyle(q, GLU_FILL);
        glBindTexture(GL_TEXTURE_2D, texture);
    if(planet_radius==1)
         { 
       glClear( GL_DEPTH_BUFFER_BIT);
         glDisable(GL_LIGHTING);
         gluSphere(q,  planet_radius, segments_count, segments_count);
        glEnable(GL_LIGHTING);
        }
    if(planet_radius<1) {  
    
      glRotatef(User.Rotation.z, 0,0,1); 
      gluSphere(q,  planet_radius, segments_count, segments_count);
      User.Rotation.z+=0.1;
        
    }  
        gluDeleteQuadric(q);  
}
 void render_rings_and_sats(const float t)
{ for(std::list<ring_t>::iterator i = rings.begin();i != rings.end();i++)
i->render();
for(std::list<planet_t>::iterator i = sats.begin();i != sats.end();i++)
i->render(t);  }
};

//GL-функции
void drawcube(){
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, photo_tex);
glBegin(GL_QUADS);

    glTexCoord2f(0.0f, 0.0f);    glVertex3f(-10, -10, 10);
    glTexCoord2f(1.0f, 0.0f);    glVertex3f(10, -10, 10);
    glTexCoord2f(1.0f, 1.0f);    glVertex3f(10, 10, 10);
    glTexCoord2f(0.0f, 1.0f);    glVertex3f(-10, 10, 10);
    // new face
    glTexCoord2f(0.0f, 0.0f);    glVertex3f(10, 10, 10);
    glTexCoord2f(1.0f, 0.0f);    glVertex3f(10, 10, -10);
    glTexCoord2f(1.0f, 1.0f);    glVertex3f(10, -10, -10);
    glTexCoord2f(0.0f, 1.0f);    glVertex3f(10, -10, 10);
    // new face
    glTexCoord2f(0.0f, 0.0f);    glVertex3f(10, 10, -10);
    glTexCoord2f(1.0f, 0.0f);    glVertex3f(-10, 10, -10);
    glTexCoord2f(1.0f, 1.0f);    glVertex3f(-10, -10, -10);
    glTexCoord2f(0.0f, 1.0f);    glVertex3f(10, -10, -10);
    // new face
    glTexCoord2f(0.0f, 0.0f);    glVertex3f(-10, -10, -10);
    glTexCoord2f(1.0f, 0.0f);    glVertex3f(-10, -10, 10);
    glTexCoord2f(1.0f, 1.0f);    glVertex3f(-10, 10, 10);
    glTexCoord2f(0.0f, 1.0f);    glVertex3f(-10, 10, -10);
    // new face
    glTexCoord2f(0.0f, 0.0f);    glVertex3f(-10, 10, -10);
    glTexCoord2f(1.0f, 0.0f);    glVertex3f(10, 10, -10);
    glTexCoord2f(1.0f, 1.0f);    glVertex3f(10, 10, 10);
    glTexCoord2f(0.0f, 1.0f);    glVertex3f(-10, 10, 10);
    // new face
    glTexCoord2f(0.0f, 0.0f);    glVertex3f(-10, -10, -10);
    glTexCoord2f(1.0f, 0.0f);    glVertex3f(10, -10, -10);
    glTexCoord2f(1.0f, 1.0f);    glVertex3f(10, -10, 10);
    glTexCoord2f(0.0f, 1.0f);    glVertex3f(-10, -10, 10);
    

glEnd();}
void drawmod(){  int l_index;

   
 
     glBindTexture(GL_TEXTURE_2D, object.id_texture); // We set the active texture 
    glBegin(GL_TRIANGLES); // glBegin and glEnd delimit the vertices that define a primitive (in our case triangles)
    for (l_index=0;l_index<object.polygons_qty;l_index++)
    {
        //----------------- FIRST VERTEX -----------------
        // Texture coordinates of the first vertex
        glTexCoord2f( object.mapcoord[ object.polygon[l_index].a ].u,
                      object.mapcoord[ object.polygon[l_index].a ].v);
        // Coordinates of the first vertex
        glVertex3f( object.vertex[ object.polygon[l_index].a ].x,
                    object.vertex[ object.polygon[l_index].a ].y,
                    object.vertex[ object.polygon[l_index].a ].z); //Vertex definition

        //----------------- SECOND VERTEX -----------------
        // Texture coordinates of the second vertex
        glTexCoord2f( object.mapcoord[ object.polygon[l_index].b ].u,
                      object.mapcoord[ object.polygon[l_index].b ].v);
        // Coordinates of the second vertex
        glVertex3f( object.vertex[ object.polygon[l_index].b ].x,
                    object.vertex[ object.polygon[l_index].b ].y,
                    object.vertex[ object.polygon[l_index].b ].z);
        
        //----------------- THIRD VERTEX -----------------
        // Texture coordinates of the third vertex
        glTexCoord2f( object.mapcoord[ object.polygon[l_index].c ].u,
                      object.mapcoord[ object.polygon[l_index].c ].v);
        // Coordinates of the Third vertex
        glVertex3f( object.vertex[ object.polygon[l_index].c ].x,
                    object.vertex[ object.polygon[l_index].c ].y,
                    object.vertex[ object.polygon[l_index].c ].z);
    }
    glEnd();   
}
void   Display()
{  
time += timeSpeed;
    
    if (controls.forward) camera.forward();        if (controls.backward) camera.backward();
    if (controls.left) camera.left();            if (controls.right) camera.right();
    if (controls.yawLeft) camera.yawLeft();        if (controls.yawRight) camera.yawRight();
    if (controls.rollLeft) camera.rollLeft();    if (controls.rollRight) camera.rollRight();
    if (controls.pitchUp) camera.pitchUp();        if (controls.pitchDown) camera.pitchDown();
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3f(1.0, 1.0, 1.0);
// set up the perspective matrix for rendering the 3d world
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslated(User.Coord.x,User.Coord.y, User.Coord.z);
glRotatef(User.Rotation.x,1,0,0);
glRotatef(User.Rotation.y,0,1,0);
    // perform the camera orientation transform
    camera.transformOrientation();
    drawcube();
    // perform the camera translation transform
    camera.transformTranslation();
core->render(t * t_factor);
   glMatrixMode(GL_MODELVIEW); // Modeling transformation
    glLoadIdentity(); // Initialize the model matrix as identity
    glTranslatef(0.0,0.0,0.0); // We move the object forward (the model matrix is multiplied by the translation matrix)
    rotation_x = rotation_x + rotation_x_increment;
    rotation_y = rotation_y + rotation_y_increment;
    rotation_z = rotation_z + rotation_z_increment;

    if (rotation_x > 359) rotation_x = 0;
    if (rotation_y > 359) rotation_y = 0;
    if (rotation_z > 359) rotation_z = 0;

    glRotatef(rotation_x,1.0,0.0,0.0); // Rotations of the object (the model matrix is multiplied by the rotation matrices)
    glRotatef(rotation_y,0.0,1.0,0.0);
    glRotatef(rotation_z,0.0,0.0,1.0);
drawmod();
 glFlush();

}

 void Reshape(GLint width, GLint height)
{   
GLint windW, windH;
GLfloat aspect;
if (!width) return;
glFinish();
windW = width;
windH = height;
aspect = (GLfloat)windW / (GLfloat)windH;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(100.0f, aspect, 0.05f, 50.0f);
glViewport (0, 0, windW, windH);
glutPostRedisplay();
}


static void Timer(int value)
{
 t += dt / 1000.0;
 glutPostRedisplay();
 glutTimerFunc(dt, Timer, 0);
}

int main(int argc, char *argv[])
{   glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize(width, height);
    glutCreateWindow("planet system");
    glutDisplayFunc(Display);
    glutIdleFunc(Display);
    glutReshapeFunc(Reshape);
    
    Init();
    Inic();

    planet_t core(tex2, 1, -1, 0, 0, 0, 0);
    ::core = &core;
    core.sats.push_back(planet_t(tex4, 0.1, 1.3, 0, 0, 5, 0));
    core.sats.push_back(planet_t(tex5, 0.16, 1.8, 0, 0, 10, 0));
    core.sats.push_back(planet_t(tex8, 0.25, 3.4, 0, 0, 14, 0));
    core.sats.push_back(planet_t(tex3, 0.2, 2.5, 0, 0, 12, 0));
    core.sats.back().sats.push_back(planet_t(tex1, 0.04, 0.3, 0, 0, 5, 0));
    core.sats.push_back(planet_t(tex6, 0.6, 5.6, 0, 0, 13, 0));
    core.sats.push_back(planet_t(tex7, 0.3, 6.8, 0, 0, 25, 0));
    core.sats.push_back(planet_t(tex1, 0.5, 4.5, 0, 0, 20, 0));
    core.sats.back().rings.push_back(ring_t(1, 1, 1, 0.7, 0.8, 0, 80));
    core.sats.back().rings.push_back(ring_t(1, 1, 1, 0.85, 0.9, 0, 80));
    core.sats.back().rings.push_back(ring_t(1, 1, 1, 0.95, 1, 0, 80));
    core.sats.push_back(planet_t(tex3, 0.2, 3, 0, 0, 15, 0));
    
 glutTimerFunc(dt, Timer, 0);
 glutMainLoop();
 
    return 0;
}
 


 smile   
PM MAIL   Вверх
  
Ответ в темуСоздание новой темы Создание опроса
Вы можете найти полезным что...
Alexeis
Rickert
  • Английская документация по DirectX лежит где-то здесь.
  • Английская документация по OpenGL лежит где-то там.
  • Гейм-дев у нас обсуждают где-то тут

Ждём вас! С уважением, Alexeis, Rickert.

 
0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | C/C++: Мультимедия, OpenGL/DirectX | Следующая тема »


 




[ Время генерации скрипта: 0.1275 ]   [ Использовано запросов: 22 ]   [ GZIP включён ]


Реклама на сайте     Информационное спонсорство

 
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности     Powered by Invision Power Board(R) 1.3 © 2003  IPS, Inc.