Allegro.cc Forums » The Depot » projectile physics

 This thread is locked; no one can reply to it.
 projectile physics
 altalena Member #13,639 October 2011 {"name":"607671","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/1\/0103dee20ab34629b707f92cac41a18a.png","w":2560,"h":1440,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/1\/0103dee20ab34629b707f92cac41a18a"}I'm trying to eventually make something that resembles Shadow of Chernobyl. Here's the projectile physics. There are no collisions yet, but I'm planning to have projectiles collide with the terrain by finding out each frame if it's height is above or below the terrain with the same x and y as the projectile.I'll try to upload an OpenGL template program later, if anyone wants to help me with implementing textures in it that would be cool, since I suck at learning new things in programming and learn best by example.edit: Here's the template program. I've improved the Perlin noise 2d algorithm to repeat every 65536 units instead of 256, and to behave the same with negative inputs as with positive inputs. ...At the briefest instant following creation all the matter of the universe was concentrated in a very small place, no larger than a grain of mustard. The matter at this time was very thin, so intangible, that it did not have real substance. It did have, however, a potential to gain substance and form and to become tangible matter. From the initial concentration of this intangible substance in its minute location, the substance expanded, expanding the universe as it did so. As the expansion progressed, a change in the substance occurred. This initially thin noncorporeal substance took on the tangible aspects of matter as we know it. From this initial act of creation, from this ethereally thin pseudosubstance, everything that has existed, or will ever exist, was, is, and will be formed. - the RaMBaN, 1194 - 1270ג וּשְׁאַבְתֶּם-מַיִם, בְּשָׂשׂוֹן, מִמַּעַיְנֵי, הַיְשׁוּעָה. - Yeshayahu 12:3
 Arthur Kalliokoski Second in Command February 2005 I got the NoisyTrees example to compile and run on linux by setting bool compatibility to 1, even though I'm not using an analog monitor. Otherwise it just said "Failed to create display". The template example wouldn't run with compatibility = 1.It appears the projectiles are dropping off in the distance due to gravity?To use textures: #SelectExpand 1 terrainimg = al_load_bitmap(terrain_name); 2 if(!terrainimg) 3 { 4 //al_show_native_message_box(0,"Error","Unable to load terrain file","",NULL,0); 5 fprintf(stderr,"Can't load terrain image\n"); 6 return 1; 7 } 8 9 terrainimgID = al_get_opengl_texture(terrainimg); 10 glBindTexture(GL_TEXTURE_2D,terrainimgID); 11 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); 12 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); 13 14 //Assuming you have one large image for terrain 15 terrainimg = al_load_bitmap(terrain_image_filename); 16 if(!terrainimg) 17 { 18 //al_show_native_message_box(0,"Error","Unable to load terrain file","",NULL,0); 19 fprintf(stderr,"Can't load terrain image\n"); 20 return 1; 21 } 22 23 terrainimgID = al_get_opengl_texture(terrainimg); //It needs a number to associate which image you want to show at the moment 24 glBindTexture(GL_TEXTURE_2D,terrainimgID); //the actual association 25 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); //make it look nicer 26 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); 27 glEnable(GL_TEXTURE_2D); 28 . 29 . 30 . 31 glColor4f(1.0,1.0,1.0,1.0); //leave color full strength, the image will do the colors now 32 33 //in the display loop 34 35 glBegin(GL_TRIANGLES); 36 37 //glColor4f(0.2f,0.2f,0.2f,1.0f); 38 glTexCoord2f(float x, float y); //where x and y vary across the texture (no matter what size) from 0.0 to 1.0 39 //The x is 0.0 at left edge, 1.0 at right edge. 40 //The y is 0.0 at bottom edge, 1.0 at top edge. Or you could flip the image in a paint app. 41 glVertex3d(wc[0],wc[2],wc[4]); “Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”― Robert A. Heinlein
 altalena Member #13,639 October 2011 Wow i feel stupid for not figuring this matrix vector thing out sooner. One less thing on my to-do list i guess.``` unit_vector[0]=1.0*cos(phi*M_2PIE/400.0)*cos(theta*M_2PIE/400.0); unit_vector[1]=1.0*sin(phi*M_2PIE/400.0)*cos(theta*M_2PIE/400.0); unit_vector[2]=1.0*sin(theta*M_2PIE/400.0); unit_vector[3]=1.0*cos((phi-100.0)*M_2PIE/400.0)*cos(theta*M_2PIE/400.0); unit_vector[4]=1.0*sin((phi-100.0)*M_2PIE/400.0)*cos(theta*M_2PIE/400.0); unit_vector[5]=1.0*sin(theta*M_2PIE/400.0); unit_vector[6]=1.0*cos(phi*M_2PIE/400.0)*cos((theta+100.0)*M_2PIE/400.0); unit_vector[7]=1.0*sin(phi*M_2PIE/400.0)*cos((theta+100.0)*M_2PIE/400.0); unit_vector[8]=1.0*sin((theta+100.0)*M_2PIE/400.0); ``` That's how to make the unit vectors for 2-axis rotation, I'm using 400ths of a circle to avoid rounding errors from using radians. Obviously, use 360 for 400 and 90 for 100 if you're using degrees. 0-2 is out vector, 3-5 is right vector, and 6-8 is up vector.I have no idea how to get the image to load in my program, however. ...At the briefest instant following creation all the matter of the universe was concentrated in a very small place, no larger than a grain of mustard. The matter at this time was very thin, so intangible, that it did not have real substance. It did have, however, a potential to gain substance and form and to become tangible matter. From the initial concentration of this intangible substance in its minute location, the substance expanded, expanding the universe as it did so. As the expansion progressed, a change in the substance occurred. This initially thin noncorporeal substance took on the tangible aspects of matter as we know it. From this initial act of creation, from this ethereally thin pseudosubstance, everything that has existed, or will ever exist, was, is, and will be formed. - the RaMBaN, 1194 - 1270ג וּשְׁאַבְתֶּם-מַיִם, בְּשָׂשׂוֹן, מִמַּעַיְנֵי, הַיְשׁוּעָה. - Yeshayahu 12:3
 Arthur Kalliokoski Second in Command February 2005 altalena said: I have no idea how to get the image to load in my program, however. ```If you're using an IDE, it's probably messing up your current directory, so try this ALLEGRO_PATH *path; path = al_get_standard_path(ALLEGRO_RESOURCES_PATH); al_change_directory(al_path_cstr(path,ALLEGRO_NATIVE_PATH_SEP)); ``` What? You already have allegro_image.h in your include list. ``` ALLEGRO_BITMAP *random_image_ptr; random_image_ptr = al_load_bitmap("my_random_image.bmp"); if(random_image_ptr == 0) { //al_show_native_message_box(0,"Error","Unable to load terrain file","",NULL,0); fprintf(stderr,"Can't load terrain image\n"); return 1; } ``` [EDIT]Oh, yeah, you'll have to link in allegro_image.lib or whatever depending on your compiler.[EDIT2]FIXED: I should have stuck in the path stuff before the al_load_bitmap part “Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”― Robert A. Heinlein
 altalena Member #13,639 October 2011 Ok. I'm linking in C:\allegro\liballegro_image-5.0.8-static-mt.a and I'm linking to all the other static libraries suggested by the code::blocks+mingw page on the wiki.I'm compiling the project and then running the .exe from an icon pinned to my w7 task bar. I put in the code ``` ALLEGRO_PATH *path; path = al_get_standard_path(ALLEGRO_RESOURCES_PATH); al_change_directory(al_path_cstr(path,ALLEGRO_NATIVE_PATH_SEP)); ``` before trying to load the bitmap.I've attached my latest code, attempting to get this working. I appreciate the help. ...At the briefest instant following creation all the matter of the universe was concentrated in a very small place, no larger than a grain of mustard. The matter at this time was very thin, so intangible, that it did not have real substance. It did have, however, a potential to gain substance and form and to become tangible matter. From the initial concentration of this intangible substance in its minute location, the substance expanded, expanding the universe as it did so. As the expansion progressed, a change in the substance occurred. This initially thin noncorporeal substance took on the tangible aspects of matter as we know it. From this initial act of creation, from this ethereally thin pseudosubstance, everything that has existed, or will ever exist, was, is, and will be formed. - the RaMBaN, 1194 - 1270ג וּשְׁאַבְתֶּם-מַיִם, בְּשָׂשׂוֹן, מִמַּעַיְנֵי, הַיְשׁוּעָה. - Yeshayahu 12:3