Sephiroth
Fayetteville, NC, USA

in 3D Graphics

OK, I have a simple clipping function up that also sets values based on where the vertex is based on the player's view. Now I can get z (the distance form the player) and y (above/below the player) easily, but how do I calculate x? I also found out that i cannot use indirection floating point values, so how can I point x, y, and z in the function to the memory location of the three actual variables being clipped and drawn?

[code]

bool CheckClipPlane(float x, float y, float z)

{

int distance;

distance = sqrt(((x - player.xpos) * (x - player.xpos)) + ((y - player.ypos) * (y - player.ypos)) + ((z - player.zpos) * (z - player.zpos)));

if(distance > 512)

return false;

if(x < (player.xpos + cos((player.heading - 45) * pi / 180.0) * distance) || z < (player.zpos - sin((player.heading - 45) * pi / 180.0) * distance))

return false;

if(x > (player.xpos + cos((player.heading + 45) * pi / 180.0) * distance) || z > (player.zpos + sin((player.heading + 45) * pi / 180.0) * distance))

return false;

//Now set x y z to how they appear in the FOV

z = distance; //How far out the vertex is

y -= player.ypos; //How far above or below the player the vertex is

// x = ?; //How do you do x???

return true;

}

[/code]

Now you would call the function with say "if(CheckClipPlane(x_m, y_m, z_m))". Now if it is too far to be seen, or the vertex is outside the player's FOV, it will return false and go on to examine the next triangle. If the vertex IS in the FOV, I need to have x_m, y_m, and z_m modified so that when I send the data to OpenGL it'll draw it as if the player really was moving around. Thanks for the help!

-[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red]

[code]

bool CheckClipPlane(float x, float y, float z)

{

int distance;

distance = sqrt(((x - player.xpos) * (x - player.xpos)) + ((y - player.ypos) * (y - player.ypos)) + ((z - player.zpos) * (z - player.zpos)));

if(distance > 512)

return false;

if(x < (player.xpos + cos((player.heading - 45) * pi / 180.0) * distance) || z < (player.zpos - sin((player.heading - 45) * pi / 180.0) * distance))

return false;

if(x > (player.xpos + cos((player.heading + 45) * pi / 180.0) * distance) || z > (player.zpos + sin((player.heading + 45) * pi / 180.0) * distance))

return false;

//Now set x y z to how they appear in the FOV

z = distance; //How far out the vertex is

y -= player.ypos; //How far above or below the player the vertex is

// x = ?; //How do you do x???

return true;

}

[/code]

Now you would call the function with say "if(CheckClipPlane(x_m, y_m, z_m))". Now if it is too far to be seen, or the vertex is outside the player's FOV, it will return false and go on to examine the next triangle. If the vertex IS in the FOV, I need to have x_m, y_m, and z_m modified so that when I send the data to OpenGL it'll draw it as if the player really was moving around. Thanks for the help!

-[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red]

It looks like you're new here. If you want to get involved, click one of these buttons!

