# Sky Box

Post your own tutorials, guides and demos.

### » Mon Sep 01, 2008 12:57 am

Man, that looks really awesome.
Moderator
B
114
S
41
G
20
Posts: 1,586
Reputation: 19,161

### » Fri Nov 26, 2010 4:36 pm

wow, i would totaly need that for the FPP parts of my game. if i would know how to execute this that is
still - awesome effect
B
29
S
8
G
7
Posts: 643
Reputation: 6,482

### » Sun Jan 30, 2011 2:47 am

I'd like to use this as a backdrop effect for a platformer game, but I don't quite understand all the events. Could you maybe explain or comment it?
B
2
S
1
G
3
Posts: 71
Reputation: 1,142

### » Sun Jan 30, 2011 12:16 pm

Y is up/down. X is left/right. Z is front/back.

Yaw: rotation around the Y axis - spinning like a top
Pitch: rotation around the X axis - spinning forward/backward
Roll: rotation around the Z axis - spinning side to side

[code:zaizl332]Set yaw to 0 - mousex / 4:[/code:zaizl332]
Sets the angle along the Y axis to mousex (the actual position of the mouse, in pixels). Divided by 4 so it doesn't spin too fast. The "0 -" part inverts the angle so that it spins in the direction of the mouse movement, remove the "0 -" to invert the mouse movement.

[code:zaizl332]Set pitch to clamp(-90,(mousey - 240)/4 ,90)[/code:zaizl332]
Sets the angle along the X axis to mousey, minus the center of the screen. Since the window is 480px tall, that would be 240. Divided by 4 so it doesn't spin too fast. The angle is also clamped between -90 degrees and 90 degrees so you can't look beyond "all the way up" and "all the way down," although David has made a small error in using clamp() here, and the proper expression should read clamp((mousey - 240)/4, -90, 90). Adding "0 -" to the beginning of this would invert the mouse movement.

Hope this helps.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

### » Mon Jan 31, 2011 9:50 am

Thanks pal.

How does the thing work though? Like, why are there two boxes, and how does the script create the skybox effect?
B
2
S
1
G
3
Posts: 71
Reputation: 1,142

### » Mon Jan 31, 2011 9:59 am

There are two boxes because... I don't know, David just wanted another box in the scene to spin around? I guess.

And the script doesn't create the skybox effect, the sky texture on the box creates the skybox effect. Hence the term "skybox." It's a sky... on a box.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

### » Mon Jan 31, 2011 3:15 pm

[quote="Drule":18dghsow]Thanks pal.

How does the thing work though? Like, why are there two boxes, and how does the script create the skybox effect?[/quote:18dghsow]
If you've ever used a 3D application like 3D max or Maya, you'll probably know that a 3D model, even something as simple as a cube, can be textured one-sided or both sides.

In 3D modelling, especially rendering a scene, it's simple to create a square room by either texturing both sides of the cube or by flipping the normals so that the textures show on the opposite side of the polygons, so that when the camera is inside the cube, you have your room.
If you enlarge this, it can be used as a skybox that encapsulates your whole scene.

The 3D box in Construct textures both sides of the polygons, so by expanding the size of the cube (the three "start of layout" commands) you push the faces so far out that you can never see them with the camera because they're actually far behind your camera view, and you're effectively always seeing the inside of the cube.

Then you have the simple code that determines the cubes rotation dependant on the mouse.

If you change the initial sizing code for the cube to:

[color=#BF0000:18dghsow]+ System: Start of layout
-> 3DBox: Set width to.Width * 10
-> 3DBox: Set height to.height * 10
-> 3DBox: Set depth to.depth * 10[/color:18dghsow]

...you'll see the effect clearly, and it will be obvious that you're looking at the inside of the cube.

I think David just put the other box in there as a reference to the rotation of the outer box for those who wanted to know how it was moving.

HTH,
Krush.
B
2
S
2
G
3
Posts: 406
Reputation: 2,062

### » Tue Feb 01, 2011 8:30 am

Oh, so the box is just huge and encapsulates the player, camera and level completely?
B
2
S
1
G
3
Posts: 71
Reputation: 1,142

### » Tue Feb 01, 2011 6:55 pm

[quote="Drule":3lhb0ruc]Oh, so the box is just huge and encapsulates the player, camera and level completely?[/quote:3lhb0ruc]
Yep.

Like I said, change the 100 to 10 at the start and you'll be able to see the cube clipping as you rotate.
By setting it to 100, it meant that the edges of the cube could never touch the camera as long as it was rotating around it's centre, which it is.

Krush.
B
2
S
2
G
3
Posts: 406
Reputation: 2,062

Previous