Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (429)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (468)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Real 4D World Rendering  (Read 3707 times)
0 Members and 1 Guest are viewing this topic.
Offline DQQAYME

Junior Member


Medals: 1
Projects: 1



« Posted 2013-05-16 05:41:57 »

What is 4 Dimension and how program it =)


Let's start simple.


1st dimension:


Imagine a corridor.
It's simply a line, you can look into 2 directions: forwards or backwards.
In a program this would be a 1-dimensional array, i.e.
1  
int[x]


2nd dimension:


Imagine a corridor that has doors to rooms.
The line we had before can now have many more lines (or corridors / rooms) along the walls of the corridor.
You see can now look into 4 directions: forwards, backwards, left, right.
In a program this would be a 2-dimensional array (an array of arrays):
1  
int[x][z]


For rotating we use one defining angle and sin and cos:

  • Sin = first and second direction (forwards, backwards)
  • Cos = third and fourth direction (left, right)
   
In different angles we move into different directions:

  • angle 90°: x+
  • angle 270°: x-
  • angle 0°: z+
  • angle 180°: z-
   

3rd dimension:


Imagine a building, which has floors, which have corridors with rooms and doors to them.
You can look into 6 directions: forwards, backwards, left, right, top and down.
In a program this would be a 3-dimensional array:
1  
int[x][z][y]


For rotating we use 2 defining angles:
Sinus for up and down and
Cos for the XZ plane.

Dimension Plane



Every new dimension adds a new Plane, which has 2 sides.
We only see a particular direction, if we look into it's angle.
To show the effect, we give those directions (sides) different colors.
If you look diagonal in 3D by 2 angles, we can see 3 sides:
Green Y, Blue Z, Red X:


If we look diagonal with only 1 angle, we can only see 2 sides:
Y Angle = 0;

 
This is how it looks like, when we see 2 X sides, 1 Z side and 2 Y sides:

 
Every new dimension adds 2 planar sides on one positive dimension and on one negative dimension (+/-).
They may have any color or texture.
Every new plane after 2 planes adds a new rotation axis, which is able to render it's own 2 sides and the 2 previous planars.
In 3D the angle 0 and 180 look along the Y-axis, and 90 and 270 along the XZ plane.

4th dimension



Imagine a group of buildings.
You can look into 8 directions: forwards, backwards, left, right, top, down, D+ and D-.
We call the new dimension D.
In a program that is a 4-dimensional array:
1  
int[x][z][y][d]


So we now have 2 new planes on which we can travel or look along.
If it's possible to cast a ray in 1d, 2d and 3d, it should be able to move in 4d!
And it is!
If we have a 4x4 matrix we can easy calculate Ray position with it,
but how to render it?
Let's use raycasting.
Every pixel casts a ray, which sets the color for a pixel to the color of the obstacle it collides with.

The maths:
To cast a ray, we have to properly normalize it:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
//2D normalize
length = sqrt(x * x + y * y)
invlen = 1 / length
x *= length
y *= length

//3D
length = sqrt(x * x + y * y + z * z)
invlen = 1 / length
x *= length
y *= length
z *= length

//4D
length = sqrt(x * x + y * y + z * z + d * d)
invlen = 1 / length
x *= length
y *= length
z *= length
d *= length


Moves In 3D it looks like here we have same XZ Position but We moves Top or bottom on Y plane
And Words Changed.


4D matrix where
In one picture we don't have a floor and in the second we have it.
We now moved in the D plane, but the XYZ position is still the same.
And Words Changed.


It's even more interesting to see how the image will be if we make the D angle diagonal and see all 4 planes:

 
Purpl Side is 4D plane color
It can be explain like
Rays that colis First World Out Of Draw Range Have Black color (1 world don’t have floor)
Rays that colis second World Have Grean color(2 world  have floor)
Rays that colis Plane Side have purple color.
(purple D plane can have same Hole like Any other Plane)
I Have img this =)
Ray Progression 2D


