# tppramod

Member

70

122 Neutral

• Rank
Member
1. ## 2D Rotation of Two Parallel Lines For Shooting Game

Hi Osmanb, Nice explanation.. Just going ahead with it. Lets have an example if: //Centre Of Rotation XC = 150; YC = 100; x1 = 100; y1 = 150; x2 = 100; y2 = 50; Therefore; x1' = 100 - 150; y1' = 150 - 100; x2' = 100 - 150; y2' = 50 - 100 Hence; x1' = -50; y1' = 50; x2' = -50; y2' = -50; so (-50,50,-50,-50) works out as the NEW ORIGIN for rotation. But how this is relative to the black dot at (150,100)? Is this origin valid!!!! Sorry i am weak in math.
2. ## 2D Rotation of Two Parallel Lines For Shooting Game

Hi bzroom, i am actually programming in Turbo C for DOS. I am actually comfortable with it. All the required graphics routines are written to draw directly to the video memory hence i does not use opengl or any window based graphic libraries. I just program for fun. Now instead of matrix can the same be done using the given formula itself? Is there any way? Because i am not comfortable with it!. x1 = x * cos(angle) - y * sin (angle); y1 = x * sin(angle) + y * cos (angle); If it can only be done through matrix then please show me how to calculate these 4 vertices using matrix in C. Regards, Pramod Kumar New Delhi, India
3. ## 2D Rotation of Two Parallel Lines For Shooting Game

Hi All, I am programming a shooting game having a gun base at the bottom. It moves upto 165 degrees to the left and 15 degrees to the right maximum. Figure 1 shows what i exactly need it. Figure 2 shows the two lines involved in the making of the gun. I am having trouble in moving both the parallel lines rotated at the centre of rotation, which is shown as black circle (between the parallel lines). i know how to move at various angles had it been only one single line. I have the following formula: x1 = x * cos(angle) - y * sin (angle); y1 = x * sin(angle) + y * cos (angle); Please show me how both the lines can be rotated using the above code so that it work like figure 1. Here is the link of Figures: http://img2.freeimagehosting.net/image.php?fd86dbece5.jpg Regards, Pramod Kumar New Delhi, India
4. ## Waiting For Vertical Refresh - How to avoid for better performance

The sprites move by 1 pixels either horizontally/vertically at a very good speed if i disable the Wait_For_Retrace() function but with a lot of flicker. i have even tried the double buffering technique but it simply killed the speed of the game. The whole animation turned to slow-motion! i have shown the Wait_For_Retrace function below. I don't know if i am doing it in the right way. void Wait_For_Retrace(void) { while ( (inp(INPUT_STATUS) & VRETRACE)) {}; while (!(inp(INPUT_STATUS) & VRETRACE)) {}; } Thanx Pramod
5. ## Waiting For Vertical Refresh - How to avoid for better performance

Its a pacman game and has been programmed in Turbo C v3.0 (320x200x256). The code is well optimized and is running smoothly without any flicker. The flow of the game is as follows: 1. Does all the calculations. 2. Draw/Moving the sprites. 3. Wait For the Vertical refresh. 4. Erase sprites. 5. Loop continues. Here if u see the movement of sprite is synchronized with the refresh rate of the video mode, and the vertical retrace signals are a very steady timing source. The sprite cannot go faster, eventhough u have coded well, than the video mode's refresh rate allows! But what happens on computers with different speeds than the one i have tested with (Pentium III, 500 Mhz.) i know that it has something to do with 8253 timer chip programming. But then what will happen to Wait For Vertical function call? will it be required then? if i omit this function then it will flicker. I just wanted to know how to give a proper delay using 8253 timer, which would allow the game to run at same speed on different computers. I don't want to change the frame rate of the game. Any help! pramod
6. ## How It Is Running Faster?

