Skip to content
This repository was archived by the owner on Dec 4, 2025. It is now read-only.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

11 Commits

Repository files navigation

WebGL First Person Render

Overview

A first person movement demonstration using WebGL 3D rendering.

External Libraries and Tools Used

Three.JS - a JavaScript library and API for 3D Graphics.

Keeny.nl - online asset market place for game models.

MTLLoader.JS - MTL Resource loader by angelxuanchang.

OBJLoader.JS - OBJ Resource loader by mrdoob.

Credit is given where due for these tools.

Techniques

Locking The Camera

Moving forwards ('w' key is being pressed):

XcameraPosition = XcameraPosition - sin(YcameraRotation) - VmouseVelocity

ZcameraPosition = ZcameraPosition - (-cos(YcameraRotation)) - VmouseVelocity

Moving backwards ('s' key is being pressed):

XcameraPosition = XcameraPosition + sin(YcameraRotation) - VmouseVelocity

ZcameraPosition = ZcameraPosition - (-cos(YcameraRotation)) - VmouseVelocity

Strafing left ('a' key is being pressed):

XcameraPosition = XcameraPosition + sin(YcameraRotation + 蟺 / 2) - VmouseVelocity

ZcameraPosition = ZcameraPosition - (-cos(YcameraRotation + 蟺 / 2)) - VmouseVelocity

Strafing right ('d' key is being pressed):

XcameraPosition = XcameraPosition + sin(YcameraRotation - 蟺 / 2) - VmouseVelocity

ZcameraPosition = ZcameraPosition - (-cos(YcameraRotation - 蟺 / 2)) - VmouseVelocity

Turning camera right ('right arrow ->' key is being pressed):

YcameraRotation = YcameraRotation + VmouseVelocity

Turning camera left ('left arrow <-' key is being pressed):

YcameraRotation = YcameraRotation - VmouseVelocity

First Person Model Tracking

Positioning:

XcameraPosition = XcameraPosition - sin(YcameraRotation + 蟺 / 6) * C

YcameraPosition = YcameraPosition - C + sin(XcameraPosition + ZcameraPosition) * C

ZcameraPosition = ZcameraPosition - cos(YcameraRotation + 蟺 / 6) * C

Rotation:

XcameraRotation = XcameraRotation

YcameraRotation = YcameraRotation - 蟺 (ensures that the model faces the right way.)

ZcameraRotation = ZcameraRotation

Projectile Calculations

VprojectileVelocityX = sin(YcameraRotation)

VprojectileVelocityY = 0

VprojectileVelocityZ = cos(YcameraRotation)

Controls

Key Movement
W Walk forward.
S Walk backward.
A Strafe left.
D Strafe right.
Space Bar Fire weapon.
Left Arrow Key Turn camera left.
Right Arrow Key Turn camera right.

Demo GIFs

First person demonstration

About

馃敨 3D FPS browser game.

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Contributors

Languages