dev.gamez.lv Forum Index dev.gamez.lv
Latvian Game Developers Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups 

Objekts
Goto page 1, 2  Next
 
dev.gamez.lv Forum Index -> OpenGL
View previous topic :: View next topic  
Author Message
coderpp



Joined: 20 Aug 2005
Posts: 167
Location: Rīga, Koknese, Gajiena

PostPosted: Sat Oct 22, 2005 11:37 am    Post subject: Objekts

Kaa es varu panaakt lai objekts kustas ar noteiktu atrumu?
Back to top
View user's profile Send e-mail
bubu
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 23 Mar 2004
Posts: 3223
Location: Riga

PostPosted: Sat Oct 22, 2005 12:49 pm    Post subject:

Maini tā pozīciju atkarībā no laika. S=V*t, kur V ir tas noteiktais ātrums. Zinot iepriekšējo pozīciju S0, nākamo var izrēķināt S1 = S0 + V*deltaT, kur deltaT ir pagājušais laiks starp iepriekšējo kadru un tekošo kadru.
Back to top
View user's profile Send e-mail
coderpp



Joined: 20 Aug 2005
Posts: 167
Location: Rīga, Koknese, Gajiena

PostPosted: Sun Oct 23, 2005 9:29 am    Post subject:

Man nesanaca. vai arii nesapratu. Objekts ir 2D grafika un visi logi tasiiti ar openGL.
Vai tu vari apmeeram paraadiit ka tam kodam jaiskatas?
Back to top
View user's profile Send e-mail
bubu
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 23 Mar 2004
Posts: 3223
Location: Riga

PostPosted: Sun Oct 23, 2005 12:50 pm    Post subject:

Spēles main loops (pseidokodā)
Code:
float T = tagadeejais_laiks();
while (speeleejam==true) {
  float dT = tagadeejais_laiks() - T;
  kustinam_objektu1_par_nobiidi( dT * V1 ); // V1,V2 kā skalāri lielumi
  kustinam_objektu2_par_nobiidi( dT * V2 );
  ...
  ziimeejam_bildi();
  T = tagadeejais_laiks();
}
kustinam_objektu_par_nobiidi - funkcija pabīda objektu vajadzīgā virzienā (V kā vektoriālu lielumu) par parametrā padotu nobīdi (pikseļu skaitu, metru skaitu, whatever).

Šis kods gan tikai labi neuvedīsies pie ļoti zemiem fps. Ja grib korektāku kustību, tad to dT laikam vajadzētu ierobežot no augšas.
Back to top
View user's profile Send e-mail
coderpp



Joined: 20 Aug 2005
Posts: 167
Location: Rīga, Koknese, Gajiena

PostPosted: Mon Oct 24, 2005 8:06 am    Post subject:

Un kaa pierakstiit tos V1, V2, lai nepiesienas ka nav defineeti?
Pareejo laikam jau sapratu.
Back to top
View user's profile Send e-mail
bubu
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 23 Mar 2004
Posts: 3223
Location: Riga

PostPosted: Mon Oct 24, 2005 7:31 pm    Post subject:

Tak V1, V2, utt ir objektu ātrumi, kurus tu pats uzdod tak cik gribi 10, 100, 11233 vai sazin cik vēl. Jo lielāks skaitlis jo ātrāk kustēsies.
Back to top
View user's profile Send e-mail
coderpp



Joined: 20 Aug 2005
Posts: 167
Location: Rīga, Koknese, Gajiena

PostPosted: Thu Oct 27, 2005 11:32 am    Post subject:

kustinam_objektu1_par_nobiidi( dT * V1 ); kustinam_objektu2_par_nobiidi( dT * V2 );
tajaas rindaas ir dazadi prieksmeti ar dazadiem atrumiem. ja es gribu lai otrs perieksmets ir tikpat atrs as ari tur varu rakstiit to V.

kustinam_objektu_par_nobiidi -kā sitais japieraksta, jaliek objekta nosaukums? Ja ja tad kaapec man piesienas "no match flor call (obj_type)(float)" vai tamliidiigi.
Back to top
View user's profile Send e-mail
kaszu



Joined: 28 Dec 2004
Posts: 103
Location: Iceberg, Northpole

PostPosted: Thu Oct 27, 2005 5:04 pm    Post subject:

da ne tak, pienemsim, ka V1 ir vektors un kustinam_objektu1_par_nobiidi ir funkcija, kurai tiek nodots vektors:
Code:

Kaut kur ieprieks ir definets x1 un y1;

void kustinam_objektu1_par_nobiidi(Vector V)
{
    x1+=V.x;
    y1+=V.y;
}


V1*dt piereizina skaitli dt vektora komponenteem.
Back to top
View user's profile Send e-mail Visit poster's website
coderpp



Joined: 20 Aug 2005
Posts: 167
Location: Rīga, Koknese, Gajiena

PostPosted: Sat Oct 29, 2005 10:15 am    Post subject:

x1+=V.x;
y1+=V.y;

ko isti dara sis te rindinas un vai tas punkts ir domats reizinasanai?
Back to top
View user's profile Send e-mail
gazz



Joined: 03 Jan 2004
Posts: 355
Location: Teika

PostPosted: Sat Oct 29, 2005 11:21 am    Post subject:

ok - enough! cik daudz tu no programmeeshanas zini? ja tu uzdod shaadus jautaajumus tad vispirms tev vaidzeetu izskriet cauri vismaz vienam izmantotaas programmeeshanas valodas tutoriaalim un saprast kas ir kas.
Back to top
View user's profile Send e-mail
elvman
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 09 Apr 2003
Posts: 1278
Location: Kuldiga

PostPosted: Sat Oct 29, 2005 12:36 pm    Post subject:

