Cainiao also learns ogre-camera light projection

Source: Internet
Author: User

Settings of light, shadow, and camera in ogre
1. To enable shadow, first call scenemanager: setshadowtechnique () and then call entity: setcastshadows () for the entity to be enabled ().
2. The lights and cameras must be created by scenemanager, which are scenemanager: createlight () and scenemanager: createcamera ().
3. you can create multiple cameras to manage ogre: viewport * Vp = mwindow-> addviewport (mcamera) with the view, and set the background color of the view using setbackgroundcolour ().
The main code is as follows:
Void tutorialapplication: createscene (void)
{
// Set the environment light to black
Mscenemgr-> setambientlight (Ogre: colourvalue (0, 0, 0 ));
// Set the projection type
Mscenemgr-> setshadowtechnique (Ogre: shadowtype_stencil_additive );
// Create an entity
Ogre: entity * entninja = mscenemgr-> createentity ("ninja", "ninja. mesh ");
// Set whether to project
Entninja-> setcastshadows (true );
Mscenemgr-> getrootscenenode ()-> createchildscenenode ()-> attachobject (entninja );
// Create a plane
Ogre: plane (Ogre: vector3: unit_y, 0 );
Ogre: meshmanager: getsingleton (). createplane ("Ground", ogre: resourcegroupmanager: default_resource_group_name,
Plane, 1500,150 0, 20, 20, true, 1, 5, 5, ogre: vector3: unit_z );

Ogre: entity * entground = mscenemgr-> createentity ("groundentity", "Ground ");
Mscenemgr-> getrootscenenode ()-> createchildscenenode ()-> attachobject (entground );

Entground-> setmaterialname ("examples/Rockwall ");
Entground-> setcastshadows (false );

Ogre: light * pointlight = mscenemgr-> createlight ("pointlight ");
Pointlight-> settype (Ogre: Light: lt_point );
Pointlight-> setposition (Ogre: vector3 (0,150,250 ));

Pointlight-> setdiffusecolour (1.0, 0.0, 0.0 );
Pointlight-> setspecularcolour (1.0, 0.0, 0.0 );

Ogre: light * directionallight = mscenemgr-> createlight ("directionallight ");
Directionallight-> settype (Ogre: Light: lt_directional );
Directionallight-> setdiffusecolour (Ogre: colourvalue (. 25,. 25, 0 ));
Directionallight-> setspecularcolour (Ogre: colourvalue (. 25,. 25, 0 ));

Directionallight-> setdirection (Ogre: vector3 (0,-1, 1 ));

Ogre: light * spotlight = mscenemgr-> createlight ("spotlight ");
Spotlight-> settype (Ogre: Light: lt_spotlight );
Spotlight-> setdiffusecolour (0, 0, 1.0 );
Spotlight-> setspecularcolour (0, 0, 1.0 );

Spotlight-> setdirection (-1,-1, 0 );
Spotlight-> setposition (Ogre: vector3 (300,300, 0 ));

Spotlight-> setspotlightrange (Ogre: Degree (35), ogre: Degree (50 ));
}
Void tutorialapplication: createcamera ()
{
// Create a camera
Mcamera = mscenemgr-> createcamera ("playercam ");
// Set the camera position
Mcamera-> setposition (Ogre: vector3 (500 ));
// Set the camera orientation
Mcamera-> lookat (Ogre: vector3 (0, 0 ));
// Sets the visible distance of the camera.
Mcamera-> setnearclipdistance (5 );
// Create a skdcamera
Mcameraman = new ogrebites: sdkcameraman (mcamera );
}

Void tutorialapplication: createviewports ()
{
// Create a view
Ogre: viewport * Vp = mwindow-> addviewport (mcamera );
// Set the background color of the view.
VP-> setbackgroundcolour (Ogre: colourvalue (0, 0 ));
// Set the camera display ratio of the view.
Mcamera-> setaspectratio (Ogre: Real (VP-> getactualwidth ()/ogre: Real (VP-> getactualheight ()));
}

Remember to modify resources. cfg and locate the resource search directory to the Media Directory of the source code sample. Otherwise, the compilation will prompt that the file cannot be found.

Running effect:


2012-7-14

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.