473,386 Members | 1,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

display 3D space

10
I have a program showing 3D space as follows:
Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <conio.h>
  3. #include <graphics.h>
  4. #include <math.h>
  5.  
  6. typedef struct {
  7.   double x, y, z;
  8. } Point3D;
  9.  
  10. double yaw, roll, pitch, depth;
  11. static Point3D p[] = {
  12. {-35.0, -35.0, 35.0},
  13. {35.0, -35.0, 35.0},
  14. {35.0, 35.0, 35.0},
  15. {-35.0, 35.0, 35.0},
  16. {-35.0, -35.0, 35.0},
  17. {-35.0, -35.0, -35.0},
  18. {35.0, -35.0, -35.0},
  19. {35.0, 35.0, -35.0},
  20. {-35.0, 35.0, -35.0},
  21. {-35.0, -35.0, -35.0}
  22. };
  23.  
  24. void show_3d(Point3D p[], int n)
  25. {
  26.   double sinyaw, cosyaw, sinroll, cosroll, sinpitch, cospitch,
  27.      yawx, yawy, rollx, rollz, pitchx, pitchy, pitchz, sx, sy;
  28.   int r;
  29.  
  30.   cleardevice();
  31.  
  32.   sinyaw = sin(yaw);
  33.   cosyaw = cos(yaw);
  34.   sinroll = sin(roll);
  35.   cosroll = cos(roll);
  36.   sinpitch = sin(pitch);
  37.   cospitch = cos(pitch);
  38.  
  39.   for (r=0; r<n; r++)
  40.   {
  41.     yawx = (cosyaw * p[r].x) - (sinyaw * p[r].y);
  42.     yawy = (sinyaw * p[r].x) + (cosyaw * p[r].y);
  43.     rollx = (cosroll * yawx) + (sinroll * p[r].z);
  44.     rollz = (cosroll * p[r].z) - (sinroll * p[r].z);
  45.     pitchy = (cospitch * yawy) - (sinpitch * rollz);
  46.     pitchz = (sinpitch * yawy) + (cospitch * rollz);
  47.  
  48.     sx = depth * (rollx+5) / (pitchy+250);
  49.     sy = depth * (pitchz-5) / (pitchy+250);
  50.     if (r == 0)
  51.       moveto(sx+getmaxx() / 2, sy + getmaxy() / 2);
  52.     else
  53.       lineto(sx+getmaxx() / 2, sy+getmaxy() / 2);
  54.   }
  55. }
  56.  
  57. void main()
  58. {
  59.   int gr_drive = DETECT, gr_mode, c=0;
  60.  
  61.   initgraph(&gr_drive, &gr_mode, "C:\\TC\\BGI");
  62.  
  63.   yaw = 5.7;
  64.   roll = 6.3;
  65.   pitch = 5.9;
  66.   depth = 360;
  67.   while (c != 27)
  68.   {
  69.     show_3d(p, 10);
  70.     c = getch();
  71.     if (c==0)
  72.       c = getch();
  73.     switch (c)
  74.     {
  75.       case 75 : yaw -= 0.1;
  76.         break;
  77.       case 77 : yaw += 0.1;
  78.         break;
  79.       case 72 : pitch -= 0.1;
  80.         break;
  81.       case 80 : pitch += 0.1;
  82.         break;
  83.     }
  84.   }
  85.   closegraph();
  86.   getch();
  87. }
  88.  
How to apply effects to the image??
Jun 1 '09 #1
2 2671
JosAH
11,448 Expert 8TB
@lonbame
What effects? All you do now is display a projection of a three dimensional 'connect the dots' wire figure.

kind regards,

Jos
Jun 1 '09 #2
RRick
463 Expert 256MB
Welcome to the world of 3D graphics. Most people's first attempt is some kind of wire frame representation of an object. Jos is right in that points and lines don't lend themselves to advanced effects like texturing, shading and lighting.

For those effects you need some kind of surface like a triangle or quadratic. But these polygon primitives add a new set of problems beyond rendering, like who's in front of who (hidden line removal), pixel to pixel shading and texturing.

Which way you go forward from here depends on what you are interested in. If you like the low level algorithms, then keep on the same track as you are right now. You'll learn a lot as you go along.

If you are more interested in the end product, then a 3D toolkit/framework is the best way to go. There is opengl open source and Directx->Direct3D for windows. Each of these toolkits provide you with functions for the manipulating 3D objects.
Jun 1 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: kindermaxiz | last post by:
hi there i have a mysql table and i want the user to add columns using a php interface and then display the table with the newly added column. I was thinking about putting all the columns...
7
by: Jeff Thies | last post by:
I'm trying to do a nav list using list items. Roughly this is putting links styled display: block and with a background color. In IE5 (windows, haven't tried Mac yet), adding the display:...
2
by: endus | last post by:
I'm having some trouble getting something to work. I'm not even sure whether or not this is possible, but it *seems* like it should be. I've done a fair amount of experimenting and googling...but...
23
by: news.hku.hk | last post by:
suppose i have: int price1 = 35000; int price2 = 600; int price3 = 8765; int price4 = 120000; int price5 = 3800000; and i want to output to screen the following:
10
by: DettCom | last post by:
Hello, I would like to be able to display or hide fields based on whether a specific Yes/No radio button is selected. This is in conjunction with a posting a just made here in the same group...
4
by: bissatch | last post by:
I am trying to use DIV tags and a class to hide the DIV and the HTML within. I will use JavScript to change it from hidden to visible but that will come later. Below is the code I am using ...
15
by: Markus Ernst | last post by:
Hi When toggling an element on and off by setting its display property via DOM access, display:none is valid for all kinds of elements, but I can't find anything about a generic value for...
12
by: Vadim Guchenko | last post by:
Hello. I'm using the following code: <html> <head> <style type="text/css"> pre {display: inline;} </style> </head>
3
by: ApexData | last post by:
I am using a continuous form for display purposes. Above this form, a single record is displayed so that when the user presses my NewButton they can enter a NewRecord which gets added to the...
6
by: shiniskumar | last post by:
Ive got to display node based on the selected level... Suppose the structure is as follows A -> B ->D ->E ->E1 ->H
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.