Jump to content
  • Advertisement

tppramod

Member
  • Content Count

    70
  • Joined

  • Last visited

Community Reputation

122 Neutral

About tppramod

  • Rank
    Member
  1. 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. 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. 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. 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. 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. tppramod

    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. 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. tppramod

    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. tppramod

    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. 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. 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. 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. 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?
  14. This is further to my earlier topic "Simple 3D plotting not working in Turbo C" under beginner forum,which is now solved. This is a simple 3D plotting code for a cube using MATRIX. It is programmed in Turbo C in Mode 13h (320X200 pixels). The program has the following main sections: 1. EnterMode13H(); 2. Transformation(); 3. Vector_Matrix_Multiplication(); 4. DrawCube(); 4. LeaveMode13H(); The Transformation() function has the following operations: 1. Translation 2. Scaling 3. Rotation X-Axis 4. Rotation Y-Axis 5. Rotation Z-Axis In the example i want to rotate on X-Axis by 45 degrees. See the code where Ax=45. The program is getting compiled without any error but there is no display. The problem should be in Transformation() or Vector_Matrix_Multiplication() functions but i could not figure out the error. There seems to be no error in the screen drawing code. Can Someone help. The Code follows: #include <stdlib.h> #include <conio.h> #include <alloc.h> #include <memory.h> #include <dos.h> typedef unsigned char byte; byte *On_Screen=(byte *)MK_FP(0xA000,0); int X, Y, Z; 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 int No_Of_Points=8; int ScreenX[8],ScreenY[8]; float RadiansPerDegree=0.0174533; float Tx=0, Ty=0, Tz=0; //For Translation in Transformation() Function float Sx=0, Sy=0, Sz=0; //For Scaling in Transformation() Function float Ax=45, Ay=0, Az=1; //For Rotation on X,Y,Z <----- 45 D trying here //All Array Declarations float Cube[8][3] = { {-10, 10,-10 }, //1 { 10, 10,-10 }, //2 {-10,-10,-10 }, //3 { 10,-10,-10 }, //4 {-10, 10, 10 }, //5 { 10, 10, 10 }, //6 {-10,-10, 10 }, //7 { 10,-10, 10 }, //8 }; //All -1 Values are replaced by appropriate values using Tranformation() function //Translation float T_Matrix[4][4] = { { 1, 0, 0,-1 }, { 0, 1, 0,-1 }, { 0, 0, 1,-1 }, { 0, 0, 0, 1 }, }; //Scaling float S_Matrix[4][4] = { {-1, 0, 0, 0 }, { 0,-1, 0, 0 }, { 0, 0,-1, 0 }, { 0, 0, 0, 1 }, }; //Rotation X-Axis double Rx_Matrix[4][4] = { { 1, 0, 0, 0 }, { 0,-1,-1, 0 }, { 0,-1,-1, 0 }, { 0, 0, 0, 1 }, }; //Rotation Y-Axis float Ry_Matrix[4][4] = { {-1, 0,-1, 0 }, { 0, 1, 0, 0 }, {-1, 0,-1, 0 }, { 0, 0, 0, 1 }, }; //Rotation Z-Axis float Rz_Matrix[4][4] = { {-1,-1, 0, 0 }, {-1,-1, 0, 0 }, { 0, 0, 1, 0 }, { 0, 0, 0, 1 }, }; float Total1_Matrix [4][4]; float Total2_Matrix [4][4]; float Total3_Matrix [4][4]; float Final_Matrix [4][4]; //---------------------------- Screen Codes Begins -------------------------- void EnterMode13H(void) {union REGS regs;regs.x.ax = 0x0013;int86(0x10, &regs, &regs);} void LeaveMode13H(void) {union REGS regs;regs.x.ax = 0x0003;int86(0x10, &regs, &regs);} //------------------------------------------------------------------------------ //------------------------- Plot-Read Pixels Begins ------------------------- void PlotPixel (signed int x, signed int y, unsigned char c) { if ((x < 320) && (y < 200)) { On_Screen[(y << 8) + (y << 6) + x] = c; } } //------------------------------- DrawVertex BEGINS ---------------------------- DrawVertext(int x, int y, int color) { int i, h, w; for (h=0; h<=1; h++) { for (w=0; w<=1; w++) { PlotPixel(x+w,y+h, color); } } } //------------------------------- DrawVertext ENDS ----------------------------- Transformation() { //Translation T_Matrix [0][3] = Tx; T_Matrix [1][3] = Ty; T_Matrix [2][3] = Tz; //Scaling S_Matrix [0][0] = Sx; S_Matrix [1][1] = Sy; S_Matrix [2][2] = Sz; //Rotation X-Axis - This is enabled as i set value of Ax to 45 D initially Rx_Matrix[1][1] = cos(RadiansPerDegree*Ax); Rx_Matrix[1][2] = sin(RadiansPerDegree*Ax); Rx_Matrix[2][1] = -sin(RadiansPerDegree*Ax); Rx_Matrix[2][2] = cos(RadiansPerDegree*Ax); //Rotation Y-Axis Ry_Matrix[0][0] = cos(RadiansPerDegree*Ay); Ry_Matrix[0][2] = -sin(RadiansPerDegree*Ay); Ry_Matrix[2][0] = sin(RadiansPerDegree*Ay); Ry_Matrix[2][2] = cos(RadiansPerDegree*Ay); //Rotation Z-Axis Rz_Matrix[0][0] = cos(RadiansPerDegree*Az); Rz_Matrix[0][1] = sin(RadiansPerDegree*Az); Rz_Matrix[1][0] = -sin(RadiansPerDegree*Az); Rz_Matrix[1][1] = cos(RadiansPerDegree*Az); Matrix_Multiplication(Rz_Matrix , Ry_Matrix, Total1_Matrix); Matrix_Multiplication(Total1_Matrix, Rx_Matrix, Total2_Matrix); Matrix_Multiplication(Total2_Matrix, S_Matrix, Total3_Matrix); Matrix_Multiplication(Total3_Matrix, T_Matrix, Final_Matrix ); } Matrix_Multiplication(float MatA[4][4],float MatB[4][4],float MatC[4][4]) { int i, j, k; for (i=0; i<4;i++) { for (j=0; j<4; j++) { MatC[j]=0; for (k=0; k<4; k++) { MatC[j] += MatA[k] * MatB[k][j]; } } } } Vector_Matrix_Multiplication() { int i; for (i=0;i<No_Of_Points;i++) { X = (Cube[0]*Final_Matrix[0][0]) + (Cube[1]*Final_Matrix[1][0]) + (Cube[2]*Final_Matrix[2][0]) + Final_Matrix[3][0]; Y = (Cube[0]*Final_Matrix[0][1]) + (Cube[1]*Final_Matrix[1][1]) + (Cube[2]*Final_Matrix[2][1]) + Final_Matrix[3][1]; Z = (Cube[0]*Final_Matrix[0][2]) + (Cube[1]*Final_Matrix[1][2]) + (Cube[2]*Final_Matrix[2][2]) + Final_Matrix[3][2]; Z += 100; ScreenX=FocalDistance*X/Z+XOrigin; ScreenY=FocalDistance*Y/Z+YOrigin; } } DrawCube() { int i; for (i=0;i<No_Of_Points;i++) { DrawVertext(ScreenX,ScreenY,12); } } void main() { EnterMode13H(); Transformation(); Vector_Matrix_Multiplication(); DrawCube(); getch(); farfree(On_Screen); LeaveMode13H(); }
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!