- 140.8K All Categories
- 103.6K Programming Languages
- 6.4K Assembler Developer
- 401 Assembly Code Share
- 239 Getting started in assembly
- 4.6K x86 Assembly
- 1.9K Basic
- 97 Qbasic
- 39.9K C and C++
- 5.6K Beginner C/C++
- 330 C/C++ on Linux/Unix
- 450 C/C++ Windows API
- 522 C++ Builder
- 253 C++ Game Development
- 3.3K C++ MFC
- 103 C++.NET
- 404 Visual C++
- 2.9K C#
- 7.9K Delphi and Kylix
- 334 Advanced Delphi
- 360 Delphi beginners
- 4 Haskell
- 9.7K Java
- 56 Enterprise JavaBeans
- 1.3K Java Beginners
- 304 Java Server Pages
- 4.1K Pascal
- 1.3K Perl
- 11 Perl 6
- 2K PHP
- 546 Python
- 37 Ruby
- 4.4K VB.NET
- 258 Advanced VB.Net
- 1.6K VBA
- 20.8K Visual Basic
- 767 Access databases and VB
- 831 Advance Visual Basic
- 1.2K Beginner VB
- 2.6K Game programming
- 315 Console programming
- 90 DirectX Game dev
- 1 Minecraft
- 112 Newbie Game Programmers
- 2 Oculus Rift
- 9K Applications
- 1.8K Computer Graphics
- 279 3D Graphics
- 129 DirectX
- 125 OpenGL
- 740 Computer Hardware
- 9 Cooling & Overclocking
- 3.4K Database & SQL
- 1.1K Access
- 91 ADO Programming
- 288 MySQL
- 358 Oracle
- 440 SQL-Server
- 535 Electronics development
- 1.6K Matlab
- 628 Sound & Music
- 25 DirectSound
- 257 XML Development
- 3.3K Classifieds
- 199 Co-operative Projects
- 198 For sale
- 190 FreeLance Software City
- 1.9K Jobs Available
- 603 Jobs Wanted
- 209 Wanted
- 2.9K Microsoft .NET
- 1.8K ASP.NET
- 1.1K .NET General
- 22 .NET WEB-Services
- 129 .NET WinForms
- 14 .NET XML
- 50 ADO.NET
- 142 C# & VB.NET School Support
- 3.4K Miscellaneous
- 4 Join the Team
- 354 Comments on this site
- 69 Computer Emulators
- 2.1K General programming
- 187 New programming languages
- 621 Off topic board
- 200 Mobile & Wireless
- 72 Android
- 126 Palm Pilot
- 338 Multimedia
- 154 Demo programming
- 184 MP3 programming
- 0 Bash scripts
- 27 Cloud Computing
- 1 Witsbits Go Cloud
- 53 FreeBSD
- 1.7K LINUX programming
- 1 Awk scripting
- 332 Linux Support
- 0 Sed scripting
- 370 MS-DOS
- 0 Shell scripting
- 321 Windows CE & Pocket PC
- 4.1K Windows programming
- 177 COM/DCOM
- 61 Networking And Security
- 17 Windows 2003 Server
- 6 Windows Vista
- 176 Windows XP
- 939 Software Development
- 416 Algorithms
- 68 Object Orientation
- 24 RUP & UML
- 91 Project Management
- 95 Quality & Testing
- 268 Security
- 63 Evil Scripting
- 81 Hacking
- 7.7K WEB-Development
- 1.8K Active Server Pages
- 61 AJAX
- 4 Bootstrap Themes
- 55 CGI Development
- 28 ColdFusion
- 224 Flash development
- 1.4K HTML & WEB-Design
- 1.4K Internet Development
- 131 Mobile Internet & Messaging
- 211 Wireless development
- 2.2K JavaScript
- 37 JQuery
- 304 WEB Servers
- 153 Apache
- 79 IIS
- 150 WEB-Services / SOAP

## Comments

: [code]

: bool CheckClipPlane(float x, float y, float z)

: {

: int distance;

:

: distance = sqrt(((x - player.xpos) * (x - player.xpos)) + ((y - player.ypos) * (y - player.ypos)) + ((z - player.zpos) * (z - player.zpos)));

:

: if(distance > 512)

: return false;

:

: if(x < (player.xpos + cos((player.heading - 45) * pi / 180.0) * distance) || z < (player.zpos - sin((player.heading - 45) * pi / 180.0) * distance))

: return false;

:

: if(x > (player.xpos + cos((player.heading + 45) * pi / 180.0) * distance) || z > (player.zpos + sin((player.heading + 45) * pi / 180.0) * distance))

: return false;

:

: //Now set x y z to how they appear in the FOV

: z = distance; //How far out the vertex is

: y -= player.ypos; //How far above or below the player the vertex is

: // x = ?; //How do you do x???

:

: return true;

: }

: [/code]

: Now you would call the function with say "if(CheckClipPlane(x_m, y_m, z_m))". Now if it is too far to be seen, or the vertex is outside the player's FOV, it will return false and go on to examine the next triangle. If the vertex IS in the FOV, I need to have x_m, y_m, and z_m modified so that when I send the data to OpenGL it'll draw it as if the player really was moving around. Thanks for the help!

: -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red]

:

If you're planning to do something serious that is not a good approach.Matrices is what you should use(almost every 3d game uses them).The position and orientation of an object in 3d space can be represented either by a 3x3 matrix and a position vector, or a 4x4 matrix(last row it's the position vector). I've chosen the 3x3 matrix and the pos. vector.The rows of the matrix represent in order: the RIGHT vector, the UP vector and the last row is the FORWARD vector. But keep in mind that theese vector's must be normalized(ie. their length must be 1) and there must be 90 deg between them.Now let's say the camera orientation matrix is M ,the camera pos is P ,the world vertex is V and the camera space vertex(the one you need to find out) is cV.You'll have:

cV.x=M.RIGHT*(V-P)

cV.y=M.UP*(V-P)

cV.z=M.FORWARD*(V-P)

