GameEngineering_2: Sprite rendering

Description

  • Draw a 2D “sprite” overlay
  • Draw a sprite that uses a texture “atlas”

Reading Time: 1.0 hours

Coding Time: 5.5 hours

Write-up Time: 1 hours

Total Time: 7.5 hours

Download Link: http://blogs.eae.utah.edu/jdong/wp-content/uploads/sites/13/2014/12/game.zip

Achievement

1. Create the new Sprite class to draw a 2D overlay

In general, sprite is a 2D object which is similar to actor game object, but they are different in following:

Sprite only has vertex buffer while actor has vertex buffer and index buffer. The reason is that sprite only needs four vertexes.

Sprite vertex only needs the information of position and uv coordination, although it could still share the vertex format with actor class.

Sprite draw function is DrawPrimitive rather than DrawIndexPrimitive.

Based on those differences, here is my sprite class:

11.01

And in my World and Graphics component, before each component has Vector<Actor> list to store all actors in the game. Now I need to add Vector<Sprite> list to store the sprites game objects.

11.02

And for DrawPrimitive, we used the draw type D3DPT_TRIANGLESTRIP. The reason is that if we used D3DPT_TRIANGLELIST, we must use index buffer. But now we only need to draw a few triangles, so we could use D3DPT_TRIANGLESTRIP. In order to use D3DPT_TRIANGLESTRIP, we must define the order of the vertex in a different way, like the following:

11.03

Now the order is like in the shape of Z.

Final Effects:

11.04

11.05

2. Create the new Sprite “atlas”

By using atlas, we could make a sprite with shared texture, and even we could achieve a kind of simple animation by taking advantage of the atlas.

In my project, you could change the atlas by pressing the key from 0 – 9.

11.06 11.07

To achieve this, the UV of the atlas sprite should be changed according to the keyboard input.

Pixel Debugging:

11.08 11.09

 

11.10

Problems I met

1. Use a new vertex format

At first, I thought the sprite vertex only has two information: position and uv, so I created a new vertex format called sVertex. Then I learned from class e-mail that there is no need to create a new vertex format for just a simple sprite. So at last my sprite vertex shares the same vertex format with actor’s vertex format.

2. Mysterious bug fixing

Remember in previous I mentioned that my camera movement is not so smooth. I have asked JP and Jamie and tried several solutions but it did not work. And tonight I found that my program only update camera’s position when there is new input. Once I added the camera position update function to the branch  where there is no message sent from the window, the problem has been fixed. I still don’t know why this problem has been fixed in this way.  I guess it would take a while to check whether there is new message from the window or not. So when there is new input, the camera update function will not be called immediately.

11.11

Thesis Game – Week_12_Work: New game level map built and hanged scarecrows trigger

This week we have the new game map level and also I added the hanged scarecrow trigger to the new map:

1. New game map level

10_1

 

 

Elements:

1. House

  • Function: A warm and safe place. Player will get the information and clues here.

2. Barn

  • Function: Creepy and weird place. Current design is that barn contains a machine which player needs to interact with.

3. Silo

Function: Not decided yet.

4.Well

  • Function: A place with a puzzle. Probably it will be a hidden place for player in the last level of the game.

5. Windmill

  • Function: A place surrounded with the crows. Also it could be the alarm for the dust storm.

6. Dry Lake

  • Function: Create the atmosphere of the death.

7. Sheds

  • Function: Player could get the item (some useful tools ).

8. Corn

  • Function: Create the obstacle for player’s vision; it is also the place where the scarecrows could hide.

9. Animals Platform

  • Functions: Full of dead animals body, gross and dirty.

2. Hanged Scarecrows Trigger

8_1 10.5

When the player triggers the hanged scarecrow trigger, the scarecrow will fall down ( from the tree, the roof…). This is inspired from the SH3 ghost house  design and we want to create the jump scare for the player.

10_6

Thesis Game – Week_11_Work: Game’s New Map and New Structure

Design of the game’s structure

Description:

Game has three game levels, each level use the same game map. The transitions between each level is triggered by the events. And each game level represents one time at a day.

10.1

Each game level, the brief process of the player is:

Get out of the house — Experience event — Finish Level’s goal (Trigger the transition) — Dust bowl comes – Come back to the house (or die outside)

About the events