Cube in 4D have 4 Planes every Plane with own color.

Ray Progression 4D


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
y=0, z=2, x=2, d=1
y=0, z=3, x=2, d=1
y=0, z=3, x=3, d=1
y=-1, z=3, x=3, d=1// black

y=1, z=2, x=3, d=1
y=1, z=3, x=3, d=1
y=0, z=3, x=3, d=1
y=0, z=3, x=4, d=1
y=0, z=3, x=4, d=2// Purpl

y=1, z=2, x=3, d=1
y=1, z=3, x=3, d=1
y=1, z=3, x=4, d=1
y=1, z=3, x=4, d=2
y=0, z=3, x=4, d=2// Grean


Every new plane add Sin self and Cos prev Planes
Camera ray Projection 3D
1  
2  
3  
4  
      ray.y += Dist * sin_Y;
     
      ray.x += Dist * sin_X * cos_Y;
      ray.z += -Dist * cos_X * cos_Y;


Camera ray Projection 4D
1  
2  
3  
4  
5  
      pos.d += Dist * sin_D;
      pos.y += Dist * sin_Y * cos_D;
     
      pos.x += Dist * sin_X * cos_Y * cos_D;
      pos.z += -Dist * cos_X * cos_Y * cos_D;


4D matrix Img



We have int[2][2][2][2]
So We have two 3D Matrix
4th Dimension give ability to Ray travel between this two 3D matrix =)

If we in int[X][Y][Z][0] we in first 3D matrix
If we in int[X][Y][Z][1] we in second 3D matrix
All simple )

If we have matrix array like in minecraft in 4D it will be 4D cube

Every Cube In First 3D matrix have Side To second 3D matrix,
So we have 2 * 2 * 2 = 8 sides(Tunnels) between two 3D matrix =)

Same as with 3D we can travel only on Free place block (Air)
So Even in 4D you only can move through the Air {Air == 0, Block  == 1}
[1][2][3]    D[2] = 0
[1][2][3]    D[1] = 0
[1][2][3]    D[0] = 1

We in [1][2][3]    D[1]

Ray can move to [1][2][3] D[2] ,
but can't move to [1][2][3] D[0]  we will see wall, it can be One Color Or Texture like side in Cube Wink

Try it yourself and make a raycasting renderer and add a 4th vector component to the ray.
Is the 4 the maximum number of possible dimensions?
No, it could be any number of dimensions. 5D, 6D or even 111D =)

Bin Link http://www.2shared.com/complete/oWYgVUbR/4d_z.html

More img Wink


Offline HeroesGraveDev

JGO Kernel


Medals: 215
Projects: 11
Exp: 2 years


If it wasn't Awesome, it wasn't me.


« Reply #1 - Posted 2013-05-16 06:05:01 »

The fourth dimension is usually represented by w. Tongue

Also, this isn't a real rendering of a 4D world. It is simply a projection of 4D space into 3D space (which in turn is projected into 2D space), when actually it should be projected straight into 2D space. Of course, we can't see 4D, so it is impossible to have 'Real' 4D rendering. You can't solve that, and it's just me nit-picking, but the title is slightly incorrect. Undecided

Thirdly, your transformation of the w*-axis is slightly incorrect. The fourth dimension should travel along the direction you look in xyz space, ie: a 4D plane is perpendicular to the ray cast from the camera. Your transformation looks a bit warped, but maybe it's just the screenshot.

It would also be nice if you could fix the typos. Sometimes it can get a bit confusing and may have lead me to misunderstand some of your points. Smiley

* titled D in the article, see my first point.

Offline DQQAYME

Junior Member


Medals: 1
Projects: 1



« Reply #2 - Posted 2013-05-16 12:01:11 »

Quote from:  HeroesGraveDev
The fourth dimension is usually represented by w
No comments.