where v1*v2 =v1.x*v2.x+v1.y*v2.y+v1.z*v2.z , v1, v2 vectors

And that's all folks, I hope I didn't write this for nothing

: cV.x=M.RIGHT*(V-P)

: cV.y=M.UP*(V-P)

: cV.z=M.FORWARD*(V-P)

: where v1*v2 =v1.x*v2.x+v1.y*v2.y+v1.z*v2.z , v1, v2 vectors

: And that's all folks, I hope I didn't write this for nothing

:

Hey I REALLY appreciate the info. I knew I had to use matrices somehow but wasn't sure exactly how they were used. However, i am still not clear on a few things. What do you mean by "normalized"? Also, what's with the 90deg deal? You mean 90deg between the traingle's vertices? And finally, is there any advantage to using a 4x4 or 3x3 matrix? I mean, is one faster than the other? I would like my engine to run on slightly older machines (hopefully down to p2/300) because a lot of people I know still have 200mhz-400mhz machines which are relatively new, but technology has just sky-rocketed this year! Thanks again for the help and I'll see what I can do with what I have here. Oh and if you could direct me to a site where I can actually see some source using the matrices or show me some yourself I would be indebted to you.

-[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red]

:

The tutorial showed me basically what I know, but I am still unclear on how to get what goes into the matrix. After that, what do I do with the matrix? I am a visual learner and math was my weakest subject in HS and now in college. I took algebra three times in HS, although i later found out that one of the first two teachers I had was fired due to lack of her own knowledge in the subject... haha! Is there a site where I can actually [b]see[/b] some of this source? I have looked for this "Frog Engine" breifly but cannot seem to find it. Oh, and your engine isn't half bad! I've figured out how to draw polys/objects and rotate, zoom, and flip them, but the 3D first person perspective is still throwing me. Do you yourself have any tutorials on how to do all this that show some of the actual calculations? Thanks for your help, E_on, I REALLY appreciate it.

-[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red]

x=10

y=5

z=7

sqrt(x * x + y * y + z * z) = 13.something

The only way i can get that formula to work is to plug 0's and 1's into the x, y, and z values. And as much reading as I have done (almost two and a half hours), I am not any closer to figuring this out. A lot of people can write tutorials, but I need to SEE the code to understand it. One other thing is that I don't think I've seen anything on calculating what's in view. If this math is the actual drawing stuff, i do NOT need it. I simply pass 3 vertices to OpenGL and IT z-buffers and draws them. All I need to do is find out what vertices are in the player's FOV to send to OpenGL. Here is how this works:

[code]

glBegin(GL_TRIANGLES);

glNormal3f(0.0f, 0.0f, 1.0f);

glColor3f(1.0f, 0.0f, 0.0f);

glVertex3f(5, 5, 5);

glColor3f(0.0f, 1.0f, 0.0f);

glVertex3f(0, 0, 5);

glColor3f(0.0f, 0.0f, 1.0f);

glVertex3f(10, 0, 5);

glEnd();

[/code]

This example will draw a triangle with the top being at 5, 5, 5, the left bottom being at 0, 0, 5, and the right bottom being at 10, 0, 5. As you can see, all I need are the traingles that are in the player's sight, no matter what angle he is looking, and the proper degree of rotation to send to glRotate3f(). Then glRotate3f can properly rotate the vertices and I can send that data to glVertex3f! How do I do that? Thanks for the help, E_on.

-[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red]

x=10

y=5

z=7

sqrt(x * x + y * y + z * z) = sqrt(174) = 13.something

1 / 13.some = 0.076...

x*0.076...=0.76...

y*0.076...=0.381...

z*0.076...=0.533...

and now we have sqrt(x * x + y * y + z * z) = sqrt(1) = 1

I'm sorry you had such "untalented" math teachers. I don't know any OpenGL stuff so I can't help you with it.

: x=10

: y=5

: z=7

: sqrt(x * x + y * y + z * z) = sqrt(174) = 13.something

: 1 / 13.some = 0.076...

: x*0.076...=0.76...

: y*0.076...=0.381...

: z*0.076...=0.533...

: and now we have sqrt(x * x + y * y + z * z) = sqrt(1) = 1

: I'm sorry you had such "untalented" math teachers. I don't know any OpenGL stuff so I can't help you with it.

:

Ah so I had to multiply the results by the coordinates! That's why I kept getting all kinds of screwy errors. As for rotation, I've figured out how to rotate stuff easily. Now with this maybe I can also make it relative to the camera. Thanks for all of your help E_on, I owe ya' one.