The events structure is not linear. Here is a brief explanation:

 10.2

Basic event is the event that player must finish. It is the goal of the each level.

Additional event is the event that player could miss or he could still interact with, but the result will affects the next level’s event.

For example, in game’s level one, player must finish event A to get to the level 2. He might miss the event 1 or event2, but it is OK as he could still move to the level2. What will happen next is that he will find next game level will change due to his behavior.

So no matter what player does with the additional events, the game still moves on, which is a linear process. But the additional events would affect the following events. Now the whole process is kind of nonlinear. It gives player more freedom to interact with the game, and also this could fix the problem of the open space with a linear gameplay experience.

10.3

About the transition

After player complete the basic events (goal) of the level, the transition timer would be triggered. That means player will still have some time to hang around in the game level. And when the time is out, the dust bowl comes (or scarecrow wave attack). Before the dust bowl comes immediately, the player will be informed by sirens or alarm alert.

Now the player could choose to come back and stay alive or he will die because of the dust bowl. When the player comes back to the house, current level ends.

Temporary Level 1 Design

Before the level 1 goal is to get the lantern, and this would not change. What’s different here is that in level 1 player needs to get the lantern to explore the farm. The goal of the first level is to let player be familiar with the farm and create the anxiety for him.

When level 1 begins, player is informed to check the farm as usual (no explanation for why the character is back in this farm again). In order to explore the farm at night, player needs the lantern.

After the player gets the lantern, the transition will be triggered (about 5 minutes).  Before the dust bowl, player could explore the farm. Here are what he might encounter:

Game Level Elements:

Gross animal pen, with bones and blood on the ground, everything is broken.

Barn is locked, and noise could be heard from inside (could be machine noise, human cry or scarecrow howl).

The first introduction for the scarecrow, as it is on the cross.

Crows fly around or land on the ground.

Empty well full of sand.

Basic Event

Get the lantern and explore the farm. Player does not know the lantern will trigger the transition. He only knows that he needs to get the lantern and explore the farm. This could discourage him from immediately going back to the house once he gets the lantern if he know the lantern is the level goal.

When the transition time is out, the dust bowl comes and player needs to get back to the house.

Additional Event

Doll hanged on the tree and player could not get it without a tool. (Doll is the goal of the level 2)

  • Player could find a tool in the sheds and get the doll.
  • Player could ignore that and keep moving.

If player does not get the doll in the level 1, when it moves to the level 2, player would find the rope that hangs the doll has been cut and the doll is on the ground, broken. When the player gets close, the hanged scarecrow will fall down. (Player might get hurt because the scarecrow fell down).

If player gets the doll in the level 1, when it moves to the level 2, the hanged scarecrow is already there. And player just moves on.

Because the doll is important for character’s daughter, so the player’s attitude towards it will affect the gameplay experience and the end of the game (good end, or bad end).

Scarecrow disappearance. When player meets the first scarecrow on the cross, when the scarecrow is triggered to disappear, then there will be a blood trail from the cross to the barn.

  • Player could follow the trail to the barn and might think about the potential danger in level2.
  • Player could just ignore that.

Because in level2, barn is an important place for game events. Player needs to go to the barn to fix the machine (temporary) and then meets with the scarecrow that is able to attack

 

GameEngineering_2: Diffuse Light

Description

  • Add ambient and directional lighting to your fragment shader
  • Add keyboard controls to change the direction of the light in real time

Reading Time: 1 hour

Coding Time: 2.5 hours

Write-up Time: 1 hour

Total Time: 4.5 hours

Download Link: http://blogs.eae.utah.edu/jdong/wp-content/uploads/sites/13/2014/11/game4.zip

Achievement

1. Add normal map into the mesh file

As my maya exporter has not included the normal information, this time I need to add the normals information first into my code. Here is the updated exporter code:

10.1

Then I exported the model mesh file one more time to input into my game. Now I need to change the structure of the vertex class and also the s_vertexElements stricture by adding the normal variable, which is a float3 array.  Right now it looks like this:

10.2

2. Change the shader file

First, for vertex shader, it needs to add new argument for its input and output:

in const float3 i_position_model : POSITION, in const float3 i_normal_model:NORMAL, in const float3 i_color : COLOR0, in const float2 i_uv : TEXCOORD0,
out float4 o_position_screen : POSITION, out float3 o_normal_world: NORMAL, out float3 o_color : COLOR0, out float2 o_uv : TEXCOORD0