Quote from:  HeroesGraveDev
Also, this isn't a real rendering of a 4D world. It is simply a projection of 4D space into 3D space (which in turn is projected into 2D space), when actually it should be projected straight into 2D space. Of course, we can't see 4D, so it is impossible to have 'Real' 4D rendering. You can't solve that, and it's just me nit-picking, but the title is slightly incorrect. 

Okay same as you can't see 3D dimension on 2D screen its impossible XD

4D Projection with FOV
22 On D
45 On XZ
45 On Y



Quote from:  HeroesGraveDev
Thirdly, your transformation of the w*-axis is slightly incorrect. The fourth dimension should travel along the direction you look in xyz space, ie: a 4D plane is perpendicular to the ray cast from the camera. Your transformation looks a bit warped, but maybe it's just the screenshot.

Yes you right XYZ perpendicular D that’s why we use Cos angel D for XYZ and Sin angel D For D. =)

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline matheus23

JGO Kernel


Medals: 98
Projects: 3


You think about my Avatar right now!


« Reply #3 - Posted 2013-05-16 16:37:42 »

I tried to correct your typos and grammar errors in your article, it's such a high level in terms of math and understanding, but such a low level in English...
I'm not native English speaker myself, so it's not 100% right Smiley

I don't know if it's even possible to modify Article posts, but here it is:

What is the 4th dimension and how to program it =)


Let's start simple.

1st dimension:


Imagine a corridor.
It's simply a line, you can look into 2 directions: forwards or backwards.
In a program this would be a 1-dimensional array, i.e.
int[x]


2nd dimension:


Imagine a corridor that has doors to rooms.
The line we had before can now have many more lines (or corridors / rooms) along the walls of the corridor.
You see can now look into 4 directions: forwards, backwards, left, right.
In a program this would be a 2-dimensional array (an array of arrays):
int[x][z]

For rotating we use one defining angle and sin and cos:
  • Sin = first and second direction (forwards, backwards)
  • Cos = third and fourth direction (left, right)

In different angles we move into different directions:
  • angle 90°: x+
  • angle 180°: x-
  • angle 0°: z+ (<- Huh Both this and the one below were "-" before)
  • angle 90°: z-

3rd dimension:


Imagine a building, which has floors, which have corridors with rooms and doors to them.
You can look into 6 directions: forwards, backwards, left, right, top and down.
In a program this would be a 3-dimensional array:
int[x][z][y]

For rotating we use 2 defining angles:
Sinus for up and down and
Cos for the XZ plane.

More dimensions


Every new dimension adds a new Plane, which has 2 sides.
We only see a particular direction, if we look into it's angle.
To show the effect, we give those directions (sides) different colors.
If you look diagonal in 3D by 2 angles, we can see 3 sides:
Green Y, Blue Z, Red X:

If we look diagonal with only 1 angle, we can only see 2 sides:

This is how it looks like, when we see 2 X sides, 1 Z side and 2 Y sides:

Every new dimension adds 2 planar sides on one positive dimension and on one negative dimension (+/-).
They may have any color or texture.
Every new plane after 2 planes adds a new rotation axis, which is able to render it's own 2 sides and the 2 previous planars.
In 3D the angle 0 and 180 look along the Y-axis, and 90 and 270 along the XZ plane.

4th dimension


Imagine a group of buildings.
You can look into 8 directions: forwards, backwards, left, right, top, down, D+ and D-.
We call the new dimension D.
In a program that is a 4-dimensional array:
int[x][z][y][d]


So we now have 2 new planes on which we can travel or look along.
If it's possible to cast a ray in 1d, 2d and 3d, it should be able to move in 4d!
And it is!
If we have a 4x4 matrix we can easy calculate Ray position with it,
but how to render it?
Let's use raycasting.
Every pixel casts a ray, which sets the color for a pixel to the color of the obstacle it collides with.