Alberts traks dzeks! Apsveicami. Neko nesaprotot no programmeshanas (nu droshi vien tik traki nav) uzreiz kjeras pie objektu kustinaashanas. Kaut taadu buutu vairaak.

P.S. Bet speelju brogrammeetaajiem fiziku gan vajadzeetu maaciities
_________________
long time; /* know C */
Back to top
View user's profile Visit poster's website
coderpp



Joined: 20 Aug 2005
Posts: 167
Location: Rīga, Koknese, Gajiena

PostPosted: Sat Oct 29, 2005 3:43 pm    Post subject:

Luudu vismaz pasakiet kaa pierakstiit tagadeejais_laiks(), lai nepiesienas linker error.
Back to top
View user's profile Send e-mail
bubu
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 23 Mar 2004
Posts: 3223
Location: Riga

PostPosted: Sat Oct 29, 2005 7:22 pm    Post subject:

Atkarīgs no izmantojamās valodas, gan arī kompilētāja, gan arī izstrādes vides/OS.
Back to top
View user's profile Send e-mail
elvman
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 09 Apr 2003
Posts: 1278
Location: Kuldiga

PostPosted: Sat Oct 29, 2005 7:27 pm    Post subject:

C++ tagadeejais laiks (Windows'aa) buutu GetTickCount()
_________________
long time; /* know C */
Back to top
View user's profile Visit poster's website
coderpp



Joined: 20 Aug 2005
Posts: 167
Location: Rīga, Koknese, Gajiena

PostPosted: Mon Oct 31, 2005 7:29 am    Post subject:

Es darbojos ar C++. Man vienalga nekas nesanaak. palaiz programmu un viss nekas nenotiek. Vai varat paradiit uz koda?

Code:
#include <windows.h>
#include <GL/glut.h>

#define MAX_VERTICES 2000 // Max number of vertices (for each object)
#define MAX_POLYGONS 2000 // Max number of polygons (for each object)

typedef struct{
    float x,y;
}vertex_type;

typedef struct{
    int a,b,c;
}polygon_type;

typedef struct {
    vertex_type vertex[MAX_VERTICES];
    polygon_type polygon[MAX_POLYGONS];   
} obj_type, *obj_type_ptr;

int screen_width=1024;
int screen_height=768;

obj_type cube =
{
    {     
       3,2,  //v0
       1,4,  //v1
       1,6,  //v2
       3,8,  //v3
       5,8,   //v4
       7,6,   //v5
       7,4,   //v6
       5,2,  //v7
    },
    {
            0,1,2,
            0,2,3,
            0,3,4,
            4,5,0,
            5,6,0,
            6,7,0,
    }, 
};
void  init(void)
{
    glClearColor(0.0, 0.0, 0.2, 0.0); // This clear the background color to dark blue
    glShadeModel(GL_SMOOTH); // Type of shading for the polygons
    // Viewport transformation
    glViewport(0,0,screen_width,screen_height); 
    // Projection transformation
    glMatrixMode(GL_PROJECTION); // Specifies which matrix stack is the target for matrix operations
    glLoadIdentity(); // We initialize the projection matrix as identity
    gluPerspective(45.0f,(GLfloat)screen_width/(GLfloat)screen_height,1.0f,1000.0f); // We define the "viewing volume"
    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) 
}       
void resize (int width, int height)
{
    screen_width=width; // We obtain the new screen width values and store it
    screen_height=height; // Height value
    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // We clear both the color and the depth buffer so to draw the next frame
    glViewport(0,0,screen_width,screen_height); // Viewport transformation
    glMatrixMode(GL_PROJECTION); // Projection transformation
    glLoadIdentity(); // We initialize the projection matrix as identity
    gluPerspective(45.0f,(GLfloat)screen_width/(GLfloat)screen_height,1.0f,1000.0f);
    glutPostRedisplay (); // This command redraw the scene (it calls the same routine of glutDisplayFunc)
}
void  display(void)
{
    int l_index;
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // This clear the background color to dark blue
    glMatrixMode(GL_MODELVIEW); // Modeling transformation
    glLoadIdentity(); // Initialize the model matrix as identity   
    glTranslatef (x1, y1, -50);
    glBegin(GL_TRIANGLES); // GlBegin and glEnd delimit the vertices that define a primitive (in our case triangles)
    for (l_index=0;l_index<200;l_index++)
    {             
        glVertex2f( cube.vertex[ cube.polygon[l_index].a ].x,
                    cube.vertex[ cube.polygon[l_index].a ].y);           
        glVertex2f( cube.vertex[ cube.polygon[l_index].b ].x,
                    cube.vertex[ cube.polygon[l_index].b ].y);             
        glVertex2f( cube.vertex[ cube.polygon[l_index].c ].x,
                    cube.vertex[ cube.polygon[l_index].c ].y);
    }
    glEnd();   
   
    glFlush(); // This force the execution of OpenGL commands
    glutSwapBuffers(); // In double buffered mode we invert the positions of the visible buffer and the writing buffer
}
int main(int argc, char **argv)

    glutInit(&argc, argv);   
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize(screen_width,screen_height);
    glutInitWindowPosition(0,0);
    glutCreateWindow("www.spacesimulator.net - 3d engine tutorials: Tutorial 3");   
    glutDisplayFunc(display);
    glutIdleFunc(display);
    glutReshapeFunc (resize);
    init();
    glutMainLoop();
    return(0);   
}


Last edited by coderpp on Tue Nov 01, 2005 7:42 am; edited 1 time in total
Back to top
View user's profile Send e-mail
Display posts from previous:   
dev.gamez.lv Forum Index -> OpenGL All times are GMT + 2 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group