Then we need to change the normal from the model space into the world space:

10.3

Second, for fragment shader, it needs to add new argument for its input just like what I did for vertex shader. Moreover, it needs to add light_diffuse and light_ambient variable.

  • diffuse light: In order to get the diffuse light value, we need two more variables, which are diffuse light direction and diffuse light color. Both of them are the new constants for the fragment shader and they need to be adjusted by my game’s code.
  • ambient light: It is also a new constant for the fragment shader and it needs to be adjusted by the game’s code.

Therefore, now I need to add three more constants into the shader:

10.4

To get the diffuse value, I used the Lambert’s law. Here the simplest way to use that is like the following:

10.5

 

Finally, I need to input the diffuse light and the ambient light into the shader by: float3 color_lit = color_albedo * ( lighting_diffuse + g_light_ambient );

Ok, now everything is ready except setting the constants in game’s code. Here I created another builder in my game called lightBuilder, it would read the light lua file and write it as binary file into the target data folder.

10.10

 

Then these constants value (diffuse light color, diffuse light direction and ambient color value) would be changed according to the light binary file. Here is the code:

10.6

 

3. Final result

10.7

You can change the direction light’s direction by moving the camera, which is controlled by WASD, just like this:

Move down

10.8

 

Move to the right

10.9

If you change the ambient light color, like ambient = {0.0, 0.2, 0.2 }. The image is like:

10.11

Finally this is the PIXEL debug result:

10.12 10.13

Problems I met

This assignment goes very smoothly, so does this write-up go to the end? Of course no!

I want to share with you about the Half Lambert Diffuse Shader. This shader I has mentioned before in Unity3D shader learning, and this time I could test it in my game.

In origin, the value of diffuseAmountis from -1 to 1. When the value is smaller than zero, the output image could be dark. In order to avoid the object’s edge losing and flat looking, I set the value diffuseAmountin the range of 0 to 1 by adding one sentence: float hLambert = diffuseAmount * 0.5 + 0.5;.

Half Lambert lighting can most often be seen being used on the characters face materials, it has been used in Half Life 2.

Here is the result:

1. Lambert Diffuse Shader

10.11

2.Half Lambert Diffuse Shader

10.14

I have to say, for this SH3 rabbit, the Lambert Diffuse Shader is better… 🙂

———————————————————————————————–

Tonight I am trying to add the specular light into the game and here is the basic introduction of the specular light:

Specular Reflection

  • reflection off of shiny surfaces – you see a highlight
  • shiny metal or plastic has high specular component
  • chalk or carpet has very low specular component
  • position of the viewer IS important in specular reflection

I = Ip cos^n(a) W(theta)
I: intensity
Ip: intensity of point light
n: specular-reflection exponent (higher is sharper falloff)
W: gives specular component of non-specular materials

So I changed the fragment shader again like this:

10.16

Now the game comes out like the following:

10.15

If you want the specular light, you can disable the comment in my fragment shader: //float3 color_lit = color_albedo * ( lighting_diffuse + g_light_ambient ) + g_light_direction_color * finalSpec; and comment this line: float3 color_lit = color_albedo * ( lighting_diffuse + g_light_ambient ); then it will come.

GameEngineering_2: Maya Exporter; more meshes/materials; PIX instrumentation; user settings

Description

  • Create a plug-in for Maya that will export geometry data in your human-readable mesh format
  • Render more objects
  • Add PIX instrumentation
  • Add a way for the player to specify settings for your game

Reading Time: 2 hours

Coding Time: 10 hours

Write-up Time: 1 hour

Total Work Time: 13 hours

Download Link: http://blogs.eae.utah.edu/jdong/wp-content/uploads/sites/13/2014/11/game5.zip

Achievement

1. Maya Exporter

In order to get the correct mesh information from Maya, I need to get the right mesh format which fits my game’s MeshBuilder. Here is the code of producing the correct format:

9.3

Then I could export the model from Maya. Here is the one mesh file:

9.4

Here is the final result:

Capture2