The code is written in Turbo C v3.0 for mode 13h (300x200 pixels). The sprites move by one pixel either up or down. The flow of the code is as follows: 1. All calculations <- This goes through many calculations like collission detection, Array updation for sprites and sound support, Fonts functions, Keyboard inputs etc., which takes up considerable processing time. That is the speed of the game depends actually on these calculation. But if i run this on a faster PC it would be a different speed. Don't know if Waiting for the Vertical Retrace is stripping down the speed. 2. Draw Sprites 3. Wait For Vertical Retrace 4. Erase Sprites 5. Go to 1. NOW IS THERE ANY WAY TO INCREASE THE SPEED WITHOUT CHANGING THE FRAME.
7. ## How It Is Running Faster?

i have found that sometimes while playing a DOS game if you switch over to windows (using Alt-Tab) and then when come back to DOS game again, the game runs very fast!! There is no skipping of the frames but its runs in a normal way but faster!!. My question is how can i achieve this kind of speed in my current project, which is a DOS pacman game. I have read about system timer but the examples i have seen is talking about ajusting the frames depending about the speed of the computer and not really how to increase the processing speed WITHOUT SKIPPING FRAMES. Pramod
8. ## GCC Vs Turbo C

i have been compiling my C Code using Turbo C v3.0so far. Now i just wanted to try out with gcc compiler. it is said to be best compiler for optimization. What changes do i need to make in my code to compile with gcc. Thanks & Regards,
9. ## 2D to 3D Guidance required

thanks for the reply. u r right i won't be getting the hardware acceleration but i am not targetting any high end 3d graphics and rendering. it would be the simple one something made out like polygon filling and hidden surface removal. i have learned about hidden surface removal (HSR) of a cube but that required the cube to be in some particular orienation were any one side is fully hidden. but in the case like a retaliator many of its sides are partially visible/hidden. i don't know how the HSR work here? is it going to be something called Z-buffering where all polygons are drawn on top of the other in a series?
10. ## 2D to 3D Guidance required

i have completed a 2D pacman game written in turbo C in mode 13h. it was really interesting as the whole graphics routines and animation was programmed without using any library thereby understanding the underlying principles of graphics. I have now learned the basics of 3D and have programmed a rotating cube in C using the 3D rotation formula and as well as using matrix in mode 13h. i now want to make a 3D game similar to f-29 Retaliator, which was a DOS game BUT i DON'T want to use any library like opengl, sdl etc.... i know that it is tough but on the other hand i feel no satisfaction in using readymade libraries. i want to make everything myself!. So any good source to start the similar game? pramod
11. ## Whats wrong with this code! - Rotations

