Friday, August 23, 2013

Blender 3d Gamekit Touch Move Android Tutorial


Following last tutorial, background moving, as moving direction is wrong, we need to fix it first.
1. Rotate camera and change motion direction in game logic editor.
2. Adjust plane shape.
3. Cut seam line on the plane model. And generate uv map.
4. Export uv map as image file.
5. Open uv map in gimp2 to paint the texture.
6. Save image and load into Blender
7. Apply texture to plane. And verify in 3d view.
8. Creat txt file. Name it OnInit.lua and put some global variables/parameters. So later on if we want to change something globally, we can easily find them. This script will be called automatically when game starts.

--Global variable
    --set touch move parameters
    Sensitivity = 0.005
    --invert = -1 -> is inverted
    Invert = 1


    Threshold=3.5

9. Create txt file called planeTouchMove.lua and put following code......
mouse=OgreKit.Mouse()
scene = OgreKit.getActiveScene()
play = scene:getObject("plane")
mouse:capture()

--display mouse movement for debug
--dPrintf("---xrel: " .. mouse.xrel)
--dPrintf("---yrel: " .. mouse.yrel)
--dPrintf("---xrel + yrel: " .. mouse.xrel+mouse.yrel)

--using threshold to filter out unwanted small touch movement
if ((mouse.xrel>Threshold or mouse.xrel<-Threshold)or(mouse.yrel>Threshold or mouse.yrel<-Threshold)) then
      play:translate(-(mouse.yrel) * Sensitivity * Invert,-(mouse.xrel) * Sensitivity * Invert,0)
      dPrintf("---xrel: " .. mouse.xrel)
      dPrintf("---yrel: " .. mouse.yrel)
else
     dPrintf("no movement")
     


end


What does this do is measuring mouse movement. And pass it to the plane. It uses sensitivity and invert variables defined in the onInit.lua file to adjust the movement. And use threshold to filter out unwanted tiny figure movement.

10. Go to plane game logic and create sensor mouse + movement and click the positive pulse "..." button, it is the first to the left.

11. In game logic link sensor with lua script.
12. Pack content and save file.
13. Test on desktop.
14. Copy the blender file into android project asset folder.
15. Open eclipse and android Gamekit file.
16. Refresh asset folder and goto main.java to change file name to the one just copied.
17. Connect android device to desktop
18. In eclipse save and run.

blender file is available at:https://docs.google.com/file/d/0B2dWucciRgDPUmFOc19ibFNYNmc/edit?usp=sharing

Tuesday, August 20, 2013

How to Test Blender 3D Gamekit on Android Device


You need to install adb on your computer and eclipse First.
The Android SDK contains the Android debug bridge (adb) which is a tool which allows you to connect to a virtual or real Android device for the purpose of managing the device or debugging your application. Check links below
http://developer.android.com/sdk/index.html
http://developer.android.com/sdk/installing/installing-adt.html


1. set your android device to debug mode, in the video is a google nexus 7
2.connect usb to your desktop
3.open eclipse and open the blender 3d gamekit android package, this package can be download at:
4.pack and save your blender file, test on desktop.
5.copy your blender file into the asset folder under the eclipse project
6.refresh asset to confirm you've got it.
7.go to main.java change file name to your blender file name
8.click run, the apk will be send to your device and should be running in several minutes.
The android package can be downloaded from: