Nvisionxr_ios Tutorial Five--adding light rendering

Source: Internet
Author: User

In the previous chapter, this chapter describes the use of three lights (parallel light, point Light, Spotlight).
Introducing Header Files#import ' NVWorldLight.h ' 
1, creating a parallel light
in theonCreateinside the instance light object, code such as
 
Code:

    //  lights, ground, particles belong to the World object, so you need to create from Nvworld       //  first verify that the scene has added a light with the same name, because you want to ensure that the object creation is unique      nvworldlight  *light =  (nvworldlight *) [[self getworld] getobjectbyname:@ "Dir_light"];      if  (!light)  {         light  =  (nvworldlight *) [[self getworld] createobject:light objectname:@ "Dir_light"];          //  Set the light type           [light setType:DIRECTION];         //  Set the coordinates of the light          [light setdirection:nvposition (0, -1,  0)];     } 



in onstart
 
code:  

    nvworldlight *light =  ( nvworldlight *) [[self getworld] getobjectbyname:@ "Dir_light"];     //   Add lights to the scene      if  (light)  {           [light attach:self];     } 

in onstop
 
code:  

Nvworldlight *light = (nvworldlight *) [[Self Getworld] getobjectbyname:@ "Dir_light"];     Remove the lights from the scene if (light) {[Dettach]; }



This completes the creation, addition, and removal of the lights, running the project, comparing the previous chapter without lighting.
 
The cube's four sides have obvious shading effect, appear more real.

2, creating a point light
creating a method is similar to a parallel light, such as needing to be aware that the point light does not have a direction, so you do not need to set the light direction (it is also invalid), and the point Light has a position.
 
Code:

    //  lights, ground, particles belong to the World object, so you need to create      //  from Nvworld First verify that the scene has been added with the same name, because you want to ensure that object creation is unique      NVWorldLight *light =  ( nvworldlight *) [[self getworld] getobjectbyname:@ "Point_light"];      if  (!light)  {         light =  (nvworldlight  *) [[self getworld] createobject:light objectname:@ "Point_light"];          //  Set the light type          [light  settype:point];         //  set the coordinates of the light           [light setposition:nvposition (2.0, 2.0, 2.0)];          //  set whether the light has attenuation          [ light enableattenuation:yes];     } 



The addition and deletion of light and parallel light, as long as the corresponding light object name can be found, there is no code.
 

run the project, because the light position is in the upper right corner of the cube, so you can see the cube right up, the rest is darker.

2, creating Spotlights
Create the same method as the point light, but the spotlight has a direction and position,
 
Code:

    //  lights, ground, particles belong to the World object, so you need to create      //  from Nvworld First verify that the scene has been added with the same name, because you want to ensure that object creation is unique      NVWorldLight *light =  ( nvworldlight *) [[self getworld] getobjectbyname:@ "Spot_light"];     if   (!light)  {         light =  (nvworldlight  *) [[self getworld] createobject:light objectname:@ "Spot_light"];          //  Set the light type          [light  settype:spot];         //  Setting the light direction           [light setdirection:nvposition ( -1, -1, -1)];          //  set the coordinates of the light          [ Light setposition:nvposition (1.0, 1.0, 1.0)];         //  Set whether the light has attenuation           [light enableattenuation:yes];     }

The addition and deletion of lights is the same.
 
run the project, because the light position is in the cube right front, the direction of the light is inclined to the object, so you can see the cube right front of the corner is very bright, the rest is dark, the effect

with this section, you should have mastered the light loading, and in the next section I'll show you how to interact with the objects in the scene.

Welcome to contact:

    • Contact information: +86 18801341080

    • E-mail: [email protected]

    • Website: http://www.nvisionxr.com/

    • QQ Group: 416802300



Nvisionxr_ios Tutorial Five--adding light rendering

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.