Now in my game, I used the actor to represent each game object. Each actor get its relative material, texture and mesh file by its name ( Actor.getType() ).  Now in my game, there are three game objects, Cube( Knife), Floor ( Floor ) and Sphere ( Rabbit ).  All three mesh files are: Cube.mesh.lua, Floor.mesh.lua and Sphere.mesh.lua.

2. Pix Instrumentation 

  • D3DPERF_BeginEvent()
  • D3DPERF_EndEvent()

I added these two function in my Draw() process.  And here is the result:

9.1

9.2

You can see in the “Draw the mesh” process, it would do “Set the material”, “Set Stream Source”, “Set Indices” and “Draw Indexed Primitive”.  In this way, you could get more clear about the game’s process and it is also easier for you to debug.

3. User Setting

In general, to achieve the user setting feature, you need to do the lua operation again. What we do here is reading the user setting value from a lua table and the pass these values into the graphic class or the window class. But here we need to think about more about the player’s behavior, what if they do something wrong like deleting all the values in the file? So I need to make sure the program would not crash easily ( better not forever ) besides reading the value from the lua table.

What I did is when the lua table has the problem, set the user setting value as default instead of returning the false value. Here is what the code like:

9.5

Of course this is only part of the code. This part only check the width value. In my game, if the user setting has the wrong value ( like string for width, or negative value for the width ), the game would use the default setting. Even the player deletes all the value in to user setting file or deletes the file itself, the game would not crash.

Problems I met

1. Change the vertex format of Maya to DirectX problem

What I have done for changing the vertex format from Maya to DirectX are following:

  • Change the vertex structure for Mesh class. As I know in shader, the color datatype is float and the range is 0.0 – 1.0, while DirectX uses DWORD( RGBA ) to represent the color, and the the range is 0 – 255. Because in Maya, the range of color value is also 0.0 – 1.0, so there is no need for me to use the  D3DCOLOR  in Vertex class. In this assignment, I change the structure of the Vertex class, now it is like this: Vertex( float position[3]; float color[4]; float uv[2] ).
  • Change the UV system. Maya’s coordinate system is different than the default Direct3D behavior, like UVs have (0,0) at the lower left corner. So I change the UVs value from Maya like this: TEXCOORD -> u, 1 – v.

After I have done this, the objects could be rendered, but in a wrong way. Then I realized the Maya is right handed system and I need to change the index, too. To change the index value correctly, I need to exchange the second and third value of each triangle, like this index ( value 0, value 1, value 2 ) -> index ( value 0, value 2, value 1 ). Then this problem has been fixed.

2. PrimitiveCountToRender Problem

When I have done the Maya Exporter project and import some awesome models I found online into the game, then I found only a small part of them has been rendered. At first I thought it was the texture problem as those models usually have over one texture. But then I realized that could not be possible as the model should be rendered completely even though there is no texture attached. After I used the D3D debugger to find the problem, I found the problem came from:

HRESULT result = s_direct3dDevice->DrawIndexedPrimitive(primitiveType, indexOfFirstVertexToRender, 0, vertexCountToRender, indexOfFirstIndexToUse, primitiveCountToRender);

The primitiveCountToRender value is still 12, which is the right number for a cube. But now the current object is more complicated than a cube, so this function could not work right now. What I have done to fix this problem is get the number of the index and then diveide it by 3.

3. Maya model size could not change 

When I tried to import the silent hill nurse model into my game, I found no matter how I change the seize of the model, the output file still showed the same vertex information. After I asked other students, I came to know that because I only changed the scale of the object, which would not affect the model’s vertex position. Scale is like the factor when the object is rendering, it would use Scale to change its size. But now the Maya output does not have the Scale information, so each vertex position is still the original position. To fix this problem, I change the vertex position of the model and then export that to my game. Now it works well.

I am also thinking about the scale in Unity. I think the scale affects the size of the object in game, and this is why the scale is one the three information ( other are position and rotation ) of the transform. I am assuming the original transform vertex information is still stored in the game, every time the scale has been changed, the new transform vertex information will be calculated by multiplying the new scale and the original vertex position.

4. Full Screen Black Problem

When I set the game’s screen as full size, then the screen is all black. Even when I run the first assignment, the full screen is still black. It took me a while to figure it out until Kehan found that the problem came from the backfuffer size. After several tests, we found that the buffer size has to be the exactly same with the current screen’s resolution.

Thesis Game – Week_10_Work: New Design and Solution for our game

