Sunday, 29 May 2011

Week 12 - More second Life

Introduction

After the first lesson on second life which was a really interesting lesson we continued on more second life in much more detail. This week we spoke about building primes and also introduced LSL which stands for Linden Scripting Language, this type of scripting adds behavior to Second Life objects.

Right Click on the screen and select Build
During the lesson, we all went to Fermi Sandbox as a group. We walked as a group to a free space on the grass there we could notice that we attracted avatars to us since we were a large group avatars where probably finding it interesting. We continued getting comfortable with controls, gestures and teleporting after a while we started building objects. To build object you right click on the screen and select build. At this function a dialog box will pop up. On the right is the tools you need to build primes. On the top you select from, focus, move, edit,create and land. In the focus tab you can focus on where you want to create objects you can zoom in and out, orbit and pan. In the move tab you can grab the object and move it up and down spin it and also move it. Next is the edit tab in this section one can edit the object by stretching it, moving or rotating the object you can also give the object different colour. In the below screenshot I was experimenting with a shape and gave it a purple colour. You can either colour and stretch both sides or else only one side. 

Next tab is the create section here you can create several different shapes square, prism, pyramid, cylinder ring, tube, tree and grass. The trees and grass cannot be build everywhere. These two have to be created on land that you own.
The last tab is the land tab here you can do some transformation of the land first you select the area of the land that you want to transform then you can flatten it, raise it, smooth it, roughen it and then revert it. Then you have the bulldozer which will bulldoze any select area.
In the built panel there is also some other tabs which are;

  • General - In this section there one creator gives a description about the object being created like; giving it a name, description, who created it and also who can modify this object.
  • Object - The object section is from where you can change the dimensions of the object, you can also change the shape. 
  • Texture - The texture section is where you can give the shape different colours and textures set the transparency and glow
  • Content - The content is the section where you can add the LSL scripting. 
Creating Object
I started experimenting a bit first by building some shapes. I built a ring and edited and gave it some colours. First I started by creating the shape in the above case I used the ring. Then I went in object section and changed its dimensions, then I went to the textures section and changed its colours using the select a face so each face could be given a different colour which are purple and dark pink on the top.

LSL
After creating a shape I started by getting the hang of some LSL scripts. LSL is based on Java and C. A script in Second Life can be placed on an object but won't work on an avatar however these can be worn by avatars. To write LSL scripts one can find a built-in editor in the build panel under the content section. LSL has "States" and "Events". States are behaviours some examples are having a door which can open and close or a bulb which can light up or switch off. In a script there is at least a minimum of one script which is the default one. Events are predefined rather than being user defined. These can be caused in two ways either by objects and avatars interacting in the world or else they are created in a script. An example of an event is when an avatar touches an object  causes an event which is the touch_start ().

Below is a default script

1.  default
2.    {
3.       state_entry()
4.      {
5.           llSay(0, "Hello, Avatar!");
6.      }
7.      touch_start(integer total_number)
9.      {
10.        llSay(0, "Touched.");
11.    }
12.   }

The above code shows one state which is line 1. A state is defined by the word state followed by its name except for the default state and having the contents in 2 curly brackets  example: state running{}. Events are between the curly brackets of the state. When a state is active, events in that state are waiting to be triggered. Events are found on lines 3 and 7.  "state_entry" is triggered by the state being entered and "touch_start" when anyone touches the object.

More LSL


While working with SL
Next I tried getting on with some basic LSL. I created a new object a sphere. This script will change the objects colour when the avatar touches it. It has two states the default state and state off and has four events. The ball will be off a certain colour and when the avatar will touch it it will change colour. llSay will be display some text  on your screen. llSetColor will set the colour for the object. ALL_SIDES with a -1 value which will affect all sides of the prim.

1. default
2.   {
3.    state_entry()  
4.   {
5.       llSay(0,"Hello, Avatar");
6.       llSay(0, "Object is turning on!");
7.       llSetColor(<1.0, 1.0, 1.0>, ALL_SIDES);
8.    }
9.     touch_start(integer total_number)
10.    {
11.       state off;
12.    }
13.   }
14.   state off
15.   {
16.    state_entry()
17.    {
18.      llSay(0, "turning off!");
19.      llSetColor(<2.0, 1.0, 0.0>, ALL_SIDES);
20.    }
21.     touch_start(integer total_number)
22.     {
23.       state default;
24.    }
25. }

