├── ThirdPartyNotices.txt
├── GetStartedJS3D
├── images
│ ├── StoreLogo.png
│ ├── SplashScreen.scale-200.png
│ ├── LockScreenLogo.scale-200.png
│ ├── Square44x44Logo.scale-200.png
│ ├── Wide310x150Logo.scale-200.png
│ ├── Square150x150Logo.scale-200.png
│ └── Square44x44Logo.targetsize-24_altform-unplated.png
├── js
│ ├── controls
│ │ └── PointerLockControls.js
│ └── main.js
├── package.appxmanifest
├── index.html
├── css
│ └── stylesheet.css
└── GetStartedJS3D.jsproj
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── GetStartedJS3D.sln
├── SECURITY.md
└── .gitignore
/ThirdPartyNotices.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/Windows-appsample-get-started-js3d/HEAD/ThirdPartyNotices.txt
--------------------------------------------------------------------------------
/GetStartedJS3D/images/StoreLogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/Windows-appsample-get-started-js3d/HEAD/GetStartedJS3D/images/StoreLogo.png
--------------------------------------------------------------------------------
/GetStartedJS3D/images/SplashScreen.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/Windows-appsample-get-started-js3d/HEAD/GetStartedJS3D/images/SplashScreen.scale-200.png
--------------------------------------------------------------------------------
/GetStartedJS3D/images/LockScreenLogo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/Windows-appsample-get-started-js3d/HEAD/GetStartedJS3D/images/LockScreenLogo.scale-200.png
--------------------------------------------------------------------------------
/GetStartedJS3D/images/Square44x44Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/Windows-appsample-get-started-js3d/HEAD/GetStartedJS3D/images/Square44x44Logo.scale-200.png
--------------------------------------------------------------------------------
/GetStartedJS3D/images/Wide310x150Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/Windows-appsample-get-started-js3d/HEAD/GetStartedJS3D/images/Wide310x150Logo.scale-200.png
--------------------------------------------------------------------------------
/GetStartedJS3D/images/Square150x150Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/Windows-appsample-get-started-js3d/HEAD/GetStartedJS3D/images/Square150x150Logo.scale-200.png
--------------------------------------------------------------------------------
/GetStartedJS3D/images/Square44x44Logo.targetsize-24_altform-unplated.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/Windows-appsample-get-started-js3d/HEAD/GetStartedJS3D/images/Square44x44Logo.targetsize-24_altform-unplated.png
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | We're not ready to accept contributions at this time, but if you have any feedback, please post to the Issues list. Thanks!
2 |
3 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
4 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2017 Microsoft
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | page_type: sample
3 | languages:
4 | - javascript
5 | products:
6 | - windows
7 | - windows-uwp
8 | statusNotificationTargets:
9 | - codefirst@microsoft.com
10 | description: "A UWP game for the Microsoft Store, written in JavaScript with three.js."
11 | ---
12 |
13 | # Get Started JavaScript 3D
14 |
15 | A UWP game for the Microsoft Store, written in JavaScript with three.js
16 |
17 | ## Requirements
18 | This app requires Visual Studio to run. [Click here to learn how to get set up with Visual Studio](https://docs.microsoft.com/windows/uwp/get-started/get-set-up).
19 |
20 | ## Install and run the app
21 |
22 | 1. Clone or download this repository
23 | 2. Open **GetStartedJS3D.sln** in Visual Studio.
24 | 3. To run the app, press **F5**.
25 |
26 | ## Learn more about MonoGame and UWP
27 | For a step-by-step walkthrough of the code, check out the [JavaScript 3D tutorial on docs.microsoft.com](https://docs.microsoft.com/windows/uwp/get-started/get-started-tutorial-game-js3d).
28 |
29 | To learn more about getting started with the Universal Windows Platform, see the [Getting Started Hub](https://developer.microsoft.com/windows/apps/getstarted)
30 |
31 | To learn how to publish apps to the Microsoft Store, see [Publishing your Microsoft Store app](https://developer.microsoft.com/store/publish-apps).
32 |
--------------------------------------------------------------------------------
/GetStartedJS3D/js/controls/PointerLockControls.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @author mrdoob / http://mrdoob.com/
3 | */
4 |
5 | THREE.PointerLockControls = function ( camera ) {
6 |
7 | var scope = this;
8 |
9 | camera.rotation.set( 0, 0, 0 );
10 |
11 | var pitchObject = new THREE.Object3D();
12 | pitchObject.add( camera );
13 |
14 | var yawObject = new THREE.Object3D();
15 | yawObject.position.y = 10;
16 | yawObject.add( pitchObject );
17 |
18 | var PI_2 = Math.PI / 2;
19 |
20 | var onMouseMove = function ( event ) {
21 |
22 | if ( scope.enabled === false ) return;
23 |
24 | var movementX = event.movementX || event.mozMovementX || event.webkitMovementX || 0;
25 | var movementY = event.movementY || event.mozMovementY || event.webkitMovementY || 0;
26 |
27 | yawObject.rotation.y -= movementX * 0.002;
28 | pitchObject.rotation.x -= movementY * 0.002;
29 |
30 | pitchObject.rotation.x = Math.max( - PI_2, Math.min( PI_2, pitchObject.rotation.x ) );
31 |
32 | };
33 |
34 | this.dispose = function() {
35 |
36 | document.removeEventListener( 'mousemove', onMouseMove, false );
37 |
38 | };
39 |
40 | document.addEventListener( 'mousemove', onMouseMove, false );
41 |
42 | this.enabled = false;
43 |
44 | this.getObject = function () {
45 |
46 | return yawObject;
47 |
48 | };
49 |
50 | this.getDirection = function() {
51 |
52 | // assumes the camera itself is not rotated
53 |
54 | var direction = new THREE.Vector3( 0, 0, - 1 );
55 | var rotation = new THREE.Euler( 0, 0, 0, "YXZ" );
56 |
57 | return function( v ) {
58 |
59 | rotation.set( pitchObject.rotation.x, yawObject.rotation.y, 0 );
60 |
61 | v.copy( direction ).applyEuler( rotation );
62 |
63 | return v;
64 |
65 | };
66 |
67 | }();
68 |
69 | };
--------------------------------------------------------------------------------
/GetStartedJS3D/package.appxmanifest:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
14 |
15 |
16 | GetStartedJS3D
17 | Microsoft Corporation
18 | images\storelogo.png
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
33 |
34 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/GetStartedJS3D/index.html:
--------------------------------------------------------------------------------
1 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 | Loading...
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/GetStartedJS3D/css/stylesheet.css:
--------------------------------------------------------------------------------
1 | /*
2 | // ---------------------------------------------------------------------------------
3 | // Copyright (c) Microsoft Corporation. All rights reserved.
4 | //
5 | // The MIT License (MIT)
6 | //
7 | // Permission is hereby granted, free of charge, to any person obtaining a copy
8 | // of this software and associated documentation files (the "Software"), to deal
9 | // in the Software without restriction, including without limitation the rights
10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | // copies of the Software, and to permit persons to whom the Software is
12 | // furnished to do so, subject to the following conditions:
13 | //
14 | // The above copyright notice and this permission notice shall be included in
15 | // all copies or substantial portions of the Software.
16 | //
17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | // THE SOFTWARE.
24 | // ---------------------------------------------------------------------------------
25 | */
26 |
27 | body {
28 | background-color: #000;
29 | color: #888;
30 | font-family: Helvetica;
31 | line-height: 26px;
32 | margin: 0px;
33 | overflow: hidden;
34 | }
35 |
36 |
37 | #container {
38 | box-sizing: border-box;
39 | height: 100%;
40 | left: 0;
41 | margin: 0;
42 | position: absolute;
43 | top: 0;
44 | width: 100%;
45 | }
46 |
47 | #blocker {
48 | position: absolute;
49 | width: 100%;
50 | height: 100%;
51 | background-color: rgba(0, 0, 0, 0.5);
52 | }
53 |
54 | #instructions {
55 | width: 100%;
56 | height: 100%;
57 | font-size: 30px;
58 | font-family: 'Courier New';
59 | display: -webkit-box;
60 | display: -moz-box;
61 | display: box;
62 | -webkit-box-orient: horizontal;
63 | -moz-box-orient: horizontal;
64 | -webkit-box-pack: center;
65 | -moz-box-pack: center;
66 | -webkit-box-align: center;
67 | -moz-box-align: center;
68 | color: #ffffff;
69 | text-align: center;
70 | cursor: pointer;
71 | }
72 | #dino-alert {
73 | position: absolute;
74 | color: #aa0909;
75 | width: 100%;
76 | height: 5%;
77 | text-align: center;
78 | padding-top:2%;
79 | vertical-align:middle;
80 |
81 | }
--------------------------------------------------------------------------------
/GetStartedJS3D.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{262852C6-CD72-467D-83FE-5EEB1973A190}") = "GetStartedJS3D", "GetStartedJS3D\GetStartedJS3D.jsproj", "{C92E4F58-43DC-44FC-BE1B-FB7512C142E1}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Debug|ARM = Debug|ARM
12 | Debug|x64 = Debug|x64
13 | Debug|x86 = Debug|x86
14 | Release|Any CPU = Release|Any CPU
15 | Release|ARM = Release|ARM
16 | Release|x64 = Release|x64
17 | Release|x86 = Release|x86
18 | EndGlobalSection
19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
20 | {C92E4F58-43DC-44FC-BE1B-FB7512C142E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {C92E4F58-43DC-44FC-BE1B-FB7512C142E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {C92E4F58-43DC-44FC-BE1B-FB7512C142E1}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
23 | {C92E4F58-43DC-44FC-BE1B-FB7512C142E1}.Debug|ARM.ActiveCfg = Debug|ARM
24 | {C92E4F58-43DC-44FC-BE1B-FB7512C142E1}.Debug|ARM.Build.0 = Debug|ARM
25 | {C92E4F58-43DC-44FC-BE1B-FB7512C142E1}.Debug|ARM.Deploy.0 = Debug|ARM
26 | {C92E4F58-43DC-44FC-BE1B-FB7512C142E1}.Debug|x64.ActiveCfg = Debug|x64
27 | {C92E4F58-43DC-44FC-BE1B-FB7512C142E1}.Debug|x64.Build.0 = Debug|x64
28 | {C92E4F58-43DC-44FC-BE1B-FB7512C142E1}.Debug|x64.Deploy.0 = Debug|x64
29 | {C92E4F58-43DC-44FC-BE1B-FB7512C142E1}.Debug|x86.ActiveCfg = Debug|x86
30 | {C92E4F58-43DC-44FC-BE1B-FB7512C142E1}.Debug|x86.Build.0 = Debug|x86
31 | {C92E4F58-43DC-44FC-BE1B-FB7512C142E1}.Debug|x86.Deploy.0 = Debug|x86
32 | {C92E4F58-43DC-44FC-BE1B-FB7512C142E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
33 | {C92E4F58-43DC-44FC-BE1B-FB7512C142E1}.Release|Any CPU.Build.0 = Release|Any CPU
34 | {C92E4F58-43DC-44FC-BE1B-FB7512C142E1}.Release|Any CPU.Deploy.0 = Release|Any CPU
35 | {C92E4F58-43DC-44FC-BE1B-FB7512C142E1}.Release|ARM.ActiveCfg = Release|ARM
36 | {C92E4F58-43DC-44FC-BE1B-FB7512C142E1}.Release|ARM.Build.0 = Release|ARM
37 | {C92E4F58-43DC-44FC-BE1B-FB7512C142E1}.Release|ARM.Deploy.0 = Release|ARM
38 | {C92E4F58-43DC-44FC-BE1B-FB7512C142E1}.Release|x64.ActiveCfg = Release|x64
39 | {C92E4F58-43DC-44FC-BE1B-FB7512C142E1}.Release|x64.Build.0 = Release|x64
40 | {C92E4F58-43DC-44FC-BE1B-FB7512C142E1}.Release|x64.Deploy.0 = Release|x64
41 | {C92E4F58-43DC-44FC-BE1B-FB7512C142E1}.Release|x86.ActiveCfg = Release|x86
42 | {C92E4F58-43DC-44FC-BE1B-FB7512C142E1}.Release|x86.Build.0 = Release|x86
43 | {C92E4F58-43DC-44FC-BE1B-FB7512C142E1}.Release|x86.Deploy.0 = Release|x86
44 | EndGlobalSection
45 | GlobalSection(SolutionProperties) = preSolution
46 | HideSolutionNode = FALSE
47 | EndGlobalSection
48 | EndGlobal
49 |
--------------------------------------------------------------------------------
/SECURITY.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | ## Security
4 |
5 | Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/).
6 |
7 | If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/opensource/security/definition), please report it to us as described below.
8 |
9 | ## Reporting Security Issues
10 |
11 | **Please do not report security vulnerabilities through public GitHub issues.**
12 |
13 | Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/opensource/security/create-report).
14 |
15 | If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/opensource/security/pgpkey).
16 |
17 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc).
18 |
19 | Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
20 |
21 | * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
22 | * Full paths of source file(s) related to the manifestation of the issue
23 | * The location of the affected source code (tag/branch/commit or direct URL)
24 | * Any special configuration required to reproduce the issue
25 | * Step-by-step instructions to reproduce the issue
26 | * Proof-of-concept or exploit code (if possible)
27 | * Impact of the issue, including how an attacker might exploit the issue
28 |
29 | This information will help us triage your report more quickly.
30 |
31 | If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/opensource/security/bounty) page for more details about our active programs.
32 |
33 | ## Preferred Languages
34 |
35 | We prefer all communications to be in English.
36 |
37 | ## Policy
38 |
39 | Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/opensource/security/cvd).
40 |
41 |
42 |
--------------------------------------------------------------------------------
/GetStartedJS3D/GetStartedJS3D.jsproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 |
8 |
9 | Debug
10 | ARM
11 |
12 |
13 | Debug
14 | x64
15 |
16 |
17 | Debug
18 | x86
19 |
20 |
21 | Release
22 | AnyCPU
23 |
24 |
25 | Release
26 | ARM
27 | true
28 |
29 |
30 | Release
31 | x64
32 | true
33 |
34 |
35 | Release
36 | x86
37 | true
38 |
39 |
40 |
41 | c92e4f58-43dc-44fc-be1b-fb7512c142e1
42 |
43 |
44 |
45 | 14.0
46 |
47 |
48 |
49 |
50 | UAP
51 | 10.0.14393.0
52 | 10.0.10586.0
53 | $(VersionNumberMajor).$(VersionNumberMinor)
54 | en-US
55 | GetStartedJS3D_TemporaryKey.pfx
56 |
57 |
58 |
59 | Designer
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
88 |
89 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | artifacts/
46 |
47 | *_i.c
48 | *_p.c
49 | *_i.h
50 | *.ilk
51 | *.meta
52 | *.obj
53 | *.pch
54 | *.pdb
55 | *.pgc
56 | *.pgd
57 | *.rsp
58 | *.sbr
59 | *.tlb
60 | *.tli
61 | *.tlh
62 | *.tmp
63 | *.tmp_proj
64 | *.log
65 | *.vspscc
66 | *.vssscc
67 | .builds
68 | *.pidb
69 | *.svclog
70 | *.scc
71 |
72 | # Chutzpah Test files
73 | _Chutzpah*
74 |
75 | # Visual C++ cache files
76 | ipch/
77 | *.aps
78 | *.ncb
79 | *.opendb
80 | *.opensdf
81 | *.sdf
82 | *.cachefile
83 | *.VC.db
84 | *.VC.VC.opendb
85 |
86 | # Visual Studio profiler
87 | *.psess
88 | *.vsp
89 | *.vspx
90 | *.sap
91 |
92 | # TFS 2012 Local Workspace
93 | $tf/
94 |
95 | # Guidance Automation Toolkit
96 | *.gpState
97 |
98 | # ReSharper is a .NET coding add-in
99 | _ReSharper*/
100 | *.[Rr]e[Ss]harper
101 | *.DotSettings.user
102 |
103 | # JustCode is a .NET coding add-in
104 | .JustCode
105 |
106 | # TeamCity is a build add-in
107 | _TeamCity*
108 |
109 | # DotCover is a Code Coverage Tool
110 | *.dotCover
111 |
112 | # NCrunch
113 | _NCrunch_*
114 | .*crunch*.local.xml
115 | nCrunchTemp_*
116 |
117 | # MightyMoose
118 | *.mm.*
119 | AutoTest.Net/
120 |
121 | # Web workbench (sass)
122 | .sass-cache/
123 |
124 | # Installshield output folder
125 | [Ee]xpress/
126 |
127 | # DocProject is a documentation generator add-in
128 | DocProject/buildhelp/
129 | DocProject/Help/*.HxT
130 | DocProject/Help/*.HxC
131 | DocProject/Help/*.hhc
132 | DocProject/Help/*.hhk
133 | DocProject/Help/*.hhp
134 | DocProject/Help/Html2
135 | DocProject/Help/html
136 |
137 | # Click-Once directory
138 | publish/
139 |
140 | # Publish Web Output
141 | *.[Pp]ublish.xml
142 | *.azurePubxml
143 | # TODO: Comment the next line if you want to checkin your web deploy settings
144 | # but database connection strings (with potential passwords) will be unencrypted
145 | *.pubxml
146 | *.publishproj
147 |
148 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
149 | # checkin your Azure Web App publish settings, but sensitive information contained
150 | # in these scripts will be unencrypted
151 | PublishScripts/
152 |
153 | # NuGet Packages
154 | *.nupkg
155 | # The packages folder can be ignored because of Package Restore
156 | **/packages/*
157 | # except build/, which is used as an MSBuild target.
158 | !**/packages/build/
159 | # Uncomment if necessary however generally it will be regenerated when needed
160 | #!**/packages/repositories.config
161 | # NuGet v3's project.json files produces more ignoreable files
162 | *.nuget.props
163 | *.nuget.targets
164 |
165 | # Microsoft Azure Build Output
166 | csx/
167 | *.build.csdef
168 |
169 | # Microsoft Azure Emulator
170 | ecf/
171 | rcf/
172 |
173 | # Microsoft Store app package directories and files
174 | AppPackages/
175 | BundleArtifacts/
176 | Package.StoreAssociation.xml
177 | _pkginfo.txt
178 |
179 | # Visual Studio cache files
180 | # files ending in .cache can be ignored
181 | *.[Cc]ache
182 | # but keep track of directories ending in .cache
183 | !*.[Cc]ache/
184 |
185 | # Others
186 | ClientBin/
187 | ~$*
188 | *~
189 | *.dbmdl
190 | *.dbproj.schemaview
191 | *.pfx
192 | *.publishsettings
193 | node_modules/
194 | orleans.codegen.cs
195 |
196 | # Since there are multiple workflows, uncomment next line to ignore bower_components
197 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
198 | #bower_components/
199 |
200 | # RIA/Silverlight projects
201 | Generated_Code/
202 |
203 | # Backup & report files from converting an old project file
204 | # to a newer Visual Studio version. Backup files are not needed,
205 | # because we have git ;-)
206 | _UpgradeReport_Files/
207 | Backup*/
208 | UpgradeLog*.XML
209 | UpgradeLog*.htm
210 |
211 | # SQL Server files
212 | *.mdf
213 | *.ldf
214 |
215 | # Business Intelligence projects
216 | *.rdl.data
217 | *.bim.layout
218 | *.bim_*.settings
219 |
220 | # Microsoft Fakes
221 | FakesAssemblies/
222 |
223 | # GhostDoc plugin setting file
224 | *.GhostDoc.xml
225 |
226 | # Node.js Tools for Visual Studio
227 | .ntvs_analysis.dat
228 |
229 | # Visual Studio 6 build log
230 | *.plg
231 |
232 | # Visual Studio 6 workspace options file
233 | *.opt
234 |
235 | # Visual Studio LightSwitch build output
236 | **/*.HTMLClient/GeneratedArtifacts
237 | **/*.DesktopClient/GeneratedArtifacts
238 | **/*.DesktopClient/ModelManifest.xml
239 | **/*.Server/GeneratedArtifacts
240 | **/*.Server/ModelManifest.xml
241 | _Pvt_Extensions
242 |
243 | # Paket dependency manager
244 | .paket/paket.exe
245 | paket-files/
246 |
247 | # FAKE - F# Make
248 | .fake/
249 |
250 | # JetBrains Rider
251 | .idea/
252 | *.sln.iml
253 |
--------------------------------------------------------------------------------
/GetStartedJS3D/js/main.js:
--------------------------------------------------------------------------------
1 | // ---------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | //
4 | // The MIT License (MIT)
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 | // ---------------------------------------------------------------------------------
24 |
25 | var UNITWIDTH = 90; // Width of a cubes in the maze
26 | var UNITHEIGHT = 45; // Height of the cubes in the maze
27 | var CATCHOFFSET = 120; // Distance from the player the dino to trigger game over
28 | var DINOCOLLISIONDISTANCE = 55; // How many units away a dino can get to a wall
29 | var PLAYERCOLLISIONDISTANCE = 20; // How many units away the player can get from the wall
30 | var PLAYERSPEED = 800.0; // How fast the player moves
31 | var DINOSPEED = 400.0; // How fast the dino moves
32 | var DINOSCALE = 20; // How big our dino is scaled to
33 |
34 |
35 | var clock;
36 | var dino;
37 | var loader = new THREE.JSONLoader();
38 | var camera, controls, scene, renderer;
39 | var mapSize;
40 |
41 | var collidableObjects = [];
42 |
43 | var totalCubesWide;
44 |
45 |
46 | // Flags to determine which direction the player is moving
47 | var moveForward = false;
48 | var moveBackward = false;
49 | var moveLeft = false;
50 | var moveRight = false;
51 |
52 | // Flag to determine if the player lost the game
53 | var gameOver = false;
54 |
55 | // Velocity vectors for the player and dino
56 | var playerVelocity = new THREE.Vector3();
57 | var dinoVelocity = new THREE.Vector3();
58 |
59 |
60 | // HTML elements to be changed
61 | var blocker = document.getElementById('blocker');
62 | var instructions = document.getElementById('instructions');
63 | var dinoAlert = document.getElementById('dino-alert');
64 | dinoAlert.style.display = 'none';
65 |
66 | var container = document.getElementById('container');
67 | var body = document.getElementById('body');
68 | var blocker = document.getElementById('blocker');
69 |
70 |
71 | // Get the pointer lock and start listening for if its state changes
72 | function getPointerLock() {
73 | document.onclick = function () {
74 | container.requestPointerLock();
75 | }
76 |
77 | document.addEventListener('pointerlockchange', lockChange, false);
78 | }
79 |
80 | // Switch the controls on or off
81 | function lockChange() {
82 | // Turn on controls
83 | if (document.pointerLockElement === container) {
84 | blocker.style.display = "none";
85 | controls.enabled = true;
86 | // Turn off the controls
87 | } else {
88 | if (gameOver) {
89 | location.reload();
90 | }
91 | // Display the blocker and instruction
92 | blocker.style.display = "";
93 | controls.enabled = false;
94 | }
95 | }
96 |
97 |
98 | // Set up the game
99 | getPointerLock();
100 | init();
101 |
102 |
103 |
104 | // Set up the game
105 | function init() {
106 |
107 | // Set clock to keep track of frames
108 | clock = new THREE.Clock();
109 | // Create the scene where everything will go
110 | scene = new THREE.Scene();
111 |
112 | // Add some fog for effects
113 | scene.fog = new THREE.FogExp2(0xcccccc, 0.0015);
114 |
115 | // Set render settings
116 | renderer = new THREE.WebGLRenderer();
117 | renderer.setClearColor(scene.fog.color);
118 | renderer.setPixelRatio(window.devicePixelRatio);
119 | renderer.setSize(window.innerWidth, window.innerHeight);
120 |
121 | // Render to the container
122 | var container = document.getElementById('container');
123 | container.appendChild(renderer.domElement);
124 |
125 | // Set camera position and view details
126 | camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 1, 2000);
127 | camera.position.y = 20; // Height the camera will be looking from
128 | camera.position.x = 0;
129 | camera.position.z = 0;
130 |
131 | // Add the camera to the controller, then add to the scene
132 | controls = new THREE.PointerLockControls(camera);
133 | scene.add(controls.getObject());
134 |
135 | listenForPlayerMovement();
136 |
137 |
138 | // Add the walls(cubes) of the maze
139 | createMazeCubes();
140 | // Add ground plane
141 | createGround();
142 | // Add perimeter walls that surround the maze
143 | createPerimWalls();
144 |
145 |
146 | // load the dino JSON model and start animating once complete
147 | loader.load('./models/dino.json', function (geometry, materials) {
148 |
149 |
150 | // Get the geometry and materials from the JSON
151 | var dinoObject = new THREE.Mesh(geometry, new THREE.MultiMaterial(materials));
152 |
153 | // Scale the size of the dino
154 | dinoObject.scale.set(DINOSCALE, DINOSCALE, DINOSCALE);
155 | dinoObject.rotation.y = degreesToRadians(90);
156 | dinoObject.position.set(30, 0, -400);
157 | dinoObject.name = "dino";
158 | scene.add(dinoObject);
159 |
160 | //position.setFromMatrixPosition(dino.matrixWorld);
161 | dino = scene.getObjectByName("dino");
162 |
163 | // Model is loaded, switch from "Loading..." to instruction text
164 | instructions.innerHTML = "Click to Play! W,A,S,D or arrow keys = move Mouse = look around";
165 |
166 | // Call the animate function so that animation begins after the model is loaded
167 | animate();
168 | });
169 |
170 | // Add lights to the scene
171 | addLights();
172 |
173 | // Listen for if the window changes sizes
174 | window.addEventListener('resize', onWindowResize, false);
175 |
176 | }
177 |
178 |
179 | // Add event listeners for player movement key presses
180 | function listenForPlayerMovement() {
181 | // Listen for when a key is pressed
182 | // If it's a specified key, mark the direction as true since moving
183 | var onKeyDown = function (event) {
184 |
185 | switch (event.keyCode) {
186 |
187 | case 38: // up
188 | case 87: // w
189 | moveForward = true;
190 | break;
191 |
192 | case 37: // left
193 | case 65: // a
194 | moveLeft = true;
195 | break;
196 |
197 | case 40: // down
198 | case 83: // s
199 | moveBackward = true;
200 | break;
201 |
202 | case 39: // right
203 | case 68: // d
204 | moveRight = true;
205 | break;
206 |
207 |
208 | }
209 |
210 | };
211 |
212 | // Listen for when a key is released
213 | // If it's a specified key, mark the direction as false since no longer moving
214 | var onKeyUp = function (event) {
215 |
216 | switch (event.keyCode) {
217 |
218 | case 38: // up
219 | case 87: // w
220 | moveForward = false;
221 | break;
222 |
223 | case 37: // left
224 | case 65: // a
225 | moveLeft = false;
226 | break;
227 |
228 | case 40: // down
229 | case 83: // s
230 | moveBackward = false;
231 | break;
232 |
233 | case 39: // right
234 | case 68: // d
235 | moveRight = false;
236 | break;
237 | }
238 | };
239 |
240 | // Add event listeners for when movement keys are pressed and released
241 | document.addEventListener('keydown', onKeyDown, false);
242 | document.addEventListener('keyup', onKeyUp, false);
243 | }
244 |
245 | // Add lights to the scene
246 | function addLights() {
247 | var lightOne = new THREE.DirectionalLight(0xffffff);
248 | lightOne.position.set(1, 1, 1);
249 | scene.add(lightOne);
250 |
251 | var lightTwo = new THREE.DirectionalLight(0xffffff, .4);
252 | lightTwo.position.set(1, -1, -1);
253 | scene.add(lightTwo);
254 | }
255 |
256 | // Create the maze walls using cubes that are mapped with a 2D array
257 | function createMazeCubes() {
258 | // Maze wall mapping, assuming matrix
259 | // 1's are cubes, 0's are empty space
260 | var map = [
261 | [0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0,],
262 | [0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0,],
263 | [0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0,],
264 | [0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0,],
265 | [0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,],
266 | [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,],
267 | [1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,],
268 | [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,],
269 | [0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,],
270 | [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,],
271 | [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1,],
272 | [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0,],
273 | [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1,],
274 | [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0,],
275 | [0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0,],
276 | [1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0,],
277 | [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,],
278 | [1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0,],
279 | [0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0,],
280 | [0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0,]
281 | ];
282 |
283 | // wall details
284 | var cubeGeo = new THREE.BoxGeometry(UNITWIDTH, UNITHEIGHT, UNITWIDTH);
285 | var cubeMat = new THREE.MeshPhongMaterial({
286 | color: 0x81cfe0,
287 | });
288 |
289 | // Keep cubes within boundry walls
290 | var widthOffset = UNITWIDTH / 2;
291 | // Put the bottom of the cube at y = 0
292 | var heightOffset = UNITHEIGHT / 2;
293 |
294 | // See how wide the map is by seeing how long the first array is
295 | totalCubesWide = map[0].length;
296 |
297 | // Place walls where 1`s are
298 | for (var i = 0; i < totalCubesWide; i++) {
299 | for (var j = 0; j < map[i].length; j++) {
300 | // If a 1 is found, add a cube at the corresponding position
301 | if (map[i][j]) {
302 | // Make the cube
303 | var cube = new THREE.Mesh(cubeGeo, cubeMat);
304 | // Set the cube position
305 | cube.position.z = (i - totalCubesWide / 2) * UNITWIDTH + widthOffset;
306 | cube.position.y = heightOffset;
307 | cube.position.x = (j - totalCubesWide / 2) * UNITWIDTH + widthOffset;
308 | // Add the cube
309 | scene.add(cube);
310 | // Used later for collision detection
311 | collidableObjects.push(cube);
312 | }
313 | }
314 | }
315 | // Create the ground based on the map size the matrix/cube size produced
316 | mapSize = totalCubesWide * UNITWIDTH;
317 | }
318 |
319 |
320 | // Create the ground plane that the maze sits on top of
321 | function createGround() {
322 | // Create the ground geometry and material
323 | var groundGeo = new THREE.PlaneGeometry(mapSize, mapSize);
324 | var groundMat = new THREE.MeshPhongMaterial({ color: 0xA0522D, side: THREE.DoubleSide, shading: THREE.FlatShading });
325 |
326 | // Create the ground and rotate it flat
327 | var ground = new THREE.Mesh(groundGeo, groundMat);
328 | ground.position.set(0, 1, 0);
329 | ground.rotation.x = degreesToRadians(90);
330 | scene.add(ground);
331 | }
332 |
333 |
334 | // Make the four perimeter walls for the maze
335 | function createPerimWalls() {
336 | var halfMap = mapSize / 2; // Half the size of the map
337 | var sign = 1; // Used to make an amount positive or negative
338 |
339 | // Loop through twice, making two perimeter walls at a time
340 | for (var i = 0; i < 2; i++) {
341 | var perimGeo = new THREE.PlaneGeometry(mapSize, UNITHEIGHT);
342 | // Make the material double sided
343 | var perimMat = new THREE.MeshPhongMaterial({ color: 0x464646, side: THREE.DoubleSide });
344 | // Make two walls
345 | var perimWallLR = new THREE.Mesh(perimGeo, perimMat);
346 | var perimWallFB = new THREE.Mesh(perimGeo, perimMat);
347 |
348 | // Create left/right walls
349 | perimWallLR.position.set(halfMap * sign, UNITHEIGHT / 2, 0);
350 | perimWallLR.rotation.y = degreesToRadians(90);
351 | scene.add(perimWallLR);
352 | collidableObjects.push(perimWallLR);
353 | // Create front/back walls
354 | perimWallFB.position.set(0, UNITHEIGHT / 2, halfMap * sign);
355 | scene.add(perimWallFB);
356 | collidableObjects.push(perimWallFB);
357 |
358 | collidableObjects.push(perimWallLR);
359 | collidableObjects.push(perimWallFB);
360 |
361 | sign = -1; // Swap to negative value
362 | }
363 | }
364 |
365 | // Update the camera and renderer when the window changes size
366 | function onWindowResize() {
367 |
368 | camera.aspect = window.innerWidth / window.innerHeight;
369 | camera.updateProjectionMatrix();
370 |
371 | renderer.setSize(window.innerWidth, window.innerHeight);
372 |
373 | }
374 |
375 |
376 |
377 |
378 |
379 | function animate() {
380 | render();
381 | requestAnimationFrame(animate);
382 |
383 | // Get the change in time between frames
384 | var delta = clock.getDelta();
385 | // Update our frames per second monitor
386 |
387 | // If the player is in dino's range, trigger the chase
388 | var isBeingChased = triggerChase();
389 | // If the player is too close, trigger the end of the game
390 | if (dino.position.distanceTo(controls.getObject().position) < CATCHOFFSET) {
391 | caught();
392 | // Player is at an undetected distance
393 | // Keep the dino moving and let the player keep moving too
394 | } else {
395 | animateDino(delta);
396 | animatePlayer(delta);
397 | }
398 | }
399 |
400 | // Render the scene
401 | function render() {
402 | renderer.render(scene, camera);
403 |
404 | }
405 |
406 |
407 | // Make the dino chase the player
408 | function triggerChase() {
409 | // Check if in dino agro range
410 | if (dino.position.distanceTo(controls.getObject().position) < 300) {
411 | // Adject the target's y value. We only care about x and z for movement.
412 | var lookTarget = new THREE.Vector3();
413 | lookTarget.copy(controls.getObject().position);
414 | lookTarget.y = dino.position.y;
415 |
416 | // Make dino face camera
417 | dino.lookAt(lookTarget);
418 |
419 | // Get distance between dino and camera with a 120 unit offset
420 | // Game over when dino is the value of CATCHOFFSET units away from camera
421 | var distanceFrom = Math.round(dino.position.distanceTo(controls.getObject().position)) - CATCHOFFSET;
422 | // Alert and display distance between camera and dino
423 | dinoAlert.innerHTML = "Dino has spotted you! Distance from you: " + distanceFrom;
424 | dinoAlert.style.display = '';
425 | return true;
426 | // Not in agro range, don't start distance countdown
427 | } else {
428 | dinoAlert.style.display = 'none';
429 | return false;
430 | }
431 | }
432 |
433 | // Dino has caught the player. Turn on end prompt.
434 | function caught() {
435 | blocker.style.display = '';
436 | instructions.innerHTML = "GAME OVER Press ESC to restart";
437 | gameOver = true;
438 | instructions.style.display = '';
439 | dinoAlert.style.display = 'none';
440 | }
441 |
442 |
443 |
444 | // Animate the player camera
445 | function animatePlayer(delta) {
446 | // Gradual slowdown
447 | playerVelocity.x -= playerVelocity.x * 10.0 * delta;
448 | playerVelocity.z -= playerVelocity.z * 10.0 * delta;
449 |
450 | // If no collision and a movement key is being pressed, apply movement velocity
451 | if (detectPlayerCollision() == false) {
452 | if (moveForward) {
453 | playerVelocity.z -= PLAYERSPEED * delta;
454 | }
455 | if (moveBackward) playerVelocity.z += PLAYERSPEED * delta;
456 | if (moveLeft) playerVelocity.x -= PLAYERSPEED * delta;
457 | if (moveRight) playerVelocity.x += PLAYERSPEED * delta;
458 |
459 | controls.getObject().translateX(playerVelocity.x * delta);
460 | controls.getObject().translateZ(playerVelocity.z * delta);
461 | } else {
462 | // Collision or no movement key being pressed. Stop movememnt
463 | playerVelocity.x = 0;
464 | playerVelocity.z = 0;
465 | }
466 | }
467 |
468 |
469 | // Determine if the player is colliding with a collidable object
470 | function detectPlayerCollision() {
471 | // The rotation matrix to apply to our direction vector
472 | // Undefined by default to indicate ray should coming from front
473 | var rotationMatrix;
474 | // Get direction of camera
475 | var cameraDirection = controls.getDirection(new THREE.Vector3(0, 0, 0)).clone();
476 |
477 | // Check which direction we're moving (not looking)
478 | // Flip matrix to that direction so that we can reposition the ray
479 | if (moveBackward) {
480 | rotationMatrix = new THREE.Matrix4();
481 | rotationMatrix.makeRotationY(degreesToRadians(180));
482 | }
483 | else if (moveLeft) {
484 | rotationMatrix = new THREE.Matrix4();
485 | rotationMatrix.makeRotationY(degreesToRadians(90));
486 | }
487 | else if (moveRight) {
488 | rotationMatrix = new THREE.Matrix4();
489 | rotationMatrix.makeRotationY(degreesToRadians(270));
490 | }
491 |
492 | // Player is moving forward, no rotation matrix needed
493 | if (rotationMatrix !== undefined) {
494 | cameraDirection.applyMatrix4(rotationMatrix);
495 | }
496 |
497 | // Apply ray to player camera
498 | var rayCaster = new THREE.Raycaster(controls.getObject().position, cameraDirection);
499 |
500 | // If our ray hit a collidable object, return true
501 | if (rayIntersect(rayCaster, PLAYERCOLLISIONDISTANCE)) {
502 | return true;
503 | } else {
504 | return false;
505 | }
506 | }
507 |
508 | // Apply movement to the dino, turning when collisions are made
509 | function animateDino(delta) {
510 | // Gradual slowdown
511 | dinoVelocity.x -= dinoVelocity.x * 10.0 * delta;
512 | dinoVelocity.z -= dinoVelocity.z * 10.0 * delta;
513 |
514 |
515 | // If no collision, apply movement velocity
516 | if (detectDinoCollision() == false) {
517 | dinoVelocity.z += DINOSPEED * delta;
518 | // Move the dino
519 | dino.translateZ(dinoVelocity.z * delta);
520 |
521 | } else {
522 | // Collision. Adjust direction
523 | var directionMultiples = [-1, 1, 2];
524 | var randomIndex = getRandomInt(0, 2);
525 | var randomDirection = degreesToRadians(90 * directionMultiples[randomIndex]);
526 |
527 | dinoVelocity.z += DINOSPEED * delta;
528 |
529 | // Add the new direction
530 | dino.rotation.y += randomDirection;
531 | }
532 | }
533 |
534 |
535 | // Determine whether ornot dino is colliding with a wall
536 | function detectDinoCollision() {
537 | // Get the rotation matrix from dino
538 | var matrix = new THREE.Matrix4();
539 | matrix.extractRotation(dino.matrix);
540 | // Create direction vector
541 | var directionFront = new THREE.Vector3(0, 0, 1);
542 |
543 | // Get the vectors coming from the front of the dino
544 | directionFront.applyMatrix4(matrix);
545 |
546 | // Create raycaster
547 | var rayCasterF = new THREE.Raycaster(dino.position, directionFront);
548 |
549 |
550 | // If we have a front collision, we have to adjust our direction so return true
551 | if (rayIntersect(rayCasterF, DINOCOLLISIONDISTANCE))
552 | return true;
553 | else
554 | return false;
555 |
556 | }
557 |
558 | // Takes a ray and sees if it's colliding with anything from the list of collidable objects
559 | // Returns true if certain distance away from object
560 | function rayIntersect(ray, distance) {
561 | var intersects = ray.intersectObjects(collidableObjects);
562 | for (var i = 0; i < intersects.length; i++) {
563 | if (intersects[i].distance < distance) {
564 | return true;
565 | }
566 | }
567 | return false;
568 | }
569 |
570 | // Generate a random integer within a range
571 | function getRandomInt(min, max) {
572 | min = Math.ceil(min);
573 | max = Math.floor(max);
574 | return Math.floor(Math.random() * (max - min)) + min;
575 | }
576 |
577 | // Converts degrees to radians
578 | function degreesToRadians(degrees) {
579 | return degrees * Math.PI / 180;
580 | }
581 |
582 | // Converts radians to degrees
583 | function radiansToDegrees(radians) {
584 | return radians * 180 / Math.PI;
585 | }
586 |
--------------------------------------------------------------------------------