Part 1: Scarecrow

The reason why we need to still work on the scarecrow is that the scarecrow is not creepy enough. As the scarecrow is the main horror element in our game, once it is not scared for the player, no matter how many new features have been added, our game is still not creepy enough. So keeping working on the scarecrow is one of the main tasks we need to do for this month.

According to player’s feedback, the problem of the scarecrow is that they seem to be not connected with each other. From the view of game AI, it means the AI for one single crow is great right now, but for crowds of scarecrow, it is not enough. So our design team thinks we should focus on the crowd AI.

Here are several solutions we have come up with:

1.     Wave Attack at interval, indicated by signal

At the ordinary game time, all scarecrows are merely hanging around in the game map. However, when the time comes to a certain point, all the scarecrow will head for the area where player is in. The player will get this information by a signal, like alarm alert.

What we want to create for the player is to make they feel nervous when they hear the alert. Like in Silent Hill (movie)

Horror-Movie-Wishlist-Silent-Hill-horror-movies-9186927-1052-700 The-Nurses-in-Silent-Hill-Revelation-2012-Movie-Image-2

2.     Hanged Scarecrow Trigger with the tree

The_Hanged_Man_by_Luktarig

When the player gets to the tree, the dead scarecrow will suddenly fall down from the top of the tree and be hanged there.

 

3.     Different Type of the scarecrow’s behavior

 Ghost-names-pac-man-8970067-519-503

Eg. 1) The scarecrow that always follows the player

2) Scarecrow that always tries to hide in some places to wait for player coming. You could take the example of the four types of the ghost in Pac-­‐man.

 

 

Part 2: Game Level Design

Before in our game level, the player seems to be easy to get lost. But once they could find the goal easily, there is no strategy for them to get the item, as they just need to go straight toward that.

silent-hill-2_0

So here we think the game level should like what Silent Hill 2 level’s like:

silent_hill_02

 

GameEngineering_2: Textures

Description

  • Create a TextureBuilder tool to create the texture for your project
  • Your cube and your floor plane must render with different textures

Reading Time: 2 hours

Coding Time: 5 hours

Write-Up Time: 1 hour

Total Time: 8 hours

Download Link: http://blogs.eae.utah.edu/jdong/wp-content/uploads/sites/13/2014/11/game3.zip

Achievement

1. DDS picture produce 

The format of the texture is “.dds”. It is the format that DirectX used as Direct Draw Surface. We could use the dds tool provided by DirectX, which you could find in DirectX Utilities folder. It is very easy to get the dds picture by using this tool. But here we will do it by coding the TextureBuilder project.

Similar to the projects we used in the previous assignment, the TextureBuilder project would get the source path of the picture ( which here is the texture ) file and the target path, which is the data folder. I used JP’s texturebuilder file in my assignment.

For the function D3DXCreateTextureFromFileEx(), one interesting thing about this function is that the argument  DWORD Filter. There are multiple filters. They are used for re-sizing. They are used if you specify a size other than what’s on disk, or if you use default size and don’t specify that non pow2 is okay, and the texture is not a power of 2 size.

For example, if you load a 48×48 texture, the load function will automatically make it a 64×64 texture, as it’s the next pow2 size that’s acceptable. If you specify a filter, it will use this filter to resize the image. The texture is filtered when loaded, and filtered more when rendered, creating quite a blurry image. If you specify a filter of NONE, it will load the image as is into the upper left part of the texture, and fill the remainder of the texture with black (possibly, and most likely, transparent black if alpha is part of the format). You’ll need to do more work to get accurate texture coordinates, but image quality will be better. Of course, you could just save the image as a pow2 size to begin with.

Here is the new file of my AssetToBuild file:

8.1

2. Texture Coordinates 

8.2

 

In order to map the texture to the object, we need to understand the UV coordination. This system change the map the texture pixel ( float ) range from 0.0f to 1.0f to the object’s pixel value in integer. If a texture’s width is 256 pixel, the first pixel is mapped as 0.0f, and the 256th pixel is mapped as  1.of.

The vertical direction is “V” and the horizontal direction is “U”.

In order to add the new vertex information, I changed the vertex shader arguments and also the vertices format of the mesh file. Here is the new shader and also the new mesh file:

8.4

I add a new input argument i_uv and a new output argument o_uv. And in the definition of this function, I added the “o_uv = i_iv;”

