12/31/13

Touch Events in Unity3D

I’ve been working on Crazy Bugz for the past few days to take advantage of the 2D physics and sprites brought in by the latest version of Unity3D. Many things have been updated which reserves a post all by itself. For now, I want to discuss a discovery I made regarding the touch events. I’m not sure if this is iOS or Unity3D specific but I’ve built a work around that seems to be working for now 😀

For a demonstration, here’s a Unity3D package (requires 4.3). Build and test it on touch devices. I’ve only tested it for iOS devices. You can test it with Unity Remote but it has limitations like touch responsiveness which is critical for this demonstration.

TouchDemo
TouchDemo
TouchDemo.unitypackage
14.3 KiB
1929 Downloads
Details

First and foremost, I made a generic event handler for the different touch phases in TouchMonoBehavior.cs

The OnTouch* event handlers are all declared public virtual void and passes the Touch parameter. Meaning, each event handler could be called multiple times per Update() depending on how many touches there are (Input.touchCount). We can treat each touch separately by taking note of the finger id that comes with the touch.

All the while, I thought the touch phases have the following state diagram

Touch Phases State Diagram

Unfortunately, upon testing over and over again, it is POSSIBLE to start with Moved or Ended! I haven’t noticed if it could start with Stationary since I don’t use it for my projects at the moment. But my point here is that the Began phase CAN BE SKIPPED! I’m not sure if this is intentional but it’s happening and it got me pulling my hair for the past couple of days.

I’m using an object pool in my project where the objects react to touch. When the user touches, an object is created, let’s call that Object 0. When the user touches again, another object is created called Object 1. If Object 0 gets disabled (as part of the game mechanic) and the user touches again, Object 0 will be re-intialized and treated as something new. Objects don’t get destroyed, rather, they become disabled. This is basically how object pooling works.

Theoretically, every time a Began phase is encountered, a mirror is re-initialized in Crazy Bugz. The user can rotate or stretch this mirror by moving their finger which corresponds to the Moved phase. When the user releases their finger, an Ended phase is encountered and that mirror remains enabled until it gets disabled (shattered) by the laser. However, there are certain occasions where I touch and get a NullExceptionError. It turns out, my game is trying to look for a mirror with a specified finger id that was not created. This means, the Began phase was skipped!

As a work around, if in case the Began phase has been skipped and goes directly to Moved phase, I would treat that as a Began phase. In the case the Began phase has been skipped and goes directly to Ended, I would simply ignore it.

Not exactly the best solution but this will have to do.

The ideal case? Well, Began phase shouldn’t be skipped… ever 🙂

11/23/13

ScreenChamp Awards 2013

I recently joined the ScreenChamp Awards 2013, a contest on screen casting sponsored by TechSmith.

I’m testing my video lecture making powers and see if I can grab that People’s Choice award. I’m very happy to have been selected as a finalist! I still consider myself new to screen casting and video lecture making.

I actually submitted two videos. The first one, Lecture on Structs and Pointers in C++, did not make the finals but the second one did.  As for the topic, well, it’s about… Love 😀 Ahaha! Yes I know, the SSB (single-since-birth) programmer talks about love. Now before you think about romance, I want to clarify that my talk is about the 5 Love Languages written by… you know what… go watch the video here. Don’t forget to up vote and share it 😀

I originally wanted to give my whole 1-hour talk about the 5 Love Languages into this video lecture but I had little time to complete it. Sadly, I had to settle with just the Introduction, which is a teaser to give my audience reasons to stay and listen. I can actually give this talk without the need for normal presentation equipment like projectors and laptops. In fact, I have given this talk multiple times to some of my former students or friends over dinner at home, during lunch in the mall, and in the living area during sleepovers.

The challenge in making this video was that I had to make it interesting without knowing who I am. I think the reason why people listen to my talks is because they know me. But what if I gave this talk to complete strangers, people I’ve never conversed with before, how would they react? Also, since I’m targeting older teens, I need to make it appealing other than just showing myself. Thus, I decided to make use of drawings and hand writings. I enlisted the help of a former student who is great with art, Quina Baterna. I told her my concept and she gave me drawings of the wife, husband, logos for each love language, etc. We  recorded her, drawing these icons on a white board using colored pens.

Quina's-Drawings

Quina’s Drawings