Hi all, Here is a code for 3D rotation on X-axis, Y-axis and Z-axis for a cube. Out of which only Z-axis is working fine! X-Axis & Y-axis is also functioning but i don't know why it is poping out of the screen when the value degree increases. The main function is DrawVertex(). Can anyone tell me where i going wrong. This program is in mode 13h having screen resolution 320 x 200 pixels and is writen in Turbo C. i have commented X-Axis & Y-Axis so that only Z-Axis works. Press ESC to come out of the program. Here is the simple code. #include <stdlib.h> #include <conio.h> #include <alloc.h> #include <memory.h> #include <dos.h> #include <stdio.h> #include <math.h> //3D CUBE DEMONSTRATION - NOT WORKING! PLEASE HELP! //ALL VARIABLS typedef unsigned char byte; byte *On_Screen=(byte *)MK_FP(0xA000,0); int X, Y, Z; int X1, Y1, Z1; int X2, Y2, Z2; int X3, Y3, Z3; int XOrigin=160, YOrigin=100; //Are the coordinates of the center of the video display int FocalDistance=200; //Range 80-200 - Distance from the viewer to the screen float RadiansPerDegree=0.0174533; float Angle; int No_Of_Vertex=8; int ScreenX[8], ScreenY[8]; //For storing 2D Screen Coordinates float Cube[8][3] = { {-50, 50,-50 }, //1 { 50, 50,-50 }, //2 {-50,-50,-50 }, //3 { 50,-50,-50 }, //4 {-50, 50, 50 }, //5 { 50, 50, 50 }, //6 {-50,-50, 50 }, //7 { 50,-50, 50 }, //8 }; //KEYBOARD VARIABLES int ascii, scan, cont=1; union REGS ii,oo; char kb; //---------------------------- Screen Codes Begins -------------------------- void EnterMode13H(void) {union REGS regs;regs.x.ax = 0x0013;int86(0x10, ®s, ®s);} void LeaveMode13H(void) {union REGS regs;regs.x.ax = 0x0003;int86(0x10, ®s, ®s);} //------------------------------------------------------------------------------ //------------------------- Plot-Read Pixels Begins ------------------------- void PlotPixel (signed int x, signed int y, signed char c) { if ((x < 320) && (y < 200)) { On_Screen[(y << 8) + (y << 6) + x] = c; } } //------------------------------------------------------------------------------ //------------------------------- DrawCube BEGINS ------------------------------ DrawVertex() { int Vertices, Degrees; float ScaleFactor; PlotPixel(160,100,14); //MIDDLE OF THE SCREEN for (Degrees=0;Degrees<360;Degrees++) { for (Vertices=0;Vertices<8;Vertices++) //DRAW VERTICES { Angle = (RadiansPerDegree*Degrees); X = Cube[Vertices][0]; Y = Cube[Vertices][1]; Z = Cube[Vertices][2]; Z += 500; /* //X-Axis <---- DISABLED X = X; Y = (cos(Angle)*Y) - (sin(Angle)*Z); Z = (sin(Angle)*Y) + (cos(Angle)*Z); //Y-Axis <---- DISABLED X = (cos(Angle)*X) + (sin(Angle)*Z); Y = Y; Z = -(sin(Angle)*X) + (cos(Angle)*Z); */ //Z-Axis <--- ENABLED - WORKING FINE! X = (cos(Angle)*X) - (sin(Angle)*Y); Y = (sin(Angle)*X) + (cos(Angle)*Y); Z = Z; if (Z == 0) { Z = 1;} // Avoid division by zero //3D to 2D Transformation ScreenX[Vertices]=FocalDistance*X/Z+XOrigin; ScreenY[Vertices]=FocalDistance*Y/Z+YOrigin; PlotPixel(ScreenX[Vertices],ScreenY[Vertices],12); } delay(30); for (Vertices=0;Vertices<8;Vertices++) { PlotPixel(ScreenX[Vertices],ScreenY[Vertices],0); } } } //------------------------------- DrawCube ENDS ------------------------------ void main() { EnterMode13H(); DrawVertex(); do { if (kbhit()) { ii.h.ah=0; int86 (22,&ii,&oo); ascii=oo.h.al; scan=oo.h.ah; switch (scan) { case 1: //ESC KEY PRESSED cont = 0; farfree(On_Screen); LeaveMode13H(); break; } } } while (cont == 1); } Thanks & Regards, pramod [Edited by - tppramod on June 30, 2005 12:28:52 AM]
12. ## 3D Plotting using Matrix in Turbo C

Hi jyk, IST ARRAY float T_Matrix[4][4] = { { 1, 0, 0,-1 }, { 0, 1, 0,-1 }, { 0, 0, 1,-1 }, { 0, 0, 0, 1 }, }; 2ND ARRAY //Translation T_Matrix [0][3] = Tx; //3rd column of row 0 T_Matrix [1][3] = Ty; //3rd column of row 1 T_Matrix [2][3] = Tz; //3rd column of row 2 The 2nd Array show above is just repacing the value '-1' of the 1st Array with the appropriate values of Tx, Ty & Tz. The first one is ROW and the second is COLUMN in the array. Thus, the translation array seems to be correct. Anyway thanks for replying.
13. ## 3D Plotting using Matrix in Turbo C - Any Experts There!

Should I delete this post.
14. ## 3D Plotting using Matrix in Turbo C - Any Experts There!

It seems Matrix is easy to explain but difficult to code!!! No response so far on the code. really surprising! Where are the experts gone?