FPS Camera Mouse Look in DirectX

Youtube video:
http://youtu.be/vN-uyni45yk

 

Step1: Find mouse position

POINT p;
if (GetCursorPos(&p))
//cursor position now in p.x and p.y
float x = static_cast<float>(p.x);
float y = static_cast<float>(p.y);

Step2: Convert positions to usable values
//Normalize posiitons
x = 2 * x / static_cast<float>(SCREEN_WIDTH) – 1;
y = 2 * y / static_cast<float>(SCREEN_HEIGHT) – 1;

Step3: (Optional)
You can multiply the above values with a ‘sensitivity’ factor to adjust the sensitivity of mouse.

Step4: Assign values to Camera rotation
CAMERA.rotation.x = sensitivity * x;
CAMERA.rotation.y = -sensitivity * y;

I set sensitivity to 5.

Step5:
We shall use the ‘D3DXMatrixLookAtLH’ function in the camera to get the World to View matrix.

D3DXMATRIX* D3DXMatrixLookAtLH(
  _Inout_  D3DXMATRIX *pOut,
  _In_     const D3DXVECTOR3 *pEye,
  _In_     const D3DXVECTOR3 *pAt,
  _In_     const D3DXVECTOR3 *pUp
);

pEye-> Camera’s position
pAT-> Look at position..A point in world co-ordinates where the camera will look at
pUp-> The Up vector..normally set to D3DXVECTOR3(0, 1, 0)

We need to find the pAt vector.
We have the rotation of the camera.
We can use trigonometry to calculate a point which is at unit distance away from the Camera’s position and which is at ‘x’ degrees in XZ plane and ‘y’ degrees in YZ plane.

We can do this as follows->

D3DXVECTOR3 lookForward = D3DXVECTOR3(0,0,0);
lookForward.x = sin(transform.rotation.x );
lookForward.z = cos(transform.rotation.x );
lookForward.y = sin(transform.rotation.y );

Step6: Calculate pAt point.
So ‘lookForward’ gives us the look At point with respect to the origin. Add this to the camera’s position to get the effective look at point.

lookForward += CAMERA_POSITION;

Step7: (Optional)
You can now calculate the forward vector of the camera. You can use this to move camera’s position in the direction it is looking at.

D3DXVec3Normalize(&transform.forward, &D3DXVECTOR3(lookForward – CAMERA_POSITION));

The final matrix creation will look like this

D3DXMATRIX transform_worldToView;
D3DXMatrixLookAtLH(&transform_worldToView, CAMERA_POSITION, &(lookForward), &D3DXVECTOR3(0, 1, 0));

All is Dust – Mom and broken mirror

My mom came to visit me this week. She took a tour of the beautiful Salt Lake City. I brought her in to the lab during projects class. She played the Oculus version of the game. She found the experience exciting and innovative. She is not gamer, but there is no one who would not appreciate the Oculus the first time they tried it.

This week, I tried to make a more realistic mirror. I found a few shaders online. The shader worked well in their respective game projects. However, they wouldn’t work on All is Dust. I would guess that the problem lies in the game shaders. We had changed a couple of shader for the corn. I think this might’ve broken the reflection shaders.

Broken_mirror_chaos_deities_death

All is Dust – Better Lightening

By adding the bloom effect, the lightening had improved a lot. However, I felt that it could be improved. In reality, the light of a lightening strike is a flash that lasts for a split second. There are also multiple flashes instead of one. So I changed the lightening such that when triggered, there are two split second flashes. This made it even more realistic.

After play-testing, we figured out that the lightening helped the player look at far off places in the game world which helped in keeping himself oriented, especially in Night2 when the player is surrounded by a lot of dust.

All is Dust – Fire Bug

We ran into an issue with the fire in Night 3. The fire would turn on and off abruptly which would break the immersion. I spent a lot of time googling on this issue. I wasnt too successful. Gagan suggested that I should change the shader of the dust. I did and it worked. What was happening was that the dust sprites would obstruct the fire particles. So when I changed the shader type to ‘additive’, it solved the problem. Im guessing that by making it additive, the dust and fire would blend together to preserve the fire intensity and at the same time keep the dust intensity.

All is Dust – Lightening Issues

The lightening effect would only work for either the Oculus build or the first person build. I dug into this issue. The lightening effect triggers a glow effect. This made the lightening more realistic. The glow effect script needs to be added to the camera. Different camera objects are active for the first person and the Oculus version. I took me a while to figure out why the camera objects were ‘null’. I finally changed the script to make it work on both versions.

All is Dust – Unity 5, New Fire

Unity 5 was announced during GDC. All of its features are free for educational/development uses. So Swapnil decided we convert the project to Unity 5. It was a smooth conversion. We ran into small bugs like the ground texture was sparkling. Unity 5 was much more smooth. We noticed an increased FPS. Also, the game looked a lot more pretty as Unity 5 now is equipped with RTGI – Real Time Global Illumination.
The game came with a much nicer looking fire prefab. We decided to replace our old fire with the new slick looking fire. I was in-charge. I tweaked the fire to make it scale to the appropriate levels. The final fire looked like this –

fireNew

All is Dust – GDC Week

We went to San Francisco for GDC 2015. This time we had the summits pass. I attended conferences on AI, graphics, Math, game design and audio. The summits were informative. The AI rant was fun.
We showed our game at the University booth. Each had chosen a time slot to be at the booth. We recived valuable feedback of our game. One of the most important feedback was that the player gets disoriented in the game. So as soon as we got back we decided to implement a map.

All is Dust – GDC

The week before GDC:

At this point of time, our goal was to remove bugs. I helped the Swapnil – our lead engineer to fix some last minute bugs. The car-scene sound was broken, the end-scene mechanic was broken. I spoke with the engineers who worked on it and fixed it. The fixes were not too hard, they were initialization and logic issue bugs.

All is Dust – More debug Menu..teleporting

A lot of time was spent walking from one place to another during testing the game. So I made a tool where you could teleport to a given point. I spoke with the team to find the most important points in the game or where they would want to jump to in the map.

I came up with the following points.

Debug Tool

The mystery point is just a troll I made where the player drops from the sky and the song ‘Free falling’ starts to play. This tool was used a lot and I am sure it must have saved a lot of time playtesting.