Unfortunately, I encountered problems when I started editing the videos. It turns out, I need a LOT more art to convey my interpretations. I’m no artist, hence, I searched for free vector art online. I found some but I lacked a lot more. Being pressed for time, I resorted to the unthinkable – draw them myself. Yes, that’s right. I drew. I couldn’t create a video of me drawing since I make so many mistakes and it takes me forever to make one. Instead, I used Inkscape to create my black and white, stick figures.

I tried combining Quina’s drawings with the vector art but they don’t seem to work out well. I made a decision to redraw all of Quina’s art using Inkscape. Using this technique prevented me from presenting the art being drawn on screen. Instead, I had the drawings animated by flying them in, scaling them, translating them, and changing their opacity.

Vector-Art

My Vector Drawings

It took me a while to complete the video but I made it a couple of hours before the deadline. My friends commented that the video is such a cliff hanger or bitin. I will continue the video and include my whole talk which includes what the 5 Love Languages are and how to find out yours as well as other people’s Primary Love Language. For now, up vote my video and help me win 😀

Again, the video can be found here!

CREDITS to the following:

Free Vector Icons from http://www.endlessicons.com and http://www.clipartsfree.net

“Easy Lemon”, “Deliberate Thought” Kevin MacLeod (incompetech.com)
Licensed under Creative Commons: By Attribution 3.0
http://creativecommons.org/licenses/b…

DISCLAIMER:
I am not nor am I related to Dr Gary Chapman, Northfield Publishing or Moody Publishers.

Camtasia and SnagIt from TechSmith

10/3/13

No Projector? No Problem! Part 2

Yesterday, I started teaching using VNC to share my screen to my students. Unfortunately, I still had to draw on the whiteboard to emphasise on some points of the lecture. I used the whiteboard yesterday but today is different.

Successfully demonstrating code and lecture slides through their screens, I extended my tools by adding SmoothDraw – a free drawing tool that works very well with tablets. SmoothDraw is the recommended software by KhanAcademy in Windows. For Mac, you have the free Autodesk Sketchbook Express. Both of which were designed for tablets and drawing.

With my students viewing my screen, I put Notepad++ on the right side with SmoothDraw on the left and started drawing doubly linked lists while showing the code. On their computers, they were able to follow while they try to type the code themselves. I think my experiment was successful.

Aside from this, the students were exposed to tablets. I brought my Wacom Bamboo Pen & Touch to school. The normally noisy kids were curious and wanted to draw using the tablet. The first thing that they wrote was their name or signature. How vain 🙂

I think this also gives me the opportunity to be more comfortable with tablets so I can perhaps improve my “drawing” skills. Haha! What a joke!

10/3/13

No Projector? No Problem!

It’s been quite a long time since we’ve had a dedicated working projector for the Viper Lab (classroom where I’m teaching). We’ve already asked for additional projectors but due to the high demand, it cannot be met. We’ve resorted to asking the community through the foundation at AghamRoad.ph. Unfortunately, it’s moving slowly despite being shared in Facebook more than a handful of times already.

I’m teaching Data Structures and Algorithms and go in-depth even to the memory level and pointers when I discuss. I use a lot of code and diagrams to show my point. Unfortunately, it gets tiring to keep on writing board-full of diagrams every meeting. This is where the advantage of the online lecture slides and video lectures come in. However, even with lecture slides, if you don’t have a projector, it’s not as easy to transfer the concepts. The video lectures are meant to supplement the lectures in class for those people who want a repeat of the lecture. They weren’t designed to be the primary method for teaching.

Being desperate, I turned to a familiar technology that I’ve encountered in my previous work. It’s time to work with VNC again. VNC, Virtual Network Computing, is a network protocol for screen sharing or remote desktop. With it, you can control another computer. For my class, I didn’t need full control. I just needed a way to project my screen unto theirs. Also, since we’re low in budget, I was looking for a free portable VNC Server and Client (Viewer). Last time I checked, RealVNC had a price tag and it still has for the server but the client is free. Luckily, I found the free Ultra VNC.