The maths:
To cast a ray, we have to properly normalize it:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
// 2D normalize
length = sqrt(x * x + y * y)
invlen = 1 / length
x *= length
y *= length

// 3D
length = sqrt(x * x + y * y + z * z)
invlen = 1 / length
x *= length
y *= length
z *= length

// 4D
length = sqrt(x * x + y * y + z * z + d * d)
invlen = 1 / length
x *= length
y *= length
z *= length
d *= length


'Moving in 3d looks like having the same XZ position, but we move up or down on the y axis.
And the other way around' (quotes for a reason here Grin )


'4D matrix:
In one picture we don't have a floor and in the second we have it.
We now moved in the D plane, but the XYZ position is still the same.
And the other way around.'


It's even more interesting to see how the image will be if we make the D angle diagonal and see all 4 planes:


The purple plane is the 4th plane.
This can be explained like that:
Rays that collide in the first picture (3rd last picture) are out of draw range and have a black color (it doesn't have a floor).
Rays that collide in the second last picture have a green color (second world has a floor).
Rays that collide with the Plane side have a purple color.
(the purple D plane can have the same holes like any other plane)

So I have this Image:

Ray progression


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
float y=0, z=2, x=2, d=1
float y=0, z=3, x=2, d=1
float y=0, z=3, x=3, d=1
float y=-1, z=3, x=3, d=1// black

float y=1, z=2, x=3, d=1
float y=1, z=3, x=3, d=1
float y=0, z=3, x=3, d=1
float y=0, z=3, x=4, d=1
float y=0, z=3, x=4, d=2// Purple

float y=1, z=2, x=3, d=1
float y=1, z=3, x=3, d=1
float y=1, z=3, x=4, d=1
float y=1, z=3, x=4, d=2
float y=0, z=3, x=4, d=2// Green


Every new plane adds a sin for itself and a cos for previous planes
Camera ray Projection in 3D
      ray.y += 1 * sin_Y;
     
      ray.x += 1 * sin_X * cos_Y;
      ray.z += -1 * cos_X * cos_Y;

Camera ray Projection in 4D
      pos.d += Dist * sin_D;
      pos.y += Dist * sin_Y * cos_D;
     
      pos.x += Dist * sin_X * cos_Y * cos_D;
      pos.z += -Dist * cos_X * cos_Y * cos_D;


Try it yourself and make a raycasting renderer and add a 4th vector component to the ray.
Is the 4 the maximum number of possible dimensions?
No, it could be any number of dimensions. 5D, 6D or even 111D =)

Binary link: http://www.2shared.com/complete/oWYgVUbR/4d_z.html
(couldn't put this into quotes...)

Hope this helps some people.
I've put some sentences into quotes ('), because I really couldn't understand what you wanted to say. Other than that, a cool article.

Also, your strange image host seems to make a lot of money with... stuff... (click on images Wink )

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline DQQAYME

Junior Member


Medals: 1
Projects: 1



« Reply #4 - Posted 2013-05-16 17:51:57 »

Quote from:  matheus23
I tried to correct your typos and grammar errors in your article
Big Ty I Try fix all Now;)

Quote from:  matheus23
Also, your strange image host seems to make a lot of money with... stuff... (click on images Wink )
Don’t make money for me at all, I take first hosting that find in Google.
If some one want I can change img hosting.

Offline theagentd
« Reply #5 - Posted 2013-05-16 21:26:48 »

4D? Just throw in some smell emitters and spray some water in the players' face.

Myomyomyo.
Offline DQQAYME

Junior Member


Medals: 1
Projects: 1



« Reply #6 - Posted 2013-05-16 22:35:11 »

Quote from:  theagentd
4D? Just throw in some smell emitters and spray some water in the players' face.
I am not kickstarter I don’t ask ppl pay me or do something for me =)
I have knowledge that I tested (in my opinion on this moment I this they right)
I share them.

