Balder 3D Development Series-create a sky box

Source: Internet
Author: User

I. Concepts of skybox

The sky box is a method that gives the background of a computer game screen a wider view. When using the sky box, the horizontal screen is limited to a cube, in the background, distant mountains and rivers, buildings in the distance, and the sky are all projected into each area of the cube (this is the cube mapping method using cube projection textures ). Create a realistic 3D environment in this way. For more details, see the http://en.wikipedia.org/wiki/Skybox_ (video_games) below is the final piece of this article:

 

Ii. sky box in Balder

The Balder engine provides a ready-made skybox, so we only need to use it and map it. Of course, you will ask, how is this implemented in Silverlight? For details, refer to its source code. This series is only about the basic application of Balder, so the implementation principle is not considered for the moment, if you have the opportunity, you will be able to explain it in subsequent articles. Next, let's take a look at how to use skybox. The basic Code follows the article about material textures in Balder.

 

Iii. sky box practice drills

In order to make the article seem as simple as possible, in future articles, if there are no special circumstances, we will try to use the previous Code as much as possible (to improve the code reuse rate) and save the basic framework code, write only key code related to this section. To use skybox, you must introduce the following namespace:

Xmlns: Object = "CLR-namespace: Balder. Objects; Assembly = Balder"

It is in parallel with geometry and flat in obejects. For the first two things, we have used them before. In geometry, box, Sprite in flat. The usage of skybox, the main character of today, is roughly the same as the previous one. View the Code directly:

1 <execution: game. Skybox>
2 <object: skybox isenabled = "true"
3 front = "/materialdemo; component/assets/skybox_front.jpg"
4 back = "/materialdemo; component/assets/skybox_back.jpg"
5 Top = "/materialdemo; component/assets/skybox_top.jpg"
6 Bottom = "/materialdemo; component/assets/skybox_bottom.jpg"
7 left = "/materialdemo; component/assets/skybox_left.jpg"
8 Right = "/materialdemo; component/assets/skybox_right.jpg"
9/>
10 </execution: game. Skybox>

 

From the code, we can see that skybox is an attribute of the game object, and the texture attributes in skybox are front, back, top, bottom, left, right, which respectively represent the front of the cube, back, top, bottom, left, right. Note that the isenable attribute must be set to true to display skybox. Now, we have finished a skybox. To enable the observer to fully observe the entire skybox, add the following code to the code hidden file that controls the camera position:

1 public partial class mainpage: usercontrol
2 {
3 double _ Sin = 0;
4 Public mainpage ()
5 {
6 initializecomponent ();
7 dispatchertimer timer = new dispatchertimer ();
8 timer. interval = timespan. frommilliseconds (20 );
9 timer. Tick + = new eventhandler (timer_tick );
10 timer. Start ();
11}
12
13 void timer_tick (Object sender, eventargs E)
14 {
15 var x = system. Math. Cos (_ Sin) * 50;
16 var y = system. Math. Sin (2 * _ Sin) * 50;
17 var z = system. Math. Sin (_ Sin) * 50;
18 camera. position. x = X;
19 camera. position. Y = y;
20 camera. position. z = z;
21 _ Sin ++ = 0.006;
22}

Okay, let's get it done. Let's see how it works:



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.