Yesterday, I configured my Windows 7 on my MacBook Pro to run Ultra VNC server. I asked my students to download the RealVNC viewer from my computer (since I have apache running as well). Since we’re all using portable versions, no installation was necessary. They simply unzipped and ran the executable and connected to my laptop via VNC. At first, it wasn’t working right and the clients are all getting blank screens. I closed my VNC server multiple times and it didn’t seem to fix it. I went to the task manager to see a few lingering VNC processes running. Manually ending these instances, I ran the server again and asked everyone to connect. When I heard a few people gasp in amazement, I knew it was working.

“This is cool!”, “How did you do this?”, “It’s amazing”, “Sir, can you see my screen as well?” were the responses of the students. I told them to scale to fit their windows since my screen resolution is quite high and they only see almost half of the screen. With this at hand, I continued my lectures on Linked Lists. I can show them the lecture slide then switch to Notepad++ and Cygwin to demonstrate. I checked my students’ screens from time to time and I noticed that the mouse doesn’t show. I had to keep on highlighting texts in order for them to follow me while I talk.

However, since the lecture was about linked lists, I still needed to draw. The students were cheering “Sir, use Paint!” And I refused to give in to their demands and decided to still use the traditional method of writing on the board – which leads me to another experiment for tomorrow. Since I need to draw diagrams (lots of it), I will bring my tablet tomorrow and see if I could draw everything on screen (using SmoothDraw). Aside from that, I’ll try to record my screen using CamStudio.

Despite all these attempts, the whiteboard is still necessary since the wide space will allow me to write a ton of information and the students can easily go back by looking at the previous writings.

09/6/13

C++ Pointers + Structs

Finally done with another video lecture! This is a continuation of the previous video on Pointers and Arrays in C++. This video focuses on Pointers, Structs and Arrays in C++.

I’m still experimenting on which video lecture style is most appropriate – formal vs informal, live (hand drawn with markers) vs digital (screen recorded) – for computer programming. People might be thinking that digital is the only way to go but I believe there are certain topics that need to be discussed by hand first such as pointers.

iPad as DocuCam

My set up to record this video is shown in the picture. I was looking for a cheap, DIY docucam (document camera) and this is what I came up with. I originally looked for a 2-foot single tier wire rack but I couldn’t find one that fits. I searched around Wilcon Home Depot and arrived at the kitchen area where I got that thing. I don’t know what you call it but it was flat, elevated and had gaps for the camera to see through. I got 2 velcro straps to fasten the iPad to the kitchen thing.

It turns out, there’s a huge focal point discrepancy between the photo and video mode of the iPad 3. The video mode seemed to be zoomed in as compared to the photo mode. Meaning, I had to make my docucam higher to cover more area. I estimated that I needed around 2 feet to get it to the right height. I used my idle PS3 games and audio CDs as pedestals as shown. Despite the achieved height, half of the screen was still covered by my hand but it served the purpose. Later on, I further increased the height by replacing my makeshift pedestals with the boxes of The Book of Sith and The Jedi Path 🙂 They still served me well.

For the writing materials, I bought the whiteboard and eraser from National Book Store. The colored markers came from the president of my Advisory class, Maia Leyretana, when she came back from Korea.

I made the lecture somewhat formal, with most of the bloopers cut out or redone but there was still a fluke in one of the slides and I left it there. I recorded my voice using a Zoom H1 and edited the video using Camtasia for Mac.

Taking in the comments from my last video lecture, I targeted a max of 10 mins and had a short introduction to indicate what I’m expecting from the viewers such as prior knowledge. The original lecture that I used in class was good for 45 minutes. Cutting out the interaction and mistakes, I was able to compress it to 9:58 but I think the flow is terribly fast.

Nonetheless, I believe the video is still educational. Feel free to comment below on what I need to improve on. Thanks in advance!

You can check out the video here.

08/29/13

C++ Pointers + Arrays

Finally got to upload the video lecture on C++ Pointers + Arrays. But honestly, I think it’s boring. I still need to practice making video lectures. This is like the 3rd one that I made but I’m still not getting the hang of it.

The more I make it formal, the less interesting it becomes. If I make it casual, it tends to be lengthy.

Aside from the entertainment factor, I found it difficult to draw on Adobe Photoshop. I tried to look for drawing tools that automatically smoothen out your pencil drawings but I couldn’t find one. My best bet was Autodesk Sketchbook Express for Mac which is free to download from the Mac App Store and iTunes. It has a different user experience which was clearly intended to be keyboard-free. All the controls and settings can be done from the widgets of the user interface. Pretty interesting approach there and fun to play with. Though I need more practice writing and drawing with the tablet.