ScreenShots of End Results




Moving an object. 
To move an object this is done with the use of coordinates. Usually we use x and y coordinates but since this is a 3D world there is also z coordinate. To move an object you need to use vectors. An object can be moved by stating the position to where you want to move it using llSetPos(<x,y,z>).To move the object north use a positive value while to move an object south use a negative value.

DeckChair.

I tried building some sort of deckchair and having the avatar to relax on it. To sit on this prime I used llSetSitText("Relax"); However till now this was not of success. I wanted the avatar to "lie down" as if he was really on a deckchair. The coordinates I was giving the script are the problem, as when I tried experimenting with them the avatar set far away on it. At the moment the avatar isn't lying down on the deckchair instead it is in a sitting position which has to be changed.  
Conclusion
Second Life keeps getting more and more interesting, during class hours we also took a snapshot of our group where we all went to middlesex in SL and sat around a fountain. After this blog we can see that scripts can be added to most primes in SL. I also think that when I used other languages I think I found more help, probably because this isn't used by the same number that other languages are being used. However as other languages to get to comfortable with it all it needs is practice. 






References:
http://wiki.secondlife.com/wiki/Help:Getting_started_with_LSL

Friday, 20 May 2011

Week 11 - Term 2 Introduction to Second Life

Introduction
This coursework is divided into two terms, first term was what we covered so far and second term is all about Second Life. Second Life is a virtual 3D world and this is created by the people who use it. In this virtual world you can fly and run and travel around the world in a few minutes. In Second life one has avatars and primes. An avatar is your character which you can create according to your likings to do whatever you want him to do. In second life you can build your own things. These objects are called primes, short for primitives. Everything is build out of cubes then you can turn these cubes into different shapes like triangles, circles and more. These shapes can be giving any texture and also you can sculpt them into anything you want to create any shape. Once you have the primes you can make them communicate between other objects by getting some sample codes. A sim is an area on the map based on a simulator, this area can contain a number of prims on it. Second life is being criticized for some things like there are few people which are in it another thing is that one needs very good internet connection.

History
Second life was founded by Linden Lab by Philip Rosedale, in 1994 he taught of connecting computers via internet and create a virtual world. Linden Lab was founded in 1999 which started as a hardware company. This company needed something to go with their hardware so in 2001 they started building the Linden World and this was very much different then the Second Life we know today. They continued working through out the years and in 2011  the new Second Life Community Platform was launched and on the 29th March they also introduced a new function being the modes which the user can use Basic mode and advanced mode


For this term we won't be given any tasks one must complete, instead we will talk about what we have done. First off I started by downloading second life viewer from http://secondlife.com/support/downloads/. It's installation was pretty much straight forward and easy. After installation you register with second life. When registering you add the username that you will be using and select a password.  When loging in you can select a mode basic mode and advanced mode. The basic mode is an easier and simplified experience. While advanced mode is a bit more complicated and for those who will use the full features of Second Life Viewer.
I started of by creating my avatar, you select the gender of your avatar and also choose an outfit of your likings. If later on you would  want to change the avatars outfit you can, you can also change it's username, the only thing that cannot be changed is the name.Once you are done then you can jump into the world of Second Life. When you go to Second Life for the first time you are placed in a specific place. In here you find only first time users
Taking my avatar to Middlesex campus
Moving Controls
Once I jumped to that world I started by experimenting with the things your avatar can do. Your avatar can move to move you can either click the move button on the screen and you will be shown the controls or else using the arrow keys on the keyboard. At first I taught that clicking the on screen controls is going to be a bit frustrating as I taught the for each click it would make a step but then I noticed that you click once and keep it pressed on the controls and while the forward button is clicked you roll over the other controls to rotate or change direction. In this panel you can also choose to run or fly.
Flying using Pg Up


Your avatar can also do certain gesture. A gesture is telling you avatar to do something without moving to different places. Gestures can include clapping, bowing, crying and more. I noticed that in the gestures drop down menu each gesture starts with a slash. This is because a short-cut for using gestures would be typing the gesture you want to do in the chat and including the slash before it. On the interface you have a view button this will change the way to view. You can zoom in and zoom out and rotate.

