├── .gitattributes ├── Editor └── ALPSControllerEditor.cs ├── LICENSE.txt ├── Package ├── ALPS.v.0.1.0.unitypackage └── alpsvr-wp.unitypackage ├── Plugins └── Android │ ├── ALPSAndroid.jar │ ├── AndroidManifest.xml │ ├── libalps_native_sensor.so │ └── src │ ├── java │ └── ALPSActivity.java │ └── jni │ ├── Android.mk │ ├── Application.mk │ └── alps_native_sensor.c ├── Prefabs ├── ALPSCamera.prefab └── ALPSLightCamera.prefab ├── README.md ├── Resources ├── ALPSSkin.guiskin ├── Materials │ └── ALPSDistortion.mat └── Textures │ ├── arcs.png │ ├── blue.jpg │ └── progress_point.png ├── Screenshots └── ALPSVR_Preview.JPG ├── Scripts ├── ALPSAndroid.cs ├── ALPSBarrelMesh.cs ├── ALPSCamera.cs ├── ALPSConfig.cs ├── ALPSController.cs ├── ALPSControllerLight.cs ├── ALPSCrosshairs.cs ├── ALPSDevice.cs ├── ALPSGUI.cs ├── ALPSGyro.cs ├── ALPSNavigation.cs ├── ALPSWP8.cs └── MagnetSensor.cs └── Shaders └── ALPSDistortion.shader /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /Editor/ALPSControllerEditor.cs: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | ALPSControllerEditor is a custom editor for ALPSController class 3 | 4 | Copyright (C) 2014 ALPS VR. 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | 19 | ************************************************************************/ 20 | 21 | using UnityEngine; 22 | using System.Collections; 23 | using UnityEditor; 24 | 25 | [System.Serializable] 26 | [CustomEditor(typeof(ALPSController))] 27 | public class ALPSControllerEditor : Editor { 28 | 29 | //===================================================================================================== 30 | // Attributes 31 | //===================================================================================================== 32 | 33 | /**Public**/ 34 | public ALPSConfig deviceConfig; 35 | public ALPSController controller; 36 | 37 | public Device Device{ 38 | get{ 39 | return deviceConfig.deviceName; 40 | } 41 | set{ 42 | if(deviceConfig.deviceName != value){ 43 | controller.SetDevice(value); 44 | OnEnable(); 45 | } 46 | } 47 | } 48 | 49 | public ScreenOption screenSize{ 50 | get{ 51 | return deviceConfig.fixedSize?ScreenOption.FixedSize:ScreenOption.FullScreen; 52 | } 53 | set{ 54 | deviceConfig.fixedSize = (value == ScreenOption.FixedSize)?true:false; 55 | } 56 | } 57 | 58 | //===================================================================================================== 59 | // Functions 60 | //===================================================================================================== 61 | 62 | public void OnEnable() 63 | { 64 | controller = (ALPSController)target; 65 | deviceConfig = (controller.deviceConfig == null)? ALPSDevice.GetConfig(Device.DEFAULT):controller.deviceConfig; 66 | controller.deviceConfig = deviceConfig; 67 | ALPSCamera.deviceConfig = deviceConfig; 68 | ALPSBarrelMesh.deviceConfig = deviceConfig; 69 | ALPSCrosshairs.deviceConfig = deviceConfig; 70 | screenSize = deviceConfig.GetScreenOption (); 71 | } 72 | 73 | public override void OnInspectorGUI(){ 74 | 75 | //Device 76 | Device = (Device)EditorGUILayout.EnumPopup("Device:",Device); 77 | 78 | //IPD 79 | deviceConfig.IPD = EditorGUILayout.FloatField (new GUIContent("IPD", "Inter Pupilary Distance in millimeter. This must match the distance between the user's eyes"),deviceConfig.IPD); 80 | //Stereo distance 81 | deviceConfig.ILD = EditorGUILayout.FloatField (new GUIContent("ILD","Inter Lens Distance in millimeter. This is the distance between both cameras and this should match the IPD. Can be tweaked to increase or decrease the stereo effect."),deviceConfig.ILD); 82 | 83 | //Field Of View 84 | deviceConfig.fieldOfView = EditorGUILayout.Slider ("Vertical FOV",deviceConfig.fieldOfView, 1, 180); 85 | 86 | //Screen size 87 | screenSize = (ScreenOption)EditorGUILayout.EnumPopup("Screen size:",screenSize); 88 | 89 | if (screenSize == ScreenOption.FixedSize) { 90 | deviceConfig.Width = EditorGUILayout.IntField (new GUIContent("\twidth", "Width of the viewport in millimeter"), deviceConfig.Width); 91 | deviceConfig.Height = EditorGUILayout.IntField (new GUIContent("\theight", "Height of the viewport in millimeter"), deviceConfig.Height); 92 | deviceConfig.fixedSize = true; 93 | } else { 94 | deviceConfig.fixedSize = false; 95 | } 96 | 97 | //Barrel distortion 98 | deviceConfig.enableBarrelDistortion = EditorGUILayout.Toggle ("Barrel distortion", deviceConfig.enableBarrelDistortion); 99 | if (deviceConfig.enableBarrelDistortion) { 100 | deviceConfig.k1 = EditorGUILayout.FloatField ("\tk1", deviceConfig.k1); 101 | deviceConfig.k2 = EditorGUILayout.FloatField ("\tk2", deviceConfig.k2); 102 | } 103 | 104 | //Chromatic correction 105 | deviceConfig.enableChromaticCorrection = EditorGUILayout.Toggle ("Chromatic correction",deviceConfig.enableChromaticCorrection); 106 | if (deviceConfig.enableChromaticCorrection) { 107 | deviceConfig.chromaticCorrection = EditorGUILayout.FloatField ("\tCorrection intensity", deviceConfig.chromaticCorrection); 108 | } 109 | 110 | controller.crosshairsEnabled = EditorGUILayout.Toggle("Crosshair", controller.crosshairsEnabled); 111 | 112 | if (GUI.changed) { 113 | controller.ClearDirty(); 114 | EditorUtility.SetDirty(target); 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /Package/ALPS.v.0.1.0.unitypackage: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Foxman13/ALPS-VR/204cab8d68aa6689381c6f061872b27fa255a728/Package/ALPS.v.0.1.0.unitypackage -------------------------------------------------------------------------------- /Package/alpsvr-wp.unitypackage: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Foxman13/ALPS-VR/204cab8d68aa6689381c6f061872b27fa255a728/Package/alpsvr-wp.unitypackage -------------------------------------------------------------------------------- /Plugins/Android/ALPSAndroid.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Foxman13/ALPS-VR/204cab8d68aa6689381c6f061872b27fa255a728/Plugins/Android/ALPSAndroid.jar -------------------------------------------------------------------------------- /Plugins/Android/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 11 | 15 | 16 | 21 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Plugins/Android/libalps_native_sensor.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Foxman13/ALPS-VR/204cab8d68aa6689381c6f061872b27fa255a728/Plugins/Android/libalps_native_sensor.so -------------------------------------------------------------------------------- /Plugins/Android/src/java/ALPSActivity.java: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | ALPSActivity is the ALPS Android plugin for Unity 3 | 4 | Copyright (C) 2014 ALPS VR. 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | 19 | ************************************************************************/ 20 | 21 | package com.alpsvr.android; 22 | 23 | import android.graphics.Point; 24 | import android.hardware.Sensor; 25 | import android.hardware.SensorEvent; 26 | import android.hardware.SensorEventListener; 27 | import android.hardware.SensorManager; 28 | import android.os.Build; 29 | import android.os.Bundle; 30 | import android.os.Handler; 31 | import android.os.Vibrator; 32 | import android.view.Display; 33 | import android.view.KeyEvent; 34 | import android.view.View; 35 | import com.unity3d.player.UnityPlayerActivity; 36 | 37 | public class ALPSActivity extends UnityPlayerActivity{ 38 | 39 | //===================================================================================================== 40 | // Attributes 41 | //===================================================================================================== 42 | 43 | private SensorManager mSensorManager; 44 | private SensorManager mSensorManager2; 45 | private Sensor mGameRotation; 46 | private Sensor mGyroscope; 47 | private static float[] orientation=new float[4]; 48 | private static float[] dtGyro=new float[4]; 49 | private Handler mHandler = new Handler(); 50 | private static Vibrator v; 51 | private static int width; 52 | private static int height; 53 | private long timestamp = 0; 54 | static float NS2S = (float) (1.0/1000000000.0); 55 | static float EPSILON = (float) 0.000000001; 56 | 57 | private final SensorEventListener gameRotationListener = new SensorEventListener() { 58 | public void onSensorChanged(SensorEvent event) { 59 | //orientation=multiplyQuat(event.values,dtGyro); 60 | orientation = event.values; 61 | } 62 | public void onAccuracyChanged(Sensor sensor, int accuracy) { 63 | } 64 | }; 65 | 66 | private final SensorEventListener gyroscopeListener = new SensorEventListener() { 67 | public void onSensorChanged(SensorEvent event) { 68 | integrateGyro(event); 69 | } 70 | public void onAccuracyChanged(Sensor sensor, int accuracy) { 71 | } 72 | }; 73 | 74 | private Runnable resetImmersive = new Runnable(){ 75 | 76 | public void run() { 77 | getWindow().getDecorView().setSystemUiVisibility( 78 | View.SYSTEM_UI_FLAG_FULLSCREEN 79 | | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION 80 | | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY 81 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 82 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 83 | | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); 84 | 85 | } 86 | 87 | }; 88 | 89 | //===================================================================================================== 90 | // Functions 91 | //===================================================================================================== 92 | 93 | /** 94 | * Called when the activity is starting. 95 | */ 96 | protected void onCreate(Bundle bundle) { 97 | super.onCreate(bundle); 98 | mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); 99 | mSensorManager2 = (SensorManager) getSystemService(SENSOR_SERVICE); 100 | mGameRotation = mSensorManager.getDefaultSensor(Sensor.TYPE_GAME_ROTATION_VECTOR); 101 | mGyroscope = mSensorManager2.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); 102 | v = (Vibrator) getSystemService(VIBRATOR_SERVICE); 103 | 104 | Display display = getWindowManager().getDefaultDisplay(); 105 | Point size = new Point(); 106 | display.getRealSize(size); 107 | width = size.x; 108 | height = size.y; 109 | } 110 | 111 | /** 112 | * Called after onRestoreInstanceState(Bundle), onRestart(), or onPause(), for your activity to start interacting with the user. 113 | */ 114 | protected void onResume(){ 115 | super.onResume(); 116 | mSensorManager.registerListener(gameRotationListener, mGameRotation, SensorManager.SENSOR_DELAY_FASTEST); 117 | mSensorManager2.registerListener(gyroscopeListener, mGyroscope, SensorManager.SENSOR_DELAY_FASTEST); 118 | 119 | if (Build.VERSION.SDK_INT >= 19) { 120 | int flags = View.SYSTEM_UI_FLAG_FULLSCREEN 121 | | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION 122 | | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY 123 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 124 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 125 | | View.SYSTEM_UI_FLAG_LAYOUT_STABLE; 126 | 127 | this.findViewById(android.R.id.content).setSystemUiVisibility(flags); 128 | } 129 | 130 | } 131 | 132 | /** 133 | * Called as part of the activity lifecycle when an activity is going into the background, but has not (yet) been killed. 134 | */ 135 | protected void onPause() { 136 | super.onPause(); 137 | mSensorManager.unregisterListener(gameRotationListener); 138 | mSensorManager2.unregisterListener(gyroscopeListener); 139 | } 140 | 141 | /** 142 | * Called when a key down event has occurred. 143 | */ 144 | public boolean onKeyDown(int keyCode, KeyEvent event){ 145 | if (Build.VERSION.SDK_INT >= 19){ 146 | if (keyCode == KeyEvent.KEYCODE_BACK){ 147 | finish(); 148 | } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP) { 149 | mHandler.postDelayed(resetImmersive, 500); 150 | } 151 | } 152 | return super.onKeyDown(keyCode, event); 153 | } 154 | 155 | /** 156 | * The x component of rotation quaternion. 157 | * @return The x component of rotation quaternion. 158 | */ 159 | public static float getGameRotationX(){ 160 | return (orientation==null?0:orientation[0]); 161 | } 162 | 163 | /** 164 | * The y component of rotation quaternion. 165 | * @return The y component of rotation quaternion. 166 | */ 167 | public static float getGameRotationY(){ 168 | return (orientation==null?0:orientation[1]); 169 | } 170 | 171 | /** 172 | * The z component of rotation quaternion. 173 | * @return The z component of rotation quaternion. 174 | */ 175 | public static float getGameRotationZ(){ 176 | return (orientation==null?0:orientation[2]); 177 | } 178 | 179 | /** 180 | * The w component of rotation quaternion. 181 | * @return The w component of rotation quaternion. 182 | */ 183 | public static float getGameRotationW(){ 184 | return (orientation==null?0:orientation[3]); 185 | } 186 | 187 | /** 188 | * Vibrates constantly for the specified period of time. 189 | * @param _ms The number of milliseconds to vibrate. 190 | */ 191 | public static void vibrate(int _ms){ 192 | if(v != null) v.vibrate(_ms); 193 | } 194 | 195 | /** 196 | * The display width in pixels. 197 | * @return The display width in pixels. 198 | */ 199 | public static int getWidthPixel(){ 200 | return width; 201 | } 202 | 203 | /** 204 | * The display height in pixels. 205 | * @return The display height in pixels. 206 | */ 207 | public static int getHeightPixel(){ 208 | return height; 209 | } 210 | 211 | /** 212 | * Integrates gyroscope output over time. 213 | * @param event The gyroscope event 214 | */ 215 | //This is the method to integrate gyroscope output over time provided by the Android documentation 216 | //See : http://developer.android.com/guide/topics/sensors/sensors_motion.html#sensors-motion-gyro 217 | private void integrateGyro(SensorEvent event){ 218 | // This timestep's delta rotation to be multiplied by the current rotation 219 | // after computing it from the gyro sample data. 220 | if (timestamp != 0) { 221 | final float dT = (event.timestamp - timestamp) * NS2S; 222 | // Axis of the rotation sample, not normalized yet. 223 | float axisX = event.values[0]; 224 | float axisY = event.values[1]; 225 | float axisZ = event.values[2]; 226 | 227 | // Calculate the angular speed of the sample 228 | float omegaMagnitude = (float) Math.sqrt(axisX*axisX + axisY*axisY + axisZ*axisZ); 229 | 230 | // Normalize the rotation vector if it's big enough to get the axis 231 | // (that is, EPSILON should represent your maximum allowable margin of error) 232 | if (omegaMagnitude > EPSILON) { 233 | axisX /= omegaMagnitude; 234 | axisY /= omegaMagnitude; 235 | axisZ /= omegaMagnitude; 236 | } 237 | 238 | // Integrate around this axis with the angular speed by the timestep 239 | // in order to get a delta rotation from this sample over the timestep 240 | // We will convert this axis-angle representation of the delta rotation 241 | // into a quaternion before turning it into the rotation matrix. 242 | float thetaOverTwo = omegaMagnitude * dT / 2.0f; 243 | float sinThetaOverTwo = (float) Math.sin(thetaOverTwo); 244 | float cosThetaOverTwo = (float) Math.cos(thetaOverTwo); 245 | dtGyro[0] = sinThetaOverTwo * axisX; 246 | dtGyro[1] = sinThetaOverTwo * axisY; 247 | dtGyro[2] = sinThetaOverTwo * axisZ; 248 | dtGyro[3] = cosThetaOverTwo; 249 | 250 | //This is a hack to accelerate rotation when user moves the head. 251 | dtGyro=multiplyQuat(dtGyro,dtGyro); 252 | dtGyro=multiplyQuat(dtGyro,dtGyro); 253 | dtGyro=multiplyQuat(dtGyro,dtGyro); 254 | 255 | } 256 | timestamp = event.timestamp; 257 | } 258 | 259 | /** 260 | * Multiplies two quaternions 261 | * @param q1 First quaternion 262 | * @param q2 Second quaternion 263 | * @return Result of q1 * q2 264 | */ 265 | protected float[] multiplyQuat(float[] q1, float[] q2){ 266 | float nx = (q1[3])*(q2[0]) + (q1[0])*(q2[3]) + (q1[1])*(q2[2]) - (q1[2])*(q2[1]); 267 | float ny = (q1[3]*q2[1] - q1[0]*q2[2] + q1[1]*q2[3] + q1[2]*q2[0]); 268 | float nz = (q1[3]*q2[2] + q1[0]*q2[1] - q1[1]*q2[0] + q1[2]*q2[3]); 269 | float nw = (q1[3]*q2[3] - q1[0]*q2[0] - q1[1]*q2[1] - q1[2]*q2[2]); 270 | float[] q = {nx,ny,nz,nw}; 271 | return q; 272 | } 273 | 274 | } -------------------------------------------------------------------------------- /Plugins/Android/src/jni/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2010 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | include $(CLEAR_VARS) 18 | 19 | LOCAL_MODULE := alps_native_sensor 20 | LOCAL_SRC_FILES := alps_native_sensor.c 21 | LOCAL_LDLIBS := -llog -landroid 22 | LOCAL_STATIC_LIBRARIES := android_native_app_glue 23 | 24 | include $(BUILD_SHARED_LIBRARY) 25 | 26 | $(call import-module,android/native_app_glue) -------------------------------------------------------------------------------- /Plugins/Android/src/jni/Application.mk: -------------------------------------------------------------------------------- 1 | APP_ABI := all 2 | APP_PLATFORM := android-10 3 | -------------------------------------------------------------------------------- /Plugins/Android/src/jni/alps_native_sensor.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * The IMU algorithms used for sensor fusion has been developed by Sebastian Madgwick 17 | * and is available under the GNU GLP license at http://www.x-io.co.uk/open-source-imu-and-ahrs-algorithms/ 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "native_activity", __VA_ARGS__)) 30 | #define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "native_activity", __VA_ARGS__)) 31 | #define ASENSOR_TYPE_ROTATION_VECTOR 11 32 | #define sampleFreq 128.0f // sample frequency in Hz 33 | #define twoKpDef (2.0f * 0.5f) // 2 * proportional gain 34 | #define twoKiDef (2.0f * 0.0f) // 2 * integral gain 35 | #define betaDef 0.1f // 2 * proportional gain 36 | 37 | typedef struct Quaternion{ 38 | float x; 39 | float y; 40 | float z; 41 | float w; 42 | }Quaternion; 43 | 44 | void MahonyAHRSupdateIMU(float gx, float gy, float gz, float ax, float ay, float az,int64_t ev_timestamp); 45 | float invSqrt(float x); 46 | void multiplyQuat(Quaternion* q1, Quaternion* q2); 47 | 48 | //===================================================================================================== 49 | // Attributes 50 | //===================================================================================================== 51 | volatile float beta = betaDef; 52 | volatile float twoKp = twoKpDef; // 2 * proportional gain (Kp) 53 | volatile float twoKi = twoKiDef; // 2 * integral gain (Ki) 54 | volatile float q0 = 1.0f, q1 = 0.0f, q2 = 0.0f, q3 = 0.0f; // quaternion of sensor frame relative to auxiliary frame 55 | volatile float integralFBx = 0.0f, integralFBy = 0.0f, integralFBz = 0.0f; // integral error terms scaled by Ki 56 | static float acc_x=555,acc_y=555,acc_z=555; 57 | static float gyr_x=999,gyr_y=999,gyr_z=999; 58 | static int64_t time_stamp=-1; 59 | static int64_t gyro_time_stamp=-1; 60 | static ASensorEventQueue* sensorEventQueueGyro; 61 | static ASensorEventQueue* sensorEventQueueAcc; 62 | static float N2S = 1.0/1000000000.0; 63 | static float EPSILON = 0.000000001; 64 | static Quaternion deltaGyroQuaternion={0,0,0,0}; 65 | static Quaternion q={0,0,0,1}; 66 | 67 | //===================================================================================================== 68 | // Functions 69 | //===================================================================================================== 70 | /* Getter function used Unity. 71 | * Returns references to the orientation quaternion values. 72 | */ 73 | void get_q(float* _x, float* _y, float* _z, float* _w){ 74 | q.x = q1; 75 | q.y = q2; 76 | q.z = q3; 77 | q.w = q0; 78 | multiplyQuat(&q,&deltaGyroQuaternion); 79 | *_x = q.x; 80 | *_y = q.y; 81 | *_z = q.z; 82 | *_w = q.w; 83 | } 84 | 85 | /* Intergrates raw gyroscope data over time. 86 | * Returns a quaternion corresponding to the device orientation. 87 | */ 88 | void getQuaternionFromGyro(float ev_x,float ev_y,float ev_z,int64_t ev_timestamp){ 89 | if(gyro_time_stamp != -1){ 90 | float dT = (ev_timestamp - gyro_time_stamp) * N2S; 91 | //Calculate the angular speed of the sample 92 | float omegaMagnitude = sqrt(ev_x*ev_x + ev_y*ev_y + ev_z*ev_z); 93 | 94 | //Normalize the rotation vector 95 | if(omegaMagnitude > EPSILON){ 96 | ev_x /= omegaMagnitude; 97 | ev_y /= omegaMagnitude; 98 | ev_z /= omegaMagnitude; 99 | } 100 | 101 | 102 | float thetaOverTwo = omegaMagnitude * dT / 2.0f; 103 | float sinThetaOverTwo = sin(thetaOverTwo); 104 | float cosThetaOverTwo = cos(thetaOverTwo); 105 | deltaGyroQuaternion.x = sinThetaOverTwo * ev_x; 106 | deltaGyroQuaternion.y = sinThetaOverTwo * ev_y; 107 | deltaGyroQuaternion.z = sinThetaOverTwo * ev_z; 108 | deltaGyroQuaternion.w = cosThetaOverTwo; 109 | 110 | multiplyQuat(&deltaGyroQuaternion,&deltaGyroQuaternion); 111 | multiplyQuat(&deltaGyroQuaternion,&deltaGyroQuaternion); 112 | multiplyQuat(&deltaGyroQuaternion,&deltaGyroQuaternion); 113 | } 114 | gyro_time_stamp = ev_timestamp; 115 | 116 | } 117 | 118 | /* Loop function to process gyroscope data 119 | */ 120 | int get_sensor_events_gyro(int fd, int events, void* data) { 121 | ASensorEvent event; 122 | 123 | while (ASensorEventQueue_getEvents(sensorEventQueueGyro, &event, 1) > 0) { 124 | if(event.type==ASENSOR_TYPE_GYROSCOPE){ 125 | gyr_x = event.vector.x; 126 | gyr_y = event.vector.y; 127 | gyr_z = event.vector.z; 128 | 129 | getQuaternionFromGyro(gyr_x,gyr_y,gyr_z,event.timestamp); 130 | } 131 | } 132 | //should return 1 to continue receiving callbacks, or 0 to unregister 133 | return 1; 134 | } 135 | 136 | /* Loop function to process accelerometer data 137 | */ 138 | int get_sensor_events_acc(int fd, int events, void* data) { 139 | ASensorEvent event; 140 | 141 | while (ASensorEventQueue_getEvents(sensorEventQueueAcc, &event, 1) > 0) { 142 | if(event.type==ASENSOR_TYPE_ACCELEROMETER) { 143 | acc_x = event.acceleration.x; 144 | acc_y = event.acceleration.y; 145 | acc_z = event.acceleration.z; 146 | MahonyAHRSupdateIMU(gyr_x,gyr_y,gyr_z,acc_x,acc_y,acc_z,event.timestamp); 147 | //MadgwickAHRSupdateIMU(gyr_x,gyr_y,gyr_z,acc_x,acc_y,acc_z,event.timestamp); 148 | } 149 | } 150 | //should return 1 to continue receiving callbacks, or 0 to unregister 151 | return 1; 152 | } 153 | 154 | /* Main function 155 | */ 156 | void android_main(struct android_app* state) { 157 | app_dummy(); 158 | AAssetManager* assetManager = state->activity->assetManager; 159 | AConfiguration* config; 160 | AConfiguration_fromAssetManager(config,assetManager); 161 | AConfiguration_setNavHidden(config,ACONFIGURATION_NAVHIDDEN_YES); 162 | AConfiguration_setNavigation(config,ACONFIGURATION_NAVIGATION_NONAV ); 163 | } 164 | 165 | /* Initialization function. 166 | * Creates the sensor managers, loops and event queues. 167 | */ 168 | void init(){ 169 | app_dummy(); 170 | 171 | void* sensor_data_gyro; 172 | void* sensor_data_acc; 173 | //Create a Looper for this thread 174 | ALooper* looper_gyro = ALooper_forThread(); 175 | if(looper_gyro == NULL){ 176 | looper_gyro = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS); 177 | } 178 | 179 | ALooper* looper_acc = ALooper_forThread(); 180 | if(looper_acc == NULL){ 181 | looper_acc = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS); 182 | } 183 | 184 | //Get an instance of SensorManager 185 | ASensorManager* sensorManagerGyro = ASensorManager_getInstance(); 186 | ASensorManager* sensorManagerAcc = ASensorManager_getInstance(); 187 | 188 | ASensor const* accelerometerSensor = ASensorManager_getDefaultSensor(sensorManagerGyro, ASENSOR_TYPE_ACCELEROMETER); 189 | ASensor const* gyroscopeSensor = ASensorManager_getDefaultSensor(sensorManagerAcc, ASENSOR_TYPE_GYROSCOPE); 190 | 191 | //Create a sensor event queue 192 | sensorEventQueueGyro = ASensorManager_createEventQueue(sensorManagerGyro, looper_gyro, 3, get_sensor_events_gyro, sensor_data_gyro); 193 | sensorEventQueueAcc = ASensorManager_createEventQueue(sensorManagerAcc, looper_acc, 3, get_sensor_events_acc, sensor_data_acc); 194 | 195 | if(gyroscopeSensor != NULL){ 196 | ASensorEventQueue_enableSensor(sensorEventQueueGyro, gyroscopeSensor); 197 | ASensorEventQueue_setEventRate(sensorEventQueueGyro, gyroscopeSensor,(1000L/sampleFreq)*1000); 198 | } 199 | if(accelerometerSensor != NULL){ 200 | ASensorEventQueue_enableSensor(sensorEventQueueAcc, accelerometerSensor); 201 | ASensorEventQueue_setEventRate(sensorEventQueueAcc, accelerometerSensor,(1000L/sampleFreq)*1000); 202 | } 203 | } 204 | 205 | /* IMU algorithm update. Mahony implementation. 206 | */ 207 | void MahonyAHRSupdateIMU(float gx, float gy, float gz, float ax, float ay, float az,int64_t ev_timestamp) { 208 | if(time_stamp != -1){ 209 | float dT = (ev_timestamp - time_stamp) * N2S; 210 | float recipNorm; 211 | float halfvx, halfvy, halfvz; 212 | float halfex, halfey, halfez; 213 | float qa, qb, qc; 214 | 215 | // Compute feedback only if accelerometer measurement valid (avoids NaN in accelerometer normalisation) 216 | if(!((ax == 0.0f) && (ay == 0.0f) && (az == 0.0f))) { 217 | 218 | // Normalise accelerometer measurement 219 | recipNorm = invSqrt(ax * ax + ay * ay + az * az); 220 | ax *= recipNorm; 221 | ay *= recipNorm; 222 | az *= recipNorm; 223 | 224 | // Estimated direction of gravity and vector perpendicular to magnetic flux 225 | halfvx = q1 * q3 - q0 * q2; 226 | halfvy = q0 * q1 + q2 * q3; 227 | halfvz = q0 * q0 - 0.5f + q3 * q3; 228 | 229 | // Error is sum of cross product between estimated and measured direction of gravity 230 | halfex = (ay * halfvz - az * halfvy); 231 | halfey = (az * halfvx - ax * halfvz); 232 | halfez = (ax * halfvy - ay * halfvx); 233 | 234 | // Compute and apply integral feedback if enabled 235 | if(twoKi > 0.0f) { 236 | integralFBx += twoKi * halfex * dT/*(1.0f / sampleFreq)*/; // integral error scaled by Ki 237 | integralFBy += twoKi * halfey * dT/*(1.0f / sampleFreq)*/; 238 | integralFBz += twoKi * halfez * dT/*(1.0f / sampleFreq)*/; 239 | gx += integralFBx; // apply integral feedback 240 | gy += integralFBy; 241 | gz += integralFBz; 242 | } 243 | else { 244 | integralFBx = 0.0f; // prevent integral windup 245 | integralFBy = 0.0f; 246 | integralFBz = 0.0f; 247 | } 248 | 249 | // Apply proportional feedback 250 | gx += twoKp * halfex; 251 | gy += twoKp * halfey; 252 | gz += twoKp * halfez; 253 | } 254 | 255 | // Integrate rate of change of quaternion 256 | gx *= (0.5f * dT/*(1.0f / sampleFreq)*/); // pre-multiply common factors 257 | gy *= (0.5f * dT/*(1.0f / sampleFreq)*/); 258 | gz *= (0.5f * dT/*(1.0f / sampleFreq)*/); 259 | qa = q0; 260 | qb = q1; 261 | qc = q2; 262 | q0 += (-qb * gx - qc * gy - q3 * gz); 263 | q1 += (qa * gx + qc * gz - q3 * gy); 264 | q2 += (qa * gy - qb * gz + q3 * gx); 265 | q3 += (qa * gz + qb * gy - qc * gx); 266 | 267 | // Normalise quaternion 268 | recipNorm = invSqrt(q0 * q0 + q1 * q1 + q2 * q2 + q3 * q3); 269 | q0 *= recipNorm; 270 | q1 *= recipNorm; 271 | q2 *= recipNorm; 272 | q3 *= recipNorm; 273 | } 274 | time_stamp=ev_timestamp; 275 | } 276 | 277 | /* IMU algorithm update. Madgwick implementation. 278 | */ 279 | void MadgwickAHRSupdateIMU(float gx, float gy, float gz, float ax, float ay, float az) { 280 | float recipNorm; 281 | float s0, s1, s2, s3; 282 | float qDot1, qDot2, qDot3, qDot4; 283 | float _2q0, _2q1, _2q2, _2q3, _4q0, _4q1, _4q2 ,_8q1, _8q2, q0q0, q1q1, q2q2, q3q3; 284 | 285 | // Rate of change of quaternion from gyroscope 286 | qDot1 = 0.5f * (-q1 * gx - q2 * gy - q3 * gz); 287 | qDot2 = 0.5f * (q0 * gx + q2 * gz - q3 * gy); 288 | qDot3 = 0.5f * (q0 * gy - q1 * gz + q3 * gx); 289 | qDot4 = 0.5f * (q0 * gz + q1 * gy - q2 * gx); 290 | 291 | // Compute feedback only if accelerometer measurement valid (avoids NaN in accelerometer normalisation) 292 | if(!((ax == 0.0f) && (ay == 0.0f) && (az == 0.0f))) { 293 | 294 | // Normalise accelerometer measurement 295 | recipNorm = invSqrt(ax * ax + ay * ay + az * az); 296 | ax *= recipNorm; 297 | ay *= recipNorm; 298 | az *= recipNorm; 299 | 300 | // Auxiliary variables to avoid repeated arithmetic 301 | _2q0 = 2.0f * q0; 302 | _2q1 = 2.0f * q1; 303 | _2q2 = 2.0f * q2; 304 | _2q3 = 2.0f * q3; 305 | _4q0 = 4.0f * q0; 306 | _4q1 = 4.0f * q1; 307 | _4q2 = 4.0f * q2; 308 | _8q1 = 8.0f * q1; 309 | _8q2 = 8.0f * q2; 310 | q0q0 = q0 * q0; 311 | q1q1 = q1 * q1; 312 | q2q2 = q2 * q2; 313 | q3q3 = q3 * q3; 314 | 315 | // Gradient decent algorithm corrective step 316 | s0 = _4q0 * q2q2 + _2q2 * ax + _4q0 * q1q1 - _2q1 * ay; 317 | s1 = _4q1 * q3q3 - _2q3 * ax + 4.0f * q0q0 * q1 - _2q0 * ay - _4q1 + _8q1 * q1q1 + _8q1 * q2q2 + _4q1 * az; 318 | s2 = 4.0f * q0q0 * q2 + _2q0 * ax + _4q2 * q3q3 - _2q3 * ay - _4q2 + _8q2 * q1q1 + _8q2 * q2q2 + _4q2 * az; 319 | s3 = 4.0f * q1q1 * q3 - _2q1 * ax + 4.0f * q2q2 * q3 - _2q2 * ay; 320 | recipNorm = invSqrt(s0 * s0 + s1 * s1 + s2 * s2 + s3 * s3); // normalise step magnitude 321 | s0 *= recipNorm; 322 | s1 *= recipNorm; 323 | s2 *= recipNorm; 324 | s3 *= recipNorm; 325 | 326 | // Apply feedback step 327 | qDot1 -= beta * s0; 328 | qDot2 -= beta * s1; 329 | qDot3 -= beta * s2; 330 | qDot4 -= beta * s3; 331 | } 332 | 333 | // Integrate rate of change of quaternion to yield quaternion 334 | q0 += qDot1 * (1.0f / sampleFreq); 335 | q1 += qDot2 * (1.0f / sampleFreq); 336 | q2 += qDot3 * (1.0f / sampleFreq); 337 | q3 += qDot4 * (1.0f / sampleFreq); 338 | 339 | // Normalise quaternion 340 | recipNorm = invSqrt(q0 * q0 + q1 * q1 + q2 * q2 + q3 * q3); 341 | q0 *= recipNorm; 342 | q1 *= recipNorm; 343 | q2 *= recipNorm; 344 | q3 *= recipNorm; 345 | } 346 | 347 | /* Fast inverse square-root 348 | * See: http://en.wikipedia.org/wiki/Fast_inverse_square_root 349 | */ 350 | float invSqrt(float x) { 351 | float halfx = 0.5f * x; 352 | float y = x; 353 | long i = *(long*)&y; 354 | i = 0x5f3759df - (i>>1); 355 | y = *(float*)&i; 356 | y = y * (1.5f - (halfx * y * y)); 357 | return y; 358 | } 359 | 360 | /* Multiplies quaternions q1 and q2. Result goes in q1. 361 | */ 362 | void multiplyQuat(Quaternion* q1, Quaternion* q2){ 363 | float nx = (q1->w)*(q2->x) + (q1->x)*(q2->w) + (q1->y)*(q2->z) - (q1->z)*(q2->y); 364 | float ny = (q1->w*q2->y - q1->x*q2->z + q1->y*q2->w + q1->z*q2->x); 365 | float nz = (q1->w*q2->z + q1->x*q2->y - q1->y*q2->x + q1->z*q2->w); 366 | float nw = (q1->w*q2->w - q1->x*q2->x - q1->y*q2->y - q1->z*q2->z); 367 | q1->x = nx; 368 | q1->y = ny; 369 | q1->z = nz; 370 | q1->w = nw; 371 | } 372 | 373 | -------------------------------------------------------------------------------- /Prefabs/ALPSCamera.prefab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Foxman13/ALPS-VR/204cab8d68aa6689381c6f061872b27fa255a728/Prefabs/ALPSCamera.prefab -------------------------------------------------------------------------------- /Prefabs/ALPSLightCamera.prefab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Foxman13/ALPS-VR/204cab8d68aa6689381c6f061872b27fa255a728/Prefabs/ALPSLightCamera.prefab -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ALPS VR 2 | ======== 3 | 4 | NOTE: My fork is up-to-date with Unity 5 support and works fully with Unity Personal Edition 5 | 6 | #### Unity framework for mobile virtual reality apps #### 7 | 8 | The aim of the ALPS VR project is to create a lightweight Unity framework to help developers publish virtual reality apps for every mobile based viewers. Framework features include: 9 | *Side-by-side rendering 10 | *Barrel distortion 11 | *Chromatic aberration correction 12 | *Responsive head-tracking 13 | *Head gesture navigation system 14 | *Built-in configurations for supported devices 15 | 16 | [Official website](http://alpsvr.com) 17 | 18 | ### Usage ### 19 | 20 | Download the [Unity package](http://alpsvr.com) and import it into your Unity project. 21 | 22 | Drag and drop the ALPSCamera prefab (ALPS/Prefabs/ALPSCamera.prefab) into your scene. 23 | 24 | ![alt tag](/Screenshots/ALPSVR_Preview.JPG) 25 | 26 | ### Requirements ### 27 | * Unity 4.5 Pro or higher (untested on previous versions) 28 | * To deploy on Android: 29 | * Unity Pro for Android 30 | * Android SDK 3.2 or higher 31 | * To deploy to Windows Phone 8.1 32 | * Unity Pro 33 | * Visual Studio 2013 Update 4 or higher with the Windows SDK 34 | 35 | -------------------------------------------------------------------------------- /Resources/ALPSSkin.guiskin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Foxman13/ALPS-VR/204cab8d68aa6689381c6f061872b27fa255a728/Resources/ALPSSkin.guiskin -------------------------------------------------------------------------------- /Resources/Materials/ALPSDistortion.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Foxman13/ALPS-VR/204cab8d68aa6689381c6f061872b27fa255a728/Resources/Materials/ALPSDistortion.mat -------------------------------------------------------------------------------- /Resources/Textures/arcs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Foxman13/ALPS-VR/204cab8d68aa6689381c6f061872b27fa255a728/Resources/Textures/arcs.png -------------------------------------------------------------------------------- /Resources/Textures/blue.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Foxman13/ALPS-VR/204cab8d68aa6689381c6f061872b27fa255a728/Resources/Textures/blue.jpg -------------------------------------------------------------------------------- /Resources/Textures/progress_point.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Foxman13/ALPS-VR/204cab8d68aa6689381c6f061872b27fa255a728/Resources/Textures/progress_point.png -------------------------------------------------------------------------------- /Screenshots/ALPSVR_Preview.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Foxman13/ALPS-VR/204cab8d68aa6689381c6f061872b27fa255a728/Screenshots/ALPSVR_Preview.JPG -------------------------------------------------------------------------------- /Scripts/ALPSAndroid.cs: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | ALPSAndroid is an interface with the Android system 3 | 4 | Copyright (C) 2014 ALPS VR. 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | 19 | ************************************************************************/ 20 | 21 | using UnityEngine; 22 | using System; 23 | 24 | public class ALPSAndroid : MonoBehaviour { 25 | #if UNITY_ANDROID 26 | //===================================================================================================== 27 | // Attributes 28 | //===================================================================================================== 29 | 30 | /**Private**/ 31 | private static AndroidJavaClass jc; 32 | 33 | //===================================================================================================== 34 | // Attributes 35 | //===================================================================================================== 36 | 37 | /// 38 | /// Initializes Android ALPS Activity. 39 | /// 40 | public static void Init () { 41 | Screen.sleepTimeout = SleepTimeout.NeverSleep; 42 | jc = new AndroidJavaClass ("com.alpsvr.android.ALPSActivity"); 43 | } 44 | 45 | /// 46 | /// Vibrates constantly for 8 milliseconds. 47 | /// 48 | public static void Vibrate(){ 49 | Vibrate(8); 50 | } 51 | 52 | /// 53 | /// Vibrates constantly for the specified period of time. 54 | /// 55 | /// The number of milliseconds to vibrate. 56 | public static void Vibrate(int _milliseconds){ 57 | jc.CallStatic ("vibrate",_milliseconds); 58 | } 59 | 60 | /// 61 | /// The absolute width of the display in pixels. 62 | /// 63 | public static int WidthPixels(){ 64 | return jc.CallStatic ("getWidthPixel"); 65 | } 66 | 67 | /// 68 | /// The absolute height of the display in pixels. 69 | /// 70 | public static int HeightPixels(){ 71 | return jc.CallStatic ("getHeightPixel"); 72 | } 73 | 74 | /// 75 | /// The device orientation. 76 | /// 77 | public static Quaternion DeviceOrientation(){ 78 | //switch x and y 79 | float y = jc.CallStatic ("getGameRotationX"); 80 | float x = jc.CallStatic ("getGameRotationY"); 81 | float z = jc.CallStatic ("getGameRotationZ"); 82 | float w = jc.CallStatic ("getGameRotationW"); 83 | return new Quaternion (x,-y,z,w); 84 | } 85 | #endif 86 | } 87 | -------------------------------------------------------------------------------- /Scripts/ALPSBarrelMesh.cs: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | ALPSBarrelMesh is a factory which creates barrel shaped meshes 3 | 4 | Copyright (C) 2014 ALPS VR. 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | 19 | ************************************************************************/ 20 | 21 | using UnityEngine; 22 | using System.Collections; 23 | 24 | public class ALPSBarrelMesh { 25 | //===================================================================================================== 26 | // Attributes 27 | //===================================================================================================== 28 | 29 | /**Public**/ 30 | public static ALPSConfig deviceConfig; 31 | 32 | //===================================================================================================== 33 | // Attributes 34 | //===================================================================================================== 35 | 36 | /// 37 | /// Creates a barrel distorted mesh. 38 | /// 39 | /// Mesh resolution: number of lines. 40 | /// Mesh resolution: number of columns. 41 | /// True if the mesh is used for left camera, false otherwise. 42 | public static Mesh GenerateMesh(int _lines, int _columns,bool _leftEye){ 43 | float k1, k2; 44 | if (!deviceConfig.enableBarrelDistortion) { 45 | k1 = k2 = 0; 46 | } else { 47 | k1 = deviceConfig.k1; 48 | k2 = deviceConfig.k2; 49 | } 50 | int numVertices = (_lines + 1) * (_columns + 1); 51 | int numFaces = _lines * _columns; 52 | Mesh mesh = new Mesh (); 53 | Vector3[] vertices = new Vector3[numVertices]; 54 | Vector2[] uvs = new Vector2[numVertices]; 55 | int[] tri = new int[numFaces*6]; 56 | //If IPD is smaller than half of the width, we take width/2 for IPD 57 | //Otherwise meshes are outward-oriented 58 | float widthIPDRatio = (deviceConfig.IPD <= deviceConfig.Width * 0.5f || deviceConfig.fixedSize)?(deviceConfig.IPD / deviceConfig.Width) : 0.5f; 59 | Vector2 center = new Vector2 (_leftEye?1-widthIPDRatio:widthIPDRatio,0.5f); 60 | int x, y; 61 | 62 | //Creation of the vertices 63 | int numQuad = 0; 64 | float maxX = (_leftEye?1:0); 65 | float maxY = 0; 66 | for (y=0; y<=_lines; y++) { 67 | for(x=0; x<=_columns; x++){ 68 | int index = y*(_lines+1)+x; 69 | Vector2 vertex = new Vector2(); 70 | 71 | float rSqr = Mathf.Pow (center.x-((float)x/(float)_columns),2) + Mathf.Pow (center.y-((float)y/(float)_lines),2); 72 | float rMod = 1+k1*rSqr+k2*rSqr*rSqr; 73 | 74 | vertex.x = (float)((float)x/(float)_columns-center.x)/(float)rMod+center.x-0.5f; 75 | vertex.y = (float)((float)y/(float)_lines-center.y)/(float)rMod+center.y-0.5f; 76 | if(_leftEye){ 77 | if(vertex.xmaxX)maxX=vertex.x; 80 | } 81 | if(vertex.y>maxY)maxY=vertex.y; 82 | vertices[index] = new Vector3(vertex.x, vertex.y, 0); 83 | uvs[index] = new Vector2((float)x/(float)_columns,(float)y/(float)_lines); 84 | 85 | if(x<_columns && y<_lines){ 86 | int v; 87 | for(v=0;v<6;v++){ 88 | tri[numQuad*6+v] = index + ((v>=2 && v!=3) ? _columns : 0) + ((v==0) ? 0 : (v/5)+1); 89 | } 90 | numQuad++; 91 | } 92 | } 93 | } 94 | 95 | float scaleFactor = 1f/Mathf.Max(_leftEye?-1*(1-maxX):maxX,maxY); 96 | 97 | int i; 98 | for(i=0; i. 18 | 19 | ************************************************************************/ 20 | 21 | using UnityEngine; 22 | using System.Collections; 23 | 24 | public class ALPSCamera : MonoBehaviour{ 25 | 26 | //===================================================================================================== 27 | // Attributes 28 | //===================================================================================================== 29 | 30 | /**Public**/ 31 | public static ALPSConfig deviceConfig; 32 | public bool leftEye; 33 | 34 | /**Private**/ 35 | private Mesh mesh; 36 | 37 | //===================================================================================================== 38 | // Functions 39 | //===================================================================================================== 40 | 41 | /// 42 | /// Initializes the camera. 43 | /// 44 | public void Init(){ 45 | Vector3 camLeftPos = GetComponent().transform.localPosition; 46 | camLeftPos.x = (leftEye?-1:1) * deviceConfig.ILD * 0.0005f; 47 | camLeftPos.z = ALPSConfig.neckPivotToEye.x * 0.001f; 48 | camLeftPos.y = ALPSConfig.neckPivotToEye.y * 0.001f; 49 | GetComponent().transform.localPosition = camLeftPos; 50 | } 51 | 52 | /// 53 | /// Updates the mesh used for barrel distortion. 54 | /// 55 | public void UpdateMesh(){ 56 | GetComponent().rect = new Rect ((leftEye?0f:0.5f),0f,0.5f,1f); 57 | GetComponent().aspect = deviceConfig.Width*0.5f / deviceConfig.Height; 58 | mesh = ALPSBarrelMesh.GenerateMesh(20,20,leftEye); 59 | } 60 | 61 | /// 62 | /// Draws render texture on mesh. 63 | /// 64 | public void Draw(){ 65 | Graphics.DrawMeshNow (mesh,Camera.current.transform.position,Camera.current.transform.rotation); 66 | } 67 | } -------------------------------------------------------------------------------- /Scripts/ALPSConfig.cs: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | ALPSConfig describes a configuration for one particular device 3 | 4 | Copyright (C) 2014 ALPS VR. 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | 19 | ************************************************************************/ 20 | 21 | using UnityEngine; 22 | using System.Collections; 23 | 24 | [System.Serializable] 25 | public class ALPSConfig{ 26 | 27 | //===================================================================================================== 28 | // Attributes 29 | //===================================================================================================== 30 | 31 | /**Public**/ 32 | public const float INCH_TO_MM = 25.4f; 33 | public static float DEFAULT_DPI = 96f; 34 | 35 | //Vector between eyes and the pivot point (neck) 36 | public static Vector2 neckPivotToEye = new Vector2 (80f,120f); 37 | 38 | //Configuration name 39 | public Device deviceName; 40 | 41 | //Is barrel distortion enabled or not 42 | public bool enableBarrelDistortion; 43 | 44 | //Is chromatic correction enabled or not 45 | public bool enableChromaticCorrection; 46 | 47 | //Does the application run in full screen or must it have the same 48 | //size on every device 49 | public bool fixedSize; 50 | 51 | //Inter pupillary distance in millimeters. Must match the distance between 52 | //users' eyes 53 | public float IPD; 54 | 55 | //Inter lens distance in millimeters. Should match the IPD but can be tweaked 56 | //to increase or decrease the stereo effect. Basically, with an ILD set to 0, there 57 | //is no 3D effect. 58 | public float ILD; 59 | 60 | //Vertical field of view of both cameras 61 | [Range(1,179)] 62 | public float fieldOfView; 63 | 64 | //Chromatic correction coefficient 65 | public float chromaticCorrection; 66 | 67 | //Barrel distortion parameters. 68 | public float k1; 69 | public float k2; 70 | 71 | //DPI 72 | public float DPI; 73 | 74 | //Width of the viewport in mm 75 | [SerializeField] 76 | private int width; 77 | public int Width { 78 | get{return (int)(fixedSize?width:ALPSController.screenWidthPix/DPI*INCH_TO_MM);} 79 | set{ 80 | if(value<0) width = 0; 81 | else width = value; 82 | } 83 | } 84 | 85 | //Height of the viewport in mm 86 | [SerializeField] 87 | private int height; 88 | public int Height { 89 | get{ 90 | return (int)(fixedSize?height:ALPSController.screenHeightPix/DPI*INCH_TO_MM);} 91 | set{ 92 | if(value<0) height = 0; 93 | else height = value; 94 | } 95 | } 96 | 97 | //===================================================================================================== 98 | // Functions 99 | //===================================================================================================== 100 | 101 | /// 102 | /// Viewport height in pixels. 103 | /// 104 | public int HeightPix(){ 105 | return (int)(fixedSize ? Height * DPI / INCH_TO_MM : ALPSController.screenHeightPix); 106 | } 107 | 108 | /// 109 | /// Viewport width in pixels. 110 | /// 111 | public int WidthPix(){ 112 | return (int)(fixedSize ? Width * DPI / INCH_TO_MM : ALPSController.screenWidthPix); 113 | } 114 | 115 | /// 116 | /// Creates a new device configuration. 117 | /// 118 | /// Device name. 119 | /// True if barrel distortion must be enabled, false otherwise. 120 | /// True if chromatic correction must be enabled, false otherwise. 121 | /// True is viewport must be fixed insize, false if viewport must be fullscreen. 122 | /// Inter pupillary distance in millimeters. Must match the distance between users' eyes 123 | /// IInter lens distance in millimeters. Should match the IPD but can be tweaked to increase or decrease the stereo effect. 124 | /// Cameras field of view. 125 | /// Chromatic Correction factor. 126 | /// Barrel distortion first order factor. 127 | /// Barrel distortion second order factor. 128 | /// Viewport width in millimeters if fixed in size, ignored otherwise. 129 | /// Viewport height in millimeters if fixed in size, ignored otherwise. 130 | public ALPSConfig(Device _DeviceName, bool _EnableBarrelDistortion, bool _EnableChromaticCorrection, bool _FixedSize, float _IPD, float _ILD, float _FieldOfView, float _ChromaticCorrection, float _k1, float _k2, int _Width, int _Height){ 131 | 132 | deviceName = _DeviceName; 133 | IPD = _IPD; 134 | ILD = _ILD; 135 | fieldOfView = _FieldOfView; 136 | chromaticCorrection = _ChromaticCorrection; 137 | k1 = _k1; 138 | k2 = _k2; 139 | Width = _Width; 140 | Height = _Height; 141 | enableBarrelDistortion = _EnableBarrelDistortion; 142 | enableChromaticCorrection = _EnableChromaticCorrection; 143 | fixedSize = _FixedSize; 144 | } 145 | 146 | /// 147 | /// Returns current screen option : FixedSize or FullScreen. 148 | /// 149 | public ScreenOption GetScreenOption(){ 150 | return fixedSize ? ScreenOption.FixedSize : ScreenOption.FullScreen; 151 | } 152 | 153 | /// 154 | /// Return IPD in pixels. 155 | /// 156 | public int GetIPDPixels(){ 157 | //IPD is in millimeters while DPI is in inches 158 | return (int)(IPD * DPI / INCH_TO_MM); 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /Scripts/ALPSController.cs: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | ALPSController is the main class which manages custom rendering 3 | 4 | Copyright (C) 2014 ALPS VR. 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | 19 | ************************************************************************/ 20 | 21 | using UnityEngine; 22 | using System.Collections; 23 | 24 | [System.Serializable] 25 | public class ALPSController : MonoBehaviour { 26 | 27 | //===================================================================================================== 28 | // Attributes 29 | //===================================================================================================== 30 | 31 | /**Public**/ 32 | //The current device configuration 33 | public ALPSConfig deviceConfig = ALPSDevice.GetConfig(Device.DEFAULT); 34 | 35 | //One camera for each eye 36 | public GameObject cameraLeft; 37 | public GameObject cameraRight; 38 | 39 | //Head represents user's head 40 | public GameObject head; 41 | 42 | //Render textures 43 | public RenderTexture srcTex; 44 | public RenderTexture destTex; 45 | 46 | //Screen size 47 | public static int screenWidthPix; 48 | public static int screenHeightPix; 49 | 50 | //Material 51 | public Material mat; 52 | 53 | //Crosshairs 54 | public bool crosshairsEnabled; 55 | 56 | /**Private**/ 57 | private Rect rectLeft,rectRight; 58 | private float DPI; 59 | 60 | //===================================================================================================== 61 | // Functions 62 | //===================================================================================================== 63 | 64 | /// 65 | /// Initializes side-by-side rendering and head tracking. 66 | /// 67 | public void Awake(){ 68 | ALPSCamera.deviceConfig = deviceConfig; 69 | ALPSBarrelMesh.deviceConfig = deviceConfig; 70 | ALPSCrosshairs.deviceConfig = deviceConfig; 71 | ALPSGUI.controller = this; 72 | 73 | head = new GameObject ("ALPSHead"); 74 | head.transform.parent = transform; 75 | head.transform.position = transform.position; 76 | 77 | #if UNITY_EDITOR 78 | head.AddComponent(); 79 | screenWidthPix = Screen.width; 80 | screenHeightPix = Screen.height; 81 | #elif UNITY_ANDROID 82 | head.AddComponent(); 83 | Screen.orientation = ScreenOrientation.LandscapeLeft; 84 | ALPSAndroid.Init (); 85 | screenWidthPix = ALPSAndroid.WidthPixels (); 86 | screenHeightPix = ALPSAndroid.HeightPixels (); 87 | #elif UNITY_WP_8_1 88 | head.AddComponent(); 89 | Screen.orientation = ScreenOrientation.LandscapeLeft; 90 | ALPSWP8.Init(); 91 | screenWidthPix = ALPSWP8.WidthPixels (); 92 | screenHeightPix = ALPSWP8.HeightPixels (); 93 | #endif 94 | 95 | //Make sure the longer dimension is width as the phone is always in landscape mode 96 | if(screenWidthPix(); 106 | OneCamera.AddComponent(); 107 | (OneCamera.GetComponent("ALPSCamera") as ALPSCamera).leftEye = left; 108 | OneCamera.transform.parent = head.transform; 109 | OneCamera.transform.position = head.transform.position; 110 | if(left)cameraLeft = OneCamera; 111 | else cameraRight = OneCamera; 112 | } 113 | 114 | ALPSCamera[] ALPSCameras = FindObjectsOfType(typeof(ALPSCamera)) as ALPSCamera[]; 115 | foreach (ALPSCamera cam in ALPSCameras) { 116 | cam.Init(); 117 | } 118 | 119 | mat = Resources.Load ("Materials/ALPSDistortion") as Material; 120 | 121 | DPI = Screen.dpi; 122 | 123 | //Render Textures 124 | srcTex = new RenderTexture (2048, 1024, 16); 125 | destTex = GetComponent().targetTexture; 126 | cameraLeft.GetComponent().targetTexture = cameraRight.GetComponent().targetTexture = srcTex; 127 | 128 | // Setting the main camera 129 | GetComponent().aspect = 1f; 130 | GetComponent().backgroundColor = Color.black; 131 | GetComponent().clearFlags = CameraClearFlags.Nothing; 132 | GetComponent().cullingMask = 0; 133 | GetComponent().eventMask = 0; 134 | GetComponent().orthographic = true; 135 | GetComponent().renderingPath = RenderingPath.Forward; 136 | GetComponent().useOcclusionCulling = false; 137 | cameraLeft.GetComponent().depth = 0; 138 | cameraRight.GetComponent().depth = 1; 139 | GetComponent().depth = Mathf.Max (cameraLeft.GetComponent().depth, cameraRight.GetComponent().depth) + 1; 140 | 141 | cameraLeft.gameObject.AddComponent(); 142 | cameraRight.gameObject.AddComponent(); 143 | 144 | AudioListener[] listeners = FindObjectsOfType(typeof(AudioListener)) as AudioListener[]; 145 | if (listeners.Length < 1) { 146 | gameObject.AddComponent (); 147 | } 148 | 149 | ClearDirty(); 150 | } 151 | 152 | /// 153 | /// Renders scene for both cameras. 154 | /// 155 | public void OnPostRender(){ 156 | RenderTexture.active = destTex; 157 | GL.Clear (false,true,Color.black); 158 | RenderEye (true,srcTex); 159 | RenderEye (false,srcTex); 160 | srcTex.DiscardContents (); 161 | } 162 | 163 | /// 164 | /// Renders scene for one camera. 165 | /// 166 | /// True if renders for the left camera, false otherwise. 167 | /// Source texture on which the camera renders. 168 | private void RenderEye(bool _leftEye, RenderTexture _source){ 169 | mat.mainTexture = _source; 170 | mat.SetVector("_SHIFT",new Vector2(_leftEye?0:0.5f,0)); 171 | float convergeOffset = ((deviceConfig.Width * 0.5f) - deviceConfig.IPD) / deviceConfig.Width; 172 | mat.SetVector("_CONVERGE",new Vector2((_leftEye?1f:-1f)*convergeOffset,0)); 173 | mat.SetFloat ("_AberrationOffset",deviceConfig.enableChromaticCorrection?deviceConfig.chromaticCorrection:0f); 174 | float ratio = (deviceConfig.IPD*0.5f) / deviceConfig.Width; 175 | mat.SetVector ("_Center",new Vector2(0.5f+(_leftEye?-ratio:ratio),0.5f)); 176 | 177 | GL.Viewport (_leftEye ? rectLeft : rectRight); 178 | 179 | GL.PushMatrix (); 180 | GL.LoadOrtho (); 181 | mat.SetPass (0); 182 | if(_leftEye)cameraLeft.GetComponent().Draw (); 183 | else cameraRight.GetComponent().Draw (); 184 | GL.PopMatrix (); 185 | } 186 | 187 | /// 188 | /// Resets all the settings and applies the current DeviceConfig 189 | /// 190 | public void ClearDirty(){ 191 | //We give the current DPI to the new ALPSConfig 192 | deviceConfig.DPI = DPI; 193 | if (deviceConfig.DPI <= 0) { 194 | deviceConfig.DPI = ALPSConfig.DEFAULT_DPI; 195 | } 196 | 197 | if(cameraLeft!=null && cameraRight!=null){ 198 | float widthPix = deviceConfig.WidthPix(); 199 | float heightPix = deviceConfig.HeightPix(); 200 | 201 | rectLeft = new Rect (screenWidthPix*0.5f-widthPix*0.5f,screenHeightPix*0.5f-heightPix*0.5f,widthPix*0.5f,heightPix); 202 | rectRight = new Rect (screenWidthPix*0.5f,screenHeightPix*0.5f-heightPix*0.5f,widthPix*0.5f,heightPix); 203 | 204 | Vector3 camLeftPos = cameraLeft.transform.localPosition; 205 | camLeftPos.x = -deviceConfig.ILD*0.0005f; 206 | cameraLeft.transform.localPosition = camLeftPos; 207 | 208 | Vector3 camRightPos = cameraRight.transform.localPosition; 209 | camRightPos.x = deviceConfig.ILD*0.0005f; 210 | cameraRight.transform.localPosition = camRightPos; 211 | 212 | cameraLeft.GetComponent().fieldOfView = deviceConfig.fieldOfView; 213 | cameraRight.GetComponent().fieldOfView = deviceConfig.fieldOfView; 214 | 215 | cameraLeft.GetComponent().UpdateMesh(); 216 | cameraRight.GetComponent().UpdateMesh(); 217 | } 218 | 219 | ALPSCrosshairs[] ch = GetComponentsInChildren (); 220 | foreach (ALPSCrosshairs c in ch) { 221 | c.UpdateCrosshairs(); 222 | c.enabled = crosshairsEnabled; 223 | } 224 | } 225 | 226 | /// 227 | /// Indicates whether viewport should be fullscreen or fixed in size 228 | /// 229 | /// True if fixed in size, false if fullscreen. 230 | public void SetFixedSize(bool _fixed){ 231 | if (_fixed != deviceConfig.fixedSize) { 232 | ClearDirty(); 233 | } 234 | deviceConfig.fixedSize = _fixed; 235 | } 236 | 237 | /// 238 | /// Sets a new device configuration. 239 | /// 240 | // Name of the device. 241 | public void SetDevice(Device _device){ 242 | deviceConfig = ALPSDevice.GetConfig (_device); 243 | ALPSCamera.deviceConfig = deviceConfig; 244 | ALPSBarrelMesh.deviceConfig = deviceConfig; 245 | ALPSCrosshairs.deviceConfig = deviceConfig; 246 | ClearDirty (); 247 | } 248 | 249 | /// 250 | /// Copy camera settings to left and right cameras. Will overwrite culling masks. 251 | /// 252 | /// The camera from which you want to copy the settings. 253 | public void SetCameraSettings(Camera _cam){ 254 | cameraLeft.GetComponent().CopyFrom (_cam); 255 | cameraRight.GetComponent().CopyFrom (_cam); 256 | cameraLeft.GetComponent().rect = new Rect (0,0,0.5f,1); 257 | cameraRight.GetComponent().rect = new Rect (0.5f,0,0.5f,1); 258 | } 259 | 260 | /// 261 | /// Adds left and right layers to the existing culling masks for left and right cameras. 262 | /// 263 | /// Name of the layer rendered by the left camera. 264 | /// Name of the layer rendered by the right camera. 265 | public int SetStereoLayers(string _leftLayer, string _rightLayer){ 266 | int leftLayer = LayerMask.NameToLayer (_leftLayer); 267 | int rightLayer = LayerMask.NameToLayer (_rightLayer); 268 | if (leftLayer < 0 && rightLayer < 0) return -1; 269 | 270 | cameraLeft.GetComponent().cullingMask |= 1 << LayerMask.NameToLayer(_leftLayer); 271 | cameraLeft.GetComponent().cullingMask &= ~(1 << LayerMask.NameToLayer(_rightLayer)); 272 | 273 | cameraRight.GetComponent().cullingMask |= 1 << LayerMask.NameToLayer(_rightLayer); 274 | cameraRight.GetComponent().cullingMask &= ~(1 << LayerMask.NameToLayer(_leftLayer)); 275 | 276 | return 0; 277 | } 278 | 279 | /// 280 | /// Returns point of view position. This can be useful for setting up a Raycast. 281 | /// 282 | public Vector3 PointOfView(){ 283 | //returns current position plus NeckToEye vector 284 | return new Vector3(transform.position.x,transform.position.y + ALPSConfig.neckPivotToEye.y*0.001f,transform.position.z + ALPSConfig.neckPivotToEye.x*0.001f); 285 | } 286 | 287 | /// 288 | /// Returns forward direction vector. This can be useful for setting up a Raycast. 289 | /// 290 | public Vector3 ForwardDirection(){ 291 | return cameraLeft.GetComponent().transform.forward; 292 | } 293 | 294 | /// 295 | /// Returns left and right cameras. 296 | /// 297 | public Camera[] GetCameras(){ 298 | Camera[] cams = {cameraLeft.GetComponent(), cameraRight.GetComponent()}; 299 | return cams; 300 | } 301 | } -------------------------------------------------------------------------------- /Scripts/ALPSControllerLight.cs: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | ALPSControllerLight is the main class for non Pro license holders 3 | 4 | Copyright (C) 2014 ALPS VR. 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | 19 | ************************************************************************/ 20 | 21 | using UnityEngine; 22 | using System.Collections; 23 | 24 | public class ALPSControllerLight : MonoBehaviour { 25 | 26 | //===================================================================================================== 27 | // Attributes 28 | //===================================================================================================== 29 | 30 | /**Public**/ 31 | //One camera for each eye 32 | public GameObject cameraLeft; 33 | public GameObject cameraRight; 34 | 35 | //Head represents user's head 36 | public GameObject head; 37 | 38 | //Inter lens distance in millimeters. Should match the IPD but can be tweaked 39 | //to increase or decrease the stereo effect. Basically, with an ILD set to 0, there 40 | //is no 3D effect. 41 | public float ILD; 42 | 43 | //Vector between eyes and the pivot point (neck) 44 | public Vector2 neckToEye; 45 | 46 | //===================================================================================================== 47 | // Functions 48 | //===================================================================================================== 49 | 50 | /// 51 | /// Initializes side-by-side rendering and head tracking. 52 | /// 53 | public void Awake () { 54 | head = new GameObject ("ALPSHead"); 55 | head.transform.parent = transform; 56 | head.transform.position = transform.position; 57 | #if UNITY_EDITOR 58 | head.AddComponent (); 59 | #elif UNITY_ANDROID 60 | head.AddComponent("ALPSGyro"); 61 | #endif 62 | cameraLeft = new GameObject("CameraLeft"); 63 | cameraLeft.AddComponent (); 64 | cameraLeft.GetComponent().rect = new Rect (0,0,0.5f,1); 65 | cameraLeft.transform.parent = head.transform; 66 | cameraLeft.transform.position = head.transform.position; 67 | cameraLeft.transform.localPosition = new Vector3 (ILD*-0.0005f,neckToEye.y*0.001f,neckToEye.x*0.001f); 68 | 69 | cameraRight = new GameObject("CameraRight"); 70 | cameraRight.AddComponent (); 71 | cameraRight.GetComponent().rect = new Rect (0.5f,0,0.5f,1); 72 | cameraRight.transform.parent = head.transform; 73 | cameraRight.transform.position = head.transform.position; 74 | cameraRight.transform.localPosition = new Vector3 (ILD*0.0005f,neckToEye.y*0.001f,neckToEye.x*0.001f); 75 | 76 | AudioListener[] listeners = FindObjectsOfType(typeof(AudioListener)) as AudioListener[]; 77 | if (listeners.Length < 1) { 78 | gameObject.AddComponent (); 79 | } 80 | } 81 | 82 | /// 83 | /// Copy camera settings to left and right cameras. Will overwrite culling masks. 84 | /// 85 | /// The camera from which you want to copy the settings. 86 | public void SetCameraSettings(Camera _cam){ 87 | cameraLeft.GetComponent().CopyFrom (_cam); 88 | cameraRight.GetComponent().CopyFrom (_cam); 89 | cameraLeft.GetComponent().rect = new Rect (0,0,0.5f,1); 90 | cameraRight.GetComponent().rect = new Rect (0.5f,0,0.5f,1); 91 | } 92 | 93 | /// 94 | /// Adds left and right layers to the existing culling masks for left and right cameras. 95 | /// 96 | /// Name of the layer rendered by the left camera. 97 | /// Name of the layer rendered by the right camera. 98 | public int SetStereoLayers(string _leftLayer, string _rightLayer){ 99 | int leftLayer = LayerMask.NameToLayer (_leftLayer); 100 | int rightLayer = LayerMask.NameToLayer (_rightLayer); 101 | if (leftLayer < 0 && rightLayer < 0) return -1; 102 | 103 | cameraLeft.GetComponent().cullingMask |= 1 << LayerMask.NameToLayer(_leftLayer); 104 | cameraLeft.GetComponent().cullingMask &= ~(1 << LayerMask.NameToLayer(_rightLayer)); 105 | 106 | cameraRight.GetComponent().cullingMask |= 1 << LayerMask.NameToLayer(_rightLayer); 107 | cameraRight.GetComponent().cullingMask &= ~(1 << LayerMask.NameToLayer(_leftLayer)); 108 | 109 | return 0; 110 | } 111 | 112 | /// 113 | /// Returns point of view position. This can be useful for setting up a Raycast. 114 | /// 115 | public Vector3 PointOfView(){ 116 | //returns current position plus NeckToEye vector 117 | return new Vector3(transform.position.x,transform.position.y + neckToEye.y*0.001f,transform.position.z + neckToEye.x*0.001f); 118 | } 119 | 120 | /// 121 | /// Returns forward direction vector. This can be useful for setting up a Raycast. 122 | /// 123 | public Vector3 ForwardDirection(){ 124 | return cameraLeft.GetComponent().transform.forward; 125 | } 126 | 127 | /// 128 | /// Returns left and right cameras. 129 | /// 130 | public Camera[] GetCameras(){ 131 | Camera[] cams = {cameraLeft.GetComponent(), cameraRight.GetComponent()}; 132 | return cams; 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /Scripts/ALPSCrosshairs.cs: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | ALPSCrosshair adds a crosshair in the middle of the screen 3 | 4 | Copyright (C) 2014 ALPS VR. 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | 19 | ************************************************************************/ 20 | 21 | using UnityEngine; 22 | using System.Collections; 23 | 24 | public class ALPSCrosshairs : MonoBehaviour { 25 | 26 | //===================================================================================================== 27 | // Attributes 28 | //===================================================================================================== 29 | 30 | /**Public**/ 31 | public static ALPSConfig deviceConfig; 32 | 33 | 34 | /**Private**/ 35 | private Vector2 centerGUI; 36 | private Vector2 centerGUIBar; 37 | private Vector2 centerIPD; 38 | private bool leftEye; 39 | private Texture2D arc; 40 | private Texture2D bar; 41 | 42 | //===================================================================================================== 43 | // Functions 44 | //===================================================================================================== 45 | 46 | /// 47 | /// Initializes crosshairs. 48 | /// 49 | public void Awake(){ 50 | leftEye = GetComponent ().leftEye; 51 | arc = Resources.Load ("Textures/arcs") as Texture2D ; 52 | bar = Resources.Load ("Textures/progress_point") as Texture2D ; 53 | 54 | centerIPD = new Vector2 (ALPSController.screenWidthPix*0.5f + ((leftEye?-1:1) * ((deviceConfig.IPD <= deviceConfig.Width * 0.5f)?deviceConfig.GetIPDPixels()*0.5f:ALPSController.screenWidthPix*0.25f)) ,ALPSController.screenHeightPix * 0.5f); 55 | centerGUI = new Vector2(centerIPD.x-(arc.width * 0.5f),centerIPD.y-(arc.height * 0.5f)); 56 | centerGUIBar = new Vector2(centerIPD.x-(bar.width * 0.5f),centerIPD.y-(bar.height * 0.5f)); 57 | } 58 | 59 | /// 60 | /// Updates crosshairs. 61 | /// 62 | public void UpdateCrosshairs(){ 63 | centerIPD = new Vector2 (ALPSController.screenWidthPix*0.5f + ((leftEye?-1:1) * ((deviceConfig.IPD <= deviceConfig.Width * 0.5f)?deviceConfig.GetIPDPixels()*0.5f:ALPSController.screenWidthPix*0.25f)) ,ALPSController.screenHeightPix * 0.5f); 64 | centerGUI = new Vector2(centerIPD.x-(arc.width * 0.5f),centerIPD.y-(arc.height * 0.5f)); 65 | centerGUIBar = new Vector2(centerIPD.x-(bar.width * 0.5f),centerIPD.y-(bar.height * 0.5f)); 66 | } 67 | 68 | /// 69 | /// Paints the crosshairs. 70 | /// 71 | public void OnGUI(){ 72 | GUI.DrawTexture(new Rect(centerGUI.x,centerGUI.y,arc.width,arc.height),arc,ScaleMode.ScaleToFit, true, 0f); 73 | centerGUIBar = new Vector2(centerIPD.x-((arc.width-4)*ALPSNavigation.Progress() * 0.5f),centerIPD.y-(bar.height * 0.5f)); 74 | GUI.DrawTexture(new Rect(centerGUIBar.x,centerGUIBar.y,(arc.width-4)*ALPSNavigation.Progress(),bar.height),bar,ScaleMode.StretchToFill, true, 0f); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /Scripts/ALPSDevice.cs: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | ALPSDevice provides a specific configuration for each supported device 3 | 4 | Copyright (C) 2014 ALPS VR. 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | 19 | ************************************************************************/ 20 | 21 | using UnityEngine; 22 | using System.Collections; 23 | 24 | //==================================================================================================== 25 | // Attributes 26 | //==================================================================================================== 27 | 28 | public enum Device{ 29 | DEFAULT, 30 | ALTERGAZE, 31 | CARDBOARD, 32 | FIREFLY 33 | }; 34 | 35 | public enum ScreenOption{ 36 | FixedSize, 37 | FullScreen 38 | }; 39 | 40 | public class ALPSDevice { 41 | 42 | //==================================================================================================== 43 | // Functions 44 | //==================================================================================================== 45 | 46 | /// 47 | /// Returns device configuration corresponding to a device name. 48 | /// 49 | /// Device name. 50 | public static ALPSConfig GetConfig(Device _device){ 51 | ALPSConfig config; 52 | switch (_device) { 53 | case Device.ALTERGAZE: 54 | config = new ALPSConfig(Device.ALTERGAZE,true,true,false,62f,62f,85f,-1f,0.4f,0.2f,0,0); 55 | break; 56 | case Device.CARDBOARD: 57 | config = new ALPSConfig(Device.CARDBOARD,true,true,false,62f,62f,85f,-1.5f,0.5f,0.2f,128,75); 58 | break; 59 | case Device.FIREFLY: 60 | config = new ALPSConfig(Device.FIREFLY,true,true,false,62f,62f,85f,-2f,0.7f,0.2f,140,75); 61 | break; 62 | case Device.DEFAULT: 63 | default: 64 | config = new ALPSConfig(Device.DEFAULT,false,false,false,62f,62f,85f,0f,0f,0f,0,0); 65 | break; 66 | } 67 | return config; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /Scripts/ALPSGUI.cs: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | ALPSGUI provides a basic menu to choose a headset 3 | 4 | Copyright (C) 2014 ALPS VR. 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | 19 | ************************************************************************/ 20 | 21 | using UnityEngine; 22 | using System.Collections; 23 | 24 | public class ALPSGUI : MonoBehaviour { 25 | 26 | //===================================================================================================== 27 | // Attributes 28 | //===================================================================================================== 29 | 30 | /**Public**/ 31 | public static ALPSController controller; 32 | 33 | /**Private**/ 34 | private float beginX; 35 | private float endX; 36 | private float maxOffset; 37 | private bool GUIVisible; 38 | private bool showing; 39 | private bool hiding; 40 | private GUISkin ALPSSkin; 41 | 42 | //===================================================================================================== 43 | // Functions 44 | //===================================================================================================== 45 | 46 | /// 47 | /// Initializes device selection menu. 48 | /// 49 | public void Start(){ 50 | beginX = 0; 51 | endX = 0; 52 | maxOffset = -ALPSController.screenWidthPix*0.25f; 53 | GUIVisible = false; 54 | showing = false; 55 | hiding = false; 56 | ALPSSkin = Resources.Load ("ALPSSkin") as GUISkin; 57 | ALPSSkin.box.overflow.right = (int) maxOffset-1; 58 | ALPSSkin.button.overflow.right = (int) maxOffset-1; 59 | ALPSSkin.box.contentOffset = new Vector2((int) maxOffset-1,0); 60 | ALPSSkin.button.contentOffset = new Vector2((int) maxOffset-1,0); 61 | } 62 | 63 | /// 64 | /// Updates device selection menu. 65 | /// 66 | public void Update() { 67 | if(Input.touchCount > 0){ 68 | if (Input.GetTouch (0).phase == TouchPhase.Began) { 69 | beginX = Input.GetTouch (0).position.x; 70 | } else if (Input.GetTouch (0).phase == TouchPhase.Ended) { 71 | endX = Input.GetTouch (0).position.x; 72 | if (endX - beginX >= 150) { 73 | SwipeRight (); 74 | } else if (endX - beginX <= -150) { 75 | SwipeLeft (); 76 | } 77 | } 78 | } 79 | if (showing) { 80 | int deltaOffset = (int)(-maxOffset*Time.deltaTime/0.3f); 81 | ALPSSkin.box.overflow.right +=deltaOffset; 82 | ALPSSkin.button.overflow.right +=deltaOffset; 83 | ALPSSkin.box.contentOffset = new Vector2(ALPSSkin.box.contentOffset.x+deltaOffset,0); 84 | ALPSSkin.button.contentOffset = new Vector2(ALPSSkin.button.contentOffset.x+deltaOffset,0); 85 | if (ALPSSkin.box.overflow.right >= 0) { 86 | ALPSSkin.box.overflow.right = 0; 87 | ALPSSkin.button.overflow.right = 0; 88 | ALPSSkin.box.contentOffset = new Vector2(0,0); 89 | ALPSSkin.button.contentOffset = new Vector2(0,0); 90 | showing = false; 91 | } 92 | 93 | } else if (hiding) { 94 | int deltaOffset = (int)(-maxOffset*Time.deltaTime/0.3f); 95 | ALPSSkin.box.overflow.right -=deltaOffset;//+= (int) (maxOffset * cumulativeTime); 96 | ALPSSkin.button.overflow.right -=deltaOffset; 97 | ALPSSkin.box.contentOffset = new Vector2(ALPSSkin.box.contentOffset.x-deltaOffset,0); 98 | ALPSSkin.button.contentOffset = new Vector2(ALPSSkin.button.contentOffset.x-deltaOffset,0); 99 | if (ALPSSkin.box.overflow.right <= maxOffset) { 100 | ALPSSkin.box.overflow.right = (int)maxOffset-1; 101 | ALPSSkin.button.overflow.right = (int)maxOffset-1; 102 | ALPSSkin.box.contentOffset = new Vector2((int) maxOffset-1,0); 103 | ALPSSkin.button.contentOffset = new Vector2((int) maxOffset-1,0); 104 | hiding = false; 105 | GUIVisible = false; 106 | } 107 | } 108 | } 109 | 110 | /// 111 | /// Triggered when user swipes right. Shows device selection menu. 112 | /// 113 | private void SwipeRight(){ 114 | if (!GUIVisible) { 115 | GUIVisible = true; 116 | showing = true; 117 | } 118 | } 119 | 120 | /// 121 | /// Triggered when user swipes left. Hides device selection menu. 122 | /// 123 | private void SwipeLeft(){ 124 | if (GUIVisible) { 125 | hiding = true; 126 | } 127 | } 128 | 129 | /// 130 | /// Draws device selection menu. 131 | /// 132 | void OnGUI(){ 133 | if (GUIVisible) { 134 | GUI.skin = ALPSSkin; 135 | 136 | // Make a background box 137 | GUI.Box (new Rect (0, 0, ALPSController.screenWidthPix * 0.25f, ALPSController.screenHeightPix), "Choose a device"); 138 | 139 | if (GUI.Button (new Rect (0, ALPSController.screenHeightPix * 0.15f, ALPSController.screenWidthPix * 0.25f, ALPSController.screenHeightPix * 0.15f), "Default")) { 140 | controller.SetDevice (Device.DEFAULT); 141 | } 142 | 143 | if (GUI.Button (new Rect (0, ALPSController.screenHeightPix * 0.30f, ALPSController.screenWidthPix * 0.25f, ALPSController.screenHeightPix * 0.15f), "Altergaze")) { 144 | controller.SetDevice (Device.ALTERGAZE); 145 | } 146 | 147 | if (GUI.Button (new Rect (0, ALPSController.screenHeightPix * 0.45f, ALPSController.screenWidthPix * 0.25f, ALPSController.screenHeightPix * 0.15f), "Cardboard")) { 148 | controller.SetDevice (Device.CARDBOARD); 149 | } 150 | 151 | if (GUI.Button (new Rect (0, ALPSController.screenHeightPix * 0.60f, ALPSController.screenWidthPix * 0.25f, ALPSController.screenHeightPix * 0.15f), "Firefly VR")) { 152 | controller.SetDevice (Device.FIREFLY); 153 | } 154 | } 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /Scripts/ALPSGyro.cs: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | ALPSGyro is an interface for head tracking using Android native sensors 3 | 4 | Copyright (C) 2014 ALPS VR. 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | 19 | ************************************************************************/ 20 | 21 | using UnityEngine; 22 | using System; 23 | using System.Runtime.InteropServices; 24 | 25 | public class ALPSGyro : MonoBehaviour { 26 | //===================================================================================================== 27 | // Attributes 28 | //===================================================================================================== 29 | 30 | /**Private**/ 31 | private Quaternion landscapeLeft = Quaternion.Euler(90, 0, 0); 32 | private Quaternion orientation = Quaternion.identity; 33 | private float q0,q1,q2,q3; 34 | 35 | private bool gyroBool; 36 | private Gyroscope gyro; 37 | //private Quaternion rotFix; 38 | private Vector3 initial = new Vector3(90, 0, 0); 39 | 40 | //===================================================================================================== 41 | // Functions 42 | //===================================================================================================== 43 | #if UNITY_ANDROID 44 | [DllImport ("alps_native_sensor")] private static extern void get_q(ref float q0,ref float q1,ref float q2,ref float q3); 45 | [DllImport ("alps_native_sensor")] private static extern void init(); 46 | #endif 47 | 48 | /// 49 | /// Initializes ALPS native plugin. 50 | /// 51 | public void Awake(){ 52 | #if UNITY_ANDROID 53 | init(); 54 | #endif 55 | #if UNITY_WP_8_1 56 | gyroBool = SystemInfo.supportsGyroscope; 57 | Debug.Log("gyro bool = " + gyroBool.ToString()); 58 | 59 | if (gyroBool) 60 | { 61 | gyro = Input.gyro; 62 | gyro.enabled = true; 63 | 64 | //rotFix = new Quaternion(0, 0, 0.7071f, 0.7071f); 65 | } 66 | else 67 | { 68 | Debug.Log("No Gyro Support"); 69 | } 70 | #endif 71 | } 72 | 73 | /// 74 | /// Updates head orientation after all Update functions have been called. 75 | /// 76 | public void LateUpdate () 77 | { 78 | #if UNITY_ANDROID 79 | getOrientation(); 80 | transform.localRotation = landscapeLeft * orientation; 81 | #endif 82 | 83 | #if UNITY_WP_8_1 84 | if (gyroBool) 85 | { 86 | var gyroA = gyro.attitude; 87 | var rotation = gyroA.eulerAngles; 88 | rotation.z += 180; 89 | gyroA.eulerAngles = rotation; 90 | 91 | transform.eulerAngles = initial; 92 | transform.localRotation *= gyroA; 93 | } 94 | #endif 95 | } 96 | 97 | #if UNITY_ANDROID 98 | /// 99 | /// Gets orientation from ALPS native plugin. 100 | /// 101 | public void getOrientation(){ 102 | 103 | get_q (ref q0,ref q1,ref q2,ref q3); 104 | 105 | orientation.x = q1; 106 | orientation.y = -q0; 107 | orientation.z = q2; 108 | orientation.w = q3; 109 | } 110 | #endif 111 | } 112 | -------------------------------------------------------------------------------- /Scripts/ALPSNavigation.cs: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | ALPSNavigation provides an input-free navigation system 3 | 4 | Copyright (C) 2014 ALPS VR. 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | 19 | ************************************************************************/ 20 | 21 | using UnityEngine; 22 | using System.Collections; 23 | 24 | [RequireComponent (typeof (CharacterController))] 25 | [System.Serializable] 26 | public class ALPSNavigation : MonoBehaviour { 27 | 28 | //===================================================================================================== 29 | // Attributes 30 | //===================================================================================================== 31 | 32 | /**Public**/ 33 | public static float pitch; 34 | public float forwardLowerBound = 20; 35 | public float forwardUpperBound = 30; 36 | public float forwardLimit = 50; 37 | public float backwardLowerBound = 20; 38 | public float backwardUpperBound = 30; 39 | public float backwardLimit = 50; 40 | 41 | public static float ForwardLowerBound; 42 | public static float ForwardUpperBound; 43 | public static float BackwardLowerBound ; 44 | public static float BackwardUpperBound; 45 | public static float ForwardLimit; 46 | public static float BackwardLimit; 47 | 48 | public bool EnableVibration = false; 49 | 50 | /**Private**/ 51 | private CharacterController controller; 52 | private bool moving; 53 | private GameObject head; 54 | 55 | //===================================================================================================== 56 | // Functions 57 | //===================================================================================================== 58 | 59 | /// 60 | /// Initializes navigation system. 61 | /// 62 | public void Start () { 63 | ForwardLowerBound = forwardLowerBound; 64 | ForwardUpperBound = forwardUpperBound; 65 | BackwardLowerBound = 360 - backwardLowerBound; 66 | BackwardUpperBound = 360 - backwardUpperBound; 67 | ForwardLimit = forwardLimit; 68 | BackwardLimit = 360 - backwardLimit; 69 | 70 | controller = this.gameObject.GetComponent ("CharacterController") as CharacterController; 71 | this.gameObject.AddComponent (); 72 | head = GameObject.Find ("ALPSHead"); 73 | if (Application.platform == RuntimePlatform.Android) { 74 | moving = false; 75 | } 76 | } 77 | 78 | /// 79 | /// Updates navigation state. 80 | /// 81 | public void Update () { 82 | pitch = head.transform.eulerAngles.x; 83 | if (pitch >= ForwardLowerBound && pitch <= ForwardUpperBound) { 84 | 85 | if (!moving) 86 | { 87 | if (EnableVibration) 88 | { 89 | #if UNITY_ANDROID 90 | ALPSAndroid.Vibrate(20); 91 | #elif UNITY_WP_8_1 92 | ALPSWP8.Vibrate(200); 93 | #endif 94 | } 95 | 96 | moving = true; 97 | } 98 | controller.Move (new Vector3 (head.transform.forward.x, 0, head.transform.forward.z) * Time.deltaTime * 3); 99 | } else if (pitch >= BackwardUpperBound && pitch <= BackwardLowerBound) { 100 | if (!moving) 101 | { 102 | if (EnableVibration) 103 | { 104 | #if UNITY_ANDROID 105 | ALPSAndroid.Vibrate(20); 106 | #elif UNITY_WP_8_1 107 | ALPSWP8.Vibrate(200); 108 | #endif 109 | } 110 | moving = true; 111 | } 112 | controller.Move (new Vector3 (-head.transform.forward.x, 0, -head.transform.forward.z) * Time.deltaTime * 3); 113 | 114 | } else { 115 | if (moving) moving = false; 116 | } 117 | } 118 | 119 | /// 120 | /// Initialize Android ALPS Activity. 121 | /// 122 | public static float Progress(){ 123 | if (pitch >= ForwardLowerBound && pitch <= ForwardUpperBound || pitch >= BackwardUpperBound && pitch <= BackwardLowerBound) { 124 | return 1f; 125 | } else { 126 | if(pitch>=0 && pitch < ForwardLowerBound) return pitch/25f; 127 | else if(pitch<=360 && pitch > BackwardLowerBound)return (360-pitch)/25f; 128 | else if(pitch>ForwardUpperBound && pitch <= ForwardLimit)return (ForwardLimit-pitch)/25f; 129 | else if(pitch= BackwardLimit)return (pitch-BackwardLimit)/25f; 130 | else return 0f; 131 | } 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /Scripts/ALPSWP8.cs: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | ALPSWP8 is an interface with the Windows Phone system 3 | 4 | Copyright (C) 2014 ALPS VR. - Jasaon Fox, Peter Daukintis 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | 19 | ************************************************************************/ 20 | 21 | using UnityEngine; 22 | using System; 23 | 24 | public class ALPSWP8 : MonoBehaviour 25 | { 26 | /// 27 | /// Initializes Android ALPS Activity. 28 | /// 29 | public static void Init() 30 | { 31 | Screen.sleepTimeout = SleepTimeout.NeverSleep; 32 | } 33 | 34 | /// 35 | /// Vibrates constantly for 8 milliseconds. 36 | /// 37 | public static void Vibrate() 38 | { 39 | Vibrate(8); 40 | } 41 | 42 | /// 43 | /// Vibrates constantly for the specified period of time. 44 | /// 45 | /// The number of milliseconds to vibrate. 46 | public static void Vibrate(int _milliseconds) 47 | { 48 | #if NETFX_CORE 49 | var vibrationDevice = Windows.Phone.Devices.Notification.VibrationDevice.GetDefault(); 50 | vibrationDevice.Vibrate(TimeSpan.FromMilliseconds(_milliseconds)); 51 | #endif 52 | } 53 | 54 | /// 55 | /// The absolute width of the display in pixels. 56 | /// 57 | public static int WidthPixels() 58 | { 59 | return Screen.currentResolution.width; 60 | } 61 | 62 | /// 63 | /// The absolute height of the display in pixels. 64 | /// 65 | public static int HeightPixels() 66 | { 67 | return Screen.currentResolution.height; 68 | } 69 | 70 | /// 71 | /// The device orientation. 72 | /// 73 | public static Quaternion DeviceOrientation() 74 | { 75 | //switch x and y 76 | float y = 0.0f;// jc.CallStatic("getGameRotationX"); 77 | float x = 0.0f;//jc.CallStatic("getGameRotationY"); 78 | float z = 0.0f;//jc.CallStatic("getGameRotationZ"); 79 | float w = 0.0f;//jc.CallStatic("getGameRotationW"); 80 | return new Quaternion(x, -y, z, w); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /Scripts/MagnetSensor.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections.Generic; 3 | 4 | public class MagnetSensor : MonoBehaviour 5 | { 6 | public delegate void CardboardTrigger(); 7 | public static event CardboardTrigger OnCardboardTrigger; 8 | 9 | private const int WINDOW_SIZE = 40; 10 | private const int NUM_SEGMENTS = 2; 11 | private const int SEGMENT_SIZE = WINDOW_SIZE / NUM_SEGMENTS; 12 | private const int T1 = 30, T2 = 130; 13 | 14 | private List _sensorData; 15 | private float[] _offsets; 16 | 17 | void Awake() 18 | { 19 | _sensorData = new List(WINDOW_SIZE); 20 | _offsets = new float[SEGMENT_SIZE]; 21 | } 22 | 23 | void OnEnable() 24 | { 25 | _sensorData.Clear(); 26 | Input.compass.enabled = true; 27 | } 28 | 29 | void OnDisable() 30 | { 31 | Input.compass.enabled = false; 32 | } 33 | 34 | void Update () 35 | { 36 | Vector3 currentVector = Input.compass.rawVector; 37 | if(currentVector.x == 0 && currentVector.y == 0 && currentVector.z == 0) return; 38 | 39 | if(_sensorData.Count >= WINDOW_SIZE) _sensorData.RemoveAt(0); 40 | _sensorData.Add(currentVector); 41 | 42 | EvaluateModel(); 43 | } 44 | 45 | private void EvaluateModel() 46 | { 47 | if(_sensorData.Count < WINDOW_SIZE) return; 48 | 49 | float[] means = new float[2]; 50 | float[] maximums = new float[2]; 51 | float[] minimums = new float[2]; 52 | 53 | Vector3 baseline = _sensorData[_sensorData.Count - 1]; 54 | 55 | for(int i = 0; i < NUM_SEGMENTS; i++) 56 | { 57 | int segmentStart = 20 * i; 58 | _offsets = ComputeOffsets(segmentStart, baseline); 59 | 60 | means[i] = ComputeMean(_offsets); 61 | maximums[i] = ComputeMaximum(_offsets); 62 | minimums[i] = ComputeMinimum(_offsets); 63 | } 64 | 65 | float min1 = minimums[0]; 66 | float max2 = maximums[1]; 67 | 68 | if(min1 < T1 && max2 > T2) 69 | { 70 | _sensorData.Clear(); 71 | OnCardboardTrigger(); 72 | } 73 | } 74 | 75 | private float[] ComputeOffsets(int start, Vector3 baseline) 76 | { 77 | for(int i = 0; i < SEGMENT_SIZE; i++) 78 | { 79 | Vector3 point = _sensorData[start + i]; 80 | Vector3 o = new Vector3(point.x - baseline.x, point.y - baseline.y, point.z - baseline.z); 81 | _offsets[i] = o.magnitude; 82 | } 83 | 84 | return _offsets; 85 | } 86 | 87 | private float ComputeMean(float[] offsets) 88 | { 89 | float sum = 0; 90 | foreach(float o in offsets) 91 | { 92 | sum += o; 93 | } 94 | return sum / offsets.Length; 95 | } 96 | 97 | private float ComputeMaximum(float[] offsets) 98 | { 99 | float max = float.MinValue; 100 | foreach(float o in offsets) 101 | { 102 | max = Mathf.Max(o, max); 103 | } 104 | return max; 105 | } 106 | 107 | private float ComputeMinimum(float[] offsets) 108 | { 109 | float min = float.MaxValue; 110 | foreach(float o in offsets) 111 | { 112 | min = Mathf.Min(o, min); 113 | } 114 | return min; 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /Shaders/ALPSDistortion.shader: -------------------------------------------------------------------------------- 1 | Shader "Custom/ALPSDistortion" { 2 | Properties 3 | { 4 | _MainTex ("Base (RGB)", 2D) = "white" {} 5 | } 6 | Subshader 7 | { 8 | Pass 9 | { 10 | ZTest Always Cull Off ZWrite Off 11 | Fog { Mode off } 12 | 13 | CGPROGRAM 14 | #pragma vertex vert 15 | #pragma fragment frag 16 | #include "UnityCG.cginc" 17 | sampler2D _MainTex; 18 | float2 _SHIFT; 19 | float2 _CONVERGE; 20 | float2 _SCALE; 21 | 22 | struct appdata { 23 | float4 pos : POSITION; 24 | float2 uv : TEXCOORD0; 25 | }; 26 | 27 | struct v2f { 28 | float4 pos : SV_POSITION; 29 | float2 uv : TEXCOORD0; 30 | }; 31 | 32 | v2f vert (appdata v) { 33 | v2f o; 34 | o.pos = v.pos ; 35 | o.uv.x = (v.uv.x * 0.5f)+_SHIFT; 36 | o.uv.y = (v.uv.y); 37 | return o; 38 | } 39 | 40 | 41 | uniform float _AberrationOffset; 42 | uniform float4 _Center; 43 | uniform float _ChromaticConstant; 44 | 45 | float4 frag(v2f i):COLOR{ 46 | 47 | float2 coords = i.uv.xy; 48 | 49 | _AberrationOffset /= 300.0f; 50 | _ChromaticConstant /= 300.0f; 51 | float radius = (coords.x - _Center.x)*(coords.x - _Center.x) + (coords.y - _Center.y)*(coords.y - _Center.y); 52 | 53 | float radialOffsetX = (step(0, coords.x - _Center.x) * 2 - 1) * _ChromaticConstant + (coords.x - _Center.x) * _AberrationOffset; 54 | float radialOffsetY = (step(0, coords.y - _Center.y) * 2 - 1) * _ChromaticConstant + (coords.y - _Center.y) * _AberrationOffset; 55 | 56 | float4 red = tex2D(_MainTex , float2(coords.x + radialOffsetX, coords.y + radialOffsetY)); 57 | //Green Channel 58 | float4 green = tex2D(_MainTex, coords.xy ); 59 | //Blue Channel 60 | float4 blue = tex2D(_MainTex, float2(coords.x - radialOffsetX, coords.y - radialOffsetY)); 61 | 62 | //final color 63 | float4 finalColor = float4(red.r, green.g, blue.b, 1.0f); 64 | return finalColor; 65 | } 66 | 67 | ENDCG 68 | 69 | } 70 | } 71 | 72 | Fallback off 73 | } 74 | --------------------------------------------------------------------------------