Take them or throw them away, In any case I accept your choice.
Cheers. XD

Offline DQQAYME

Junior Member


Medals: 1
Projects: 1



« Reply #7 - Posted 2013-05-16 22:40:14 »

sorry wrong browser have double post

Offline theagentd
« Reply #8 - Posted 2013-05-17 01:56:39 »

I was joking how the "4D" label has been corrupted by stupid people who think smell is the same as adding an extra dimension. >___>

Myomyomyo.
Offline HeroesGraveDev

JGO Kernel


Medals: 215
Projects: 11
Exp: 2 years


If it wasn't Awesome, it wasn't me.


« Reply #9 - Posted 2013-05-17 06:54:42 »

@theagentd: I would have appreciated that if this weren't an article.

Have an imaginary virtual medal!

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline matheus23

JGO Kernel


Medals: 98
Projects: 3


You think about my Avatar right now!


« Reply #10 - Posted 2013-05-17 16:46:53 »

@DQQAYME:
If you wonder how to make those awesome-looking headers (the blue font), use headers:
1  
2  
3  
4  
5  
6  
/*
[h1]Top header, it's big[/h1]
[h2]Second header, slightly smaller[/h2]
[h3]Third header[/h3]
[h4]Fourth header, not available[/h4]
*/

The result is:

Top header, it's big


Second header, slightly smaller


Third header


[h4]Fourth header, not available[/h4]

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline DQQAYME

Junior Member


Medals: 1
Projects: 1



« Reply #11 - Posted 2013-05-17 20:16:55 »

Quote from:  matheus23
If you wonder how to make those awesome-looking headers (the blue font), use headers:
=)
Add New 4D Img (Cube) Matrix

int[2][2][2][2] = Two matrix int[2][2][2] - All simple, Any programmer know about that =)

Offline DQQAYME

Junior Member


Medals: 1
Projects: 1



« Reply #12 - Posted 2013-05-18 14:06:37 »

Add new fun imgs, Roll Eyes

p.s Camera Movement in 4D really hard understand Visual , even for me who know and understand all his maths Wink
Technical its simple if vision Ray collis wall - you see wall,
you see wall - you know you can’t go there.

But its really hard predict next position where you will be,
its something like camera strafe in 3d(3 Vectors, base strafe in 3d game is 2d - you move on ZX Plane)

Offline HeroesGraveDev

JGO Kernel


Medals: 215
Projects: 11
Exp: 2 years


If it wasn't Awesome, it wasn't me.


« Reply #13 - Posted 2013-05-18 21:24:54 »

Just make the player a 4D object, then add controls for movement in the fourth dimension.

Collision can be done with just a 4D AABB

Offline DQQAYME

Junior Member


Medals: 1
Projects: 1



« Reply #14 - Posted 2013-05-19 14:40:02 »

Yes, now you see that 4D is easy.
AABB do later, Have old AABB collis from World of Change project, but hi slow,
I want do new AABB ray cast collision Wink
Don’t want write crap code XD

Offline Roquen
« Reply #15 - Posted 2013-05-20 14:30:17 »

Complete unrelated, but Java doesn't have concrete nor flattened multidimensional arrays, so type[][][] with fixed lengths should be avoided (except in cases where your using the fact to quickly swap rows...for instance).
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

theagentd (6 views)
2014-04-24 23:00:44

xsi3rr4x (83 views)
2014-04-15 18:08:23

BurntPizza (75 views)
2014-04-15 03:46:01

UprightPath (86 views)
2014-04-14 17:39:50

UprightPath (69 views)
2014-04-14 17:35:47

Porlus (86 views)
2014-04-14 15:48:38

tom_mai78101 (109 views)
2014-04-10 04:04:31

BurntPizza (169 views)
2014-04-08 23:06:04

tom_mai78101 (265 views)
2014-04-05 13:34:39

trollwarrior1 (217 views)
2014-04-04 12:06:45
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!