As for screen recording, I’m using the best one out there and it’s TechSmith Camtasia for Mac which can be found here. What I’m using is the full version because the beta testing, which lasted for more than half a year, has ended and I got my free copy 😀

Nonetheless, the video can be found here. Feel free to comment but please be merciful.

I’ll try to make another one. Though I’m also exploring different methods aside from digital video lectures.

Edit: Oh look here! Autodesk is looking for beta testers for Sketchbook Pro!

08/25/13

Facebook Comments

That turned out easier than I expected…

I’m now using Facebook comments for this blog rather than the built-in comment system of WordPress. I followed the instructions here and it worked like a charm. I didn’t know making a Facebook App was that simple too. Amazing.

Thank goodness for nerds like Fat Panda.

07/16/13

First Long Test of Batch 2014

I can’t believe I have barely touched my blog for more than a year. Wow! Maybe it’s because I didn’t have star wars bonus questions anymore. But nonetheless, it’s back 😀

The first LT of CS4 SY 2013-2014 had 4 bonus questions all related to Star Wars Episode I. The questions were

1) Who was Darth Vader’s mother?
2) What did Yoda sense in Anakin when he was presented to the Jedi Council?
3) Which planet did Qui-Gon die in?
4) What does TPM stand for?

The correct answers are Shmi, fear, Naboo and The Phantom Menace. There were a couple of funny answers for (1), namely, Darth Mother and Mrs Vader. But the 4th question had really crazy answers. And here’s the list…

The Potato Man
The Potato Master
The Planet Master
Triple Pulse Magnet
The Planet Mars
Technological Programming Machine
The Perfect Me
Total Prime Midichlorians
The Pancake Monster
T Planetary Movement
The Prime Minister
Teleportation Malfunction (where is the ‘P’?)
Toilet Paper Management
True Patrol Master
Tingling Potty Mouth
The Product Multiplier
Trigger Powered Machinegun
The Protection Machine
To Pass Math
Treasure Planet Map
Total Programming Mess
Transport Pair Mechanism
Twin Propulsion (Where is the ‘M’?)
The Post Menstruation

Haha! The last one was totally unexpected. I can’t wait for the next exam. 😀

03/12/11

And this school year ends…

Batch 2013, I will miss you. And I’m sure you won’t miss the Star Wars bonus questions in Comp Sci long tests. Speaking of which, the last long test for the school year had the following questions:

1) What does AT-AT stand for?
2) What does TIE stand for?
3) Which side does the X-wing belong to?
4) Who created Star Wars?

The correct answers are: All Terrain – Armored Transport, Twin Ion Engine, The Rebellion or Rebel Alliance and George Lucas.

Many people got George Lucas and many thought that the choices for 3 is light or dark side. It’s supposed to be a choice between the Galatic Empire or the Rebel Alliance. As for the first two questions, here are their answers:

ATAT = nagmamadali?
Above Thinking – Annexing Toilet
A trip at Tartakovsky
Aspired to attack troops
Anakin Tywalker – Anakin Tywalker
Android Technology
A truck, a truck
Ang tae – ay tae
Arguing the Affinity of Terabytes
Atat na Atat
A Totally – Awesome Toy
Anti Tank – Aerial Trooper
Asdfghjkl Test – Asdfghjkl Test
Another test – about toucans
All Terrain – Attack Transport
Eager (example: si JM ay atat ng kumain)
All the awesome things
At the – Asian Tower
AsTeroid – AsTeroid

The Immortal Enemy
Thinking in End
The Internation Embassy
The Internet Explorer
Talking Indian Emperor
The Intelligent Emperor
Totally Inverted Eyes
To Interlace Everything
Tae Invading Earth
Technological Improvement Era
The Inexplanable Explanation
Troop Interceptor Engager
Test is Ergghhh
The Imperial Emperor
The Industrial Evolution
The Intelligent Exorcism
(Duh!) Draw!
Tactical International Electronics, Ltd
The Integrated Entropy
The Indeed End
The Intergalactic Enforcers
The Imperial Emperor

Hehe… Haaay, no more crazy bonus questions with weird answers from teenagers for the next two months…