8.3

3. Attach the texture to the object

There are several part I have changed. First is the structure of the s_vertexElements[], the new format is like this:

8.5

Secondly, when the program reads the binary file, now it will read an extra argument, which is the uv value.

Third, set the texture of the direct device.

8.6

Here is the my game right now:

8.7

And here is the screenshot of the Pixel Tool:

8.8

And what I want to talk about more is the Texture Filtering.

In msdn, it is described as:

When Direct3D renders a primitive, it maps the 3D primitive onto a 2D screen. If the primitive has a texture, Direct3D must use that texture to produce a color for each pixel in the primitive’s 2D rendered image. For every pixel in the primitive’s on-screen image, it must obtain a color value from the texture. This process is called texture filtering.

When a texture filter operation is performed, the texture being used is typically also being magnified or minified. In other words, it is being mapped into a primitive image that is larger or smaller than itself. Magnification of a texture can result in many pixels being mapped to one texel. The result can be a chunky appearance. Minification of a texture often means that a single pixel is mapped to many texels. The resulting image can be blurry or aliased. To resolve these problems, some blending of the texel colors must be performed to arrive at a color for the pixel.

Direct3D simplifies the complex process of texture filtering. It provides you with three types of texture filtering – linear filtering, anisotropic filtering, and mipmap filtering. If you select no texture filtering, Direct3D uses a technique called nearest-point sampling.

In order to set the filter of the texture map, we need to use the function 

HRESULT SetSamplerState(
  [in]  DWORD Sampler,
  [in]  D3DSAMPLERSTATETYPE Type,
  [in]  DWORD Value
);

1. Nearest-Point Sampling ( cost less, poor texture effect )

g_device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
g_device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);

2. Linear Texture Filtering ( between the 1 and 3 )

g_device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
g_device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);

3. Anisotropic Texture Filtering ( cost most, great texture effect )

g_device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_ANISOTROPIC);
g_device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_ANISOTROPIC);
g_device->SetSamplerState(0, D3DSAMP_MAXANISOTROPY, 4);

The following are Nearest-Point Sampling,  Linear Texture Filtering and Anisotropic Texture Filtering (from left to right ). And you can see the difference.

Nearest-Point Sampling
7.9
Linear Texture Filtering
8.0
Anisotropic Texture Filtering

7.10

Problems I met

1. uv mess problem

After I implement the texture, the texture on the object is just like in a mess. The reason is that the structure of the s_vertexElements has not been changed. After I changed the format of that,  the texture shows normally.

 

 

GameEngineering_2: Binary mesh file

Description

  • Create a human-readable mesh file format using Lua
  • Create a new MeshBuilder tool
  • Change your game/engine code to load the binary cube and floor meshes from the built files rather than having the data hard-coded

Reading Time: 4 hours

Coding Time: 11 hours

Write-Up Time: 1.5 hours

Total Time: 16.5 hours

Download Link: http://blogs.eae.utah.edu/jdong/wp-content/uploads/sites/13/2014/11/game.zip

Achievement

1. Mesh Format

This is the mesh format I used in my project:

7.1

The first two numbers represent the count of the vertex and index.  For each vertex, it stores the position information and color information in a table that has no key value. And also for the indices, it stores its value in an integer array, where three numbers represent for one triangle.

/******************************************Jinghui Dong’ Blog *****************************************************/

2. Lua Function

In the previous project, I used the lua function created by JP. Those functions mostly are like “LoadTableValue” and “LoadTable”, meaning they either load the table or load the value of the table. However, the method is not so good, especially there are table in a table in table ( endless…). If I keep reading lua table in this way, I will need to create countless lua read function, which is stupid. So, I create my own Lua Table Helper Class to help the mesh builder read the lua value from the lua file.

In general, I need three types of lua function: 1) LoadTable( load the lua table with the path provided ); 2) GetToStack ( check whether the variable has been successfully on the top); 3) Get ( get the variable and return it).

So I create my LuaTableHelper class and implement those three functions. Particularly, I set the Get function as a template function.

7.2

For the GetToStack function, it will the situation that the table you want has a key value or not. To successfully get the required table, it will relatively needs two different functions:

lua_getfield and lua_rawgeti. If I want to look for a table with key value, I could use lua_getfield, and if I want to look for a table without a key value, I can use the function lua_rawgeti, like this lua_rawgeti(lua_state, -1, index). The index means the number of the lua table in order. In my project,  lua_rawgeti(lua_state, -1, 0) could means loading the first table in Vertices table.

/******************************************Jinghui Dong’ Blog *****************************************************/

3. Write and Read Binary File

Once I get the count of vertex and index and also the buffer of both of them, I could write them into the binary file. Just like this:

7.3

Remember to change the data type of each variable to (char*).

This is my binary file:

7.4

Then in my mesh class, I could read these binary files an assign the value to my mesh’s vertex buffer and index buffer.

7.5

7.6

   /******************************************Jinghui Dong’ Blog *****************************************************/

Problems I met

This time, I would like to describe the whole process of my programming.

Before I started, I listed three problem I would meet for this assignment:

1. How to read the lua table from the mesh file?

2. How to put the variables I read from lua file to binary file?

3. Is there any change in mesh class as now it would read the variable from binary file?

In general, most of the problem I met in this assignment came from the question 1.

 First, I found the biggest problem is how to traverse the lua table.  And there is the solution:

7.7

The -2 in stack is the key and the -1 in stack is the value.  And before you pop out the value from the stack, you could do some process, like storing it to a variable.

After I finished this, an error came out:

1. command … exited with code -1073741819

To solve this problem, 1) first I checked whether the extension of the file is wrong. No thing was wrong. 2) Anything wrong with the file’s path? No was wrong. After about another one hour check, I found a strange result. Each time I built the project for the first time, this error would come out. But if I build the project again, this error disappeared. So there might be some problems with the building dependence. And yes! This is the problem! After I fixed the order of the project dependence. This problem has been solved.

Then another problem showed up. The old friend:2. LNK 2019. This problem came from my LuaTableHelper class as the definition of the template function should be put into the header file rather than the cpp file.

And the last big problem I met, which forced me to stay up all night, 3. was the lua table reading process problem. Even though the lua class was created successfully, the value my program read from the lua file was still not correct. You know, debug the lua function is hard. And finally, I solved this problem by using std::cout  a lot to see the debug information. I found my program failed to read the vertex table with no key value. At that time I found out I need to use lua_rawgeti function.

This is the debug information which helps me to solve this problem:

7.8

It shows the value from the lua table and also how many values have been read from the file, making it easy for me to check whether the value is right or not and also whether some values have been missed. In this picture, you can see the position information and the color information have been successfully read from the lua file.

Thesis Game – Week_9_Work: Player’s Feedback

Design and Programming

  1. Easy to get lost and confused to get lost. I could not find the goal of the game level. (part 2)
  2. No feedback of the health point and I don’t know whether I am injured. Now I feel very safe even though I have been attacked before.
  3. The scarecrow’s behavior is not scared. There is no information to suggest its approach. And also I don’t feel they are around me when I was playing the game.
  4. The height of the player is too low and I don’t feel comfortable.
  5. The change after death is confusing. I thought it was another scene at first, and then I realized I am dead.
  6. Our game’s cost of the memory is too high.
  7. No inventory for the game item, making me confused after I have picked up the item, especially after I was dead.
  8. When I face backward to the picture on the table, I could still access to that.
  9. The way of crouch is weird.

 

Art

  1. The texture of the scarecrow should be improved, and the model is not sacred enough.
  2. Could not understand the meaning of the picture on the table.
  3. Scarecrow needs the animation, even when it is frozen.
  4. Use more light to bake the scene to create a better game level.
  5. It is too dark for the outside level.
  6. The texture of the door is not good.
  7. Need a better shader. Now everything is too Unity style.

 

 

Thesis Game – Week_8_Work: Blood rain particle system and dying crows surrounding effect

This week is what I did for our game project is the following:

1. Blood Effect

  • Blood Trail on Ground

8_2

  • Blood Rain

8_3

2. Dying crows surrounding effect

When the player has been attacked by the scarecrow, several crows will be created. The number of the crows will be decided according to the health point that player still has.

10.4

8_4

When the player’s health point is lower than 4 ( the full health point is 5), there will be 10 crows. If the health point is lower than 2.0, there will be 20 crows. Last if the health point is lower than 1.0, all the surrounding crows will attack the player.