Experiment 5: Mouse selection of game entities

Source: Internet
Author: User

Experiment 5: Mouse selection of game entities

I,Lab content:

1. Create a simple game scenario and create some game roles in the scenario;

2. Use the ray scene query to prevent the camera from traversing the ground;

3. Ray-based Scenario query is used to enable Mouse clicking and drag-and-drop operations for a single game role;

4. Use a manual object to create a rectangle selection box;

5. Use space scenario query to select and drag and drop multiple game roles;

II,Purpose:

1. Understand the working principle of Ray scene query, and be familiar with the use of the RaySceneQueries class and Its Application in scenario selection.

2. Understand how to create manual objects and how to use the ManualObjec class.

3. Understand the working principle of spatial scenario query, and be familiar with the use of the PlaneBoundedVolume class and Its Application in scenario selection.

Iii. Experiment steps

1,Framework establishment and objectives

Refer to the Ogre Chinese Wiki and set several goals:

First, make a small improvement, because it is very troublesome to initialize the device window every time, and find the Root restore method. First of all, we want to right-click the mouse and bind it to the "Mouse observation" mode. It is rather depressing not to use the mouse four times, so we should first add mouse control to the Program (although only when we keep the right mouse button pressed ).

Second, we want to prevent the camera from penetrating the surface. This will bring it closer to what we expected.

Third, we want to add an object there by clicking the left mouse button on the surface.

Finally, we want to "drag" objects. Select the object we want to see, hold down the left mouse button, and move it to the place we want to place it. Release the left mouse button and lock it again.

...

The first step is very simple. Copy the previous experiment framework.

2,CeGUI ImprovementChina Unicom:

Using CeGUI of version 0.75 can be described as a constant problem. First, you must set up your own initialization CeGUI,

The message that is converted to CeGUi when the key bit is read:

Register the Response Message of quit as the quit function of the App (an error will be reported when it is registered as the quit function in the listener)

Inject the mouse message into the CeGui In the listener:

The Quit function simply uses a m_bQuit variable.

Exit when m_bQuit is true:

Debugging result:

3,Terrain collision detection, camera height

Transmit a vector at the camera's position and use mRaySceneQuery to obtain the height of the Current Ground and obtain the RaySceneQueryResult at the camera's position.

The angle of view will no longer have a puncture on the ground:

4,Terrain Selection

Correct a bug and inject the CeGUI message in message processing;

Use the Camera: getCameraToViewpointRay provided by Ogre; a useful function that converts a click (X and Y coordinates) on the screen into a Ray for the RaySceneQuery object.

Obtain the WorldGeometry location in the center of the current Angle of View:

When you move the mouse, if you keep pressing the left button, move the location of the new Entity:

Results, such:

Iv. experiment data and processing results

The results are all given, the code is included with the project...

5. Think about the question or experience or suggestions for improving the experiment

The ability of Ogre depends on your imagination.

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.