Teleporting is going from one location to another destination. This is done either by using the search or using the world map. First place I teleported to was the Middlesex Campus. Although to my disappointment there was barley anyone there. Here one can find loads of posters and some classrooms and also a hall.  

Your avatar can also go to shops and buy whatever things you want to buy. Clothes for your avatar and different things. 

Conclusion
After several lessons we are to be able to build a room which has a garage and as soon as you approach it, it will automatically open and close. I never used Second Life and never heard of it. At first I couldn't understand why we were learning it cause for me it looked like a "game" but then when I started researching deeper and unserstanding it concept I realized that one will use coding in this and will make things move and communicate with others. Also it might be that in the future Second Life will take over chatting with MSN and Yahoo and this can be the future of chatting or it can be enhanced more and take over facebook. It could imitate the users movement and the avatar will be able to do them on screen. Since technology is evolving fast everything is possible. I see great potential in Second Life and think that teenagers would really enjoy it as I enjoyed it myself.  Although this is a good thing I do find a disadvantage to it, even nowadays kids forgot how to have fun and play because they are always stuck with their screens playing games. The question is, If second life is enhanced  will this make it worst? 

References: 
             http://secondlife.com/

Thursday, 5 May 2011

Week 10 - CourseWork 2

Introduction
After the first coursework which was the animation of the moving man we started looking at the server side and went into PHP. This coursework had to be done mainly with the use of PHP. 

What to do?
We were asked to write a remote Web Space management system and the user is to be able to add and organise files to this area. This area is to be secured with a password. The theme of this management space was to be of anything we wanted. 

Features: 

(1)  Your program should be written as PHP scripts . The user should be able to work with this program via a Web browser from any computer connected to the Internet.

(2)  When your program starts, it should ask the user to enter a password and username, and not allow the user to access their Web space unless they know the password. Passwords should be stored in an appropriate MySQL database.
(3) Once allowed access the user should be able to:
  • Make and delete directories
  • Delete Files
  • Upload new files
  • Only be able to access their own space, which should have space limits imposed upon it.
Implementation:
First of I started by deciding what theme I want to use. Since this is a school coursework I taught of something that has to do with school. Therefore the theme I choose is having a school website which offers advanced courses to students and their students have to submit their homework and tests online. Three directories will be used; homework, tests and results. In the homework folder they can each upload their homework in that folder. Tests are uploaded in the tests folder and then they can download their test results from the tests folder.

I continued by designing the layout of this site. A simple image was created where it had different sections; courses, submit homework, register and contact us. This time in my work in HTML I introduced hotspots. Hotspots are, when you have one image divided into regions (hotspots). When this region is clicked an action can occur, like taking you to another page. This is done by first giving the image a usemap=" "; attribute, this will be like an id to show the image which map to use in case you have more than one. Then you select the shape of the hotspot and mark its coordinates and put the link to where you want the users to go when they click on it.
 Example: <area shape="rect" coords="55,464,140,496" href="courses.php" alt="courses" />
I added CSS to give the page more style and linked each page with the CSS style sheet page.
Index Page


After defining all the pages I started off by building the login. A database was created where the usernames and passwords are stored. 

This database was created for the login, if one of these users login using these following username and password they will login successfully, if however they miss type there details or someone else will try and login with fake details, they won't be logged in.

After that I kicked off with the login. I created a form with two fields username and password and login and reset buttons added some CSS to give it some style. The login button will go to a page which has the validation process while the reset button will clear the details from the fields. I then started creating the page which validates the username and password. I started by connecting the database. 


The above screenshot shows the code to the connection, $host, $username, $password and $db_name are variables I created to use them. It's better to declare the variable then using the real values throughout the pages, because if you decide to change them, then you would have to change the whole thing throughout the code and like this you just change the values of the variables.


Next I researched how to protect the script from SQL injection. SQL injection is when someone inserts an SQL statement on your database without your permission. This usually happens when a user is asked to input their details and instead of a name they give you a MYSQ statement that you won't know about. I researched for code that will protect the work against MYSQL injection and used it in my SQL and fixed it to suit my code.

Then the table from which the usernames and passwords are validated is passed. This was done using the SELECT*FROM statement. 

Next if the logging is validate, the user will be directed to another page which is the space management, while if the login fails he will be shown an error message and he will have a try again link which will direct the user the the login part again.

Logged in

Login Failure
Next when the user manages to login he needs to select a directory so that one can upload the file he wants into the directory he wants to choose. To do so first I created a folder named uploads and created 3 different folders in it; homework, tests and results. Each folder will have its specific use. After that I did the php code. To list a directory one needs to use the readdir()function. This function reads the entry from the directory. First it opens the current directory by giving it the correct path. Then an array was defined to hold the files. Then a loop will loop through all the files and it will store the filename and close the directory using the closedir() function. After that a foreach loop was done and in it there is the echo which will display the select option for each file. With this function the user is able to select his folder in which he wants to upload his work.
After this, the user needs to upload the file. The user will first browse his computer to select the file that he would want to upload and then he uploads the file. Then if the file is uploaded successfully the user will be directed to another page where he will be shown the file details; file name and file type and then he will informed that his file has been uploaded successfully. If the file won't be uploaded successful the user will be shown an error message and he will be have a go back link.

In this page I encountered a lot of problems and had a lot of trouble, it was not finding the path and had some undefined indexes errors. Regarding the path I tested it by first trying to direct the path to somewhere else, I used My Documents as a testing path and this worked perfectly. Then I learnt that in PHP one has to use \\ slash instead of single slashed. After that I had to add the file that the user would have chosen by adding .$_POST['fileFolders']."\\". Another problem I found was to show the size of the file. For some reason it didn't work and couldn't find a way to solve it.

Uploaded
Error in Uploading

View Files 
The user then has the ability to view the files that there is found in the directory. This was done by using the opendir() function.  First the path was specified of which folder you want to view, then an if statement was used to open the given directory  and proceed to read its contents. This works by the user clicking the view files button and if this works the user will be directed to view the files in the directory. Then to go back to the management system he uses a link to go back. In this part I also encountered a problem which also was a path problem because of the single slash. When I changed it into double slashes it worked.

View Files
Delete Files
Another function which was required to do was the delete function. My idea of this was making a check box near each file found in the directory and when the user would want to delete any file the user will check the box to delete the folder. I tried doing this using the unlink()function. Also since one users can create directories one users have to have the ability to delete them this is to be done using rmdir()function. This biggest problem in this was to make the check-boxes synchronize  Unfortunately this function did not work as I taught it would. 

Space Limit
Also we had to create space limits so that they won't exceed their space limit. This can be done using the getDirectorySize()function. My aim for this function was, letting the user uploads and when he exceeds his limit the user would be informed and won't be able to upload any more files. Also this function did not work. 

Mobile
This site was also required to work from a mobile. This was done by typing in my IP address in the URL of the browser on the mobile. It did work good, it uploaded and one could view it but the problem was that it didn't fit perfectly on the screen since it is a small screen one would need to do a lot of scrolling. But this could be fixed by instead of giving the width a fixed size using pixels, percentages are used so that they size would fit on every type of screen size.
Conclusion
Improvements
As improvements it could have come a bit better, since not everything works I would start by trying and making those functions working, fixing errors for exceeding size limits, deleting files and also deleting folders. Also I have a registry form and a forgot your password function. Also these can be as an improvement. I did some research regarding these two pages though they look like they require advanced PHP and the registry form also needs some  PHP. 


Conclusion
Although I didn't manage to get this project working as the required requirements I am still happy by how far I've gone mostly because I have never coded PHP before. I will continue working and improving this project and blog about my improvements as it was a really interesting work and also will definitely come in handy in the future. I tried giving much detail as possible though this blog was done in a few time since bloggert had some problems and my previous post got deleted and had to do it all again!. I think PHP is a really interactive language and provides a lot of interactive parts with the users. It isn't such a hard language to code.  I will keep on working with PHP as practice makes perfect. 

References:
             http://www.tizag.com/mysqlTutorial/mysql-php-sql-injection.php
             http://www.w3schools.com/PHP/php_file_upload.asp
             http://php.net/manual/en/function.opendir.php