Showing posts with label iPad. Show all posts
Showing posts with label iPad. Show all posts

Saturday, January 18, 2014

Blender 3D Mobile Plane Animation and Collision Test

Showing how to make plane moving and run it on Android and iOS.
1.model the propeller

2. add rotation to propeller in game logic

3. apply scale before testing on ogrekit, otherwise model will be out of scale

4.move plane to start point

5.using time line to add key frames

6. add the animation to plane in game logic

7. fine tune plane locations in graph editor

9. test animation on pc

10. change planes to rigid body physics

11. using box as collision bounds

12. Test on PC

13. Test on Android

14. Test on ipad


Monday, December 23, 2013

Blender 3D Mobile Enemy Plane Modelling & UV Map

Showing how to Model and UV Map a bit complicated plane for running on iOS, Android Devices using Bender 3d with Gamekit.
1. Insert your design as blender3D back ground
2. Create wing using box. Put mirror modifier. Then extrude the side face. Adjust nods on the way to form the shade. Finalize mirror modifier when finishes.
3. Create a cylinder and use extrude scale on the way to create fuselage and engines.
4. Repeat to do the back wing, join components together and give it name
5. Now to unwrap the model for texturing. Go to side ortho view and press 'B' to box select the under side half of the plane. Remove Top of wing faces from selection by Press 'Shift' and mouse right button.
6. Change to top view. Then click unwrap and use project from view.
7. Move the UV map for giving spaces for other parts' uv map.
8. Unwrap other parts of the plane
9. Overlap 2 sides of rudder for easier texturing in future.
10. export the uv map. open in Gimp2 or PhotoShop, paint plane skin
11. load image into Blender3d Texture. and Set the coordination as UV.
12. Select shadeless, for constant colouring.

13. Testing on Android and iOS, Check my other post / youtube for how to do this.














Saturday, November 9, 2013

Blender3D GameKit Lua Plane Top Bottom Constraint



The top bottom constraint is a bit tricky. As camera keeps moving with plane. I used camera as a reference to calcuate the top and bottom screen edge.
1. Get camera position
2. Calculate current top edge Y location
3. Calculate current bottom edge Y location
4. Compare with current plane location, and return signals, -1 as plane too low, 1 as plane too high, 0 for plane inside the screen
5. feed the signal and mouse movement to function edgeMoveFilter, which only permit plane move toward centre if it is on edge
The code is below and red marks are comments.
******Oninit.lua****************
    --Global variable
    --set touch move parameters
    Sensitivity = 0.005
    --invert = -1 -> is inverted
    Invert = 1
    Threshold=3.5
 -- Plane Contrain
    Xmin = -0.87
    Xmax = 0.87
 -- Plane Top Bottom Constrain
    Ymin = -1.50
    Ymax = 1.30
--filter movement so plane will only move towards center if touchs edge
function edgeMoveFilter(limitSignal,oldX)
    if limitSignal == -1 and oldX > 0 then
        return oldX
    elseif limitSignal == -1 and oldX < 0 then
        return 0
    elseif limitSignal == 1 and oldX >0 then
        return 0
    elseif limitSignal ==1 and oldX <0 then
        return oldX
    end
        return 0
end   

--check if over boundary on Y axis
function YoverLimit(obj,cameraObj)
    local vec3 = obj:getPosition()
    local cameraV = cameraObj:getLinearVelocity()
    --get camero position
    local cameraP = cameraObj:getPosition()
    --calculate bottom edge ;ocation
    local nextYmin = cameraP.y+Ymin
    --calculate top edge location
    local nextYmax = cameraP.y+Ymax
    --check whether plane is on edge and return signals
    if vec3.y < nextYmin then
        return -1
    elseif vec3.y > nextYmax then
        return 1
    else 
        return 0
    end
end

--endNew-----------
function XoverLimit(obj)
    local vec3 = obj:getPosition()
    if vec3.x < Xmin then
        return -1
    elseif vec3.x > Xmax then
        return 1
    else
        return 0
    end
end
function printPosition(obj)
    local vec3 = obj:getPosition()
    dPrintf("position x: " .. vec3.x)
    dPrintf("position y: " .. vec3.y)
    dPrintf("position z: " .. vec3.z)
    
end    
function velocityCap(v,vmax)
    if (v>vmax) then
        return vmax
    elseif (v < -vmax) then
        return -vmax
    else return v
    end
end

******planeTouchMove.lua****************  

mouse=OgreKit.Mouse()
scene = OgreKit.getActiveScene()
play = scene:getObject("plane")
--new--get camera objcet
camera = scene:getObject("Camera")
--end new---------------------------
logicM = OgreKit.LogicManager()
myLogicObject = logicM:getObject("plane")
mySensor = myLogicObject:getSensor("Collision")
maxVelocity=0.08


mouse:capture()
--print current plane posistion on screen
--printPosition(play)
--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)and (not(play.touchBoundary))) then
      velocityY=velocityCap((mouse.yrel) * Sensitivity, maxVelocity)
      velocityX=velocityCap((mouse.xrel) * Sensitivity, maxVelocity) 
      --new----------------------
      --check if plane over screen boundary 
      limitSignalX = XoverLimit(play)
      limitSignalY = YoverLimit(play,camera)
      --the X Y directions are swap as the screen is in landscape
      if limitSignalX==0  and limitSignalY == 0 then
      --when plane is inside boundary
        play:translate(-velocityY* Invert,-velocityX * Invert,0)
      else
      --when plane touches boundary it can only move away from boundrary
        newY = edgeMoveFilter(limitSignalX,-velocityY * Invert)
        newX = edgeMoveFilter(limitSignalY,-velocityX * Invert)
        play:translate(newY,newX,0)
      end
      --end new---------------------
end


  


    

Saturday, September 28, 2013

Blender Gamekit Lua Constrain Plane Side Movement

Blender 3D game engine provides location constraint to limit object in a certain area. However this was not implemented in the Gamekit package. I have to do some scripting to get around it. So my plane will not fly out of the screen. Below is the script and red bits are my explanations. This is apart of series tutorials to create a 2d arcade plane game using Blender 3D and gamekit. Check this blog for more details.


-------BELOW IS OnInit.lua--------------

--Global variable
    --set touch move parameters
    Sensitivity = 0.005
    --invert = -1 -> is inverted
    Invert = 1
    Threshold=3.5
 -- Plane Constrain parameter
    Xmin = -0.87 --This is the left boundary, adjust if necessary
    Xmax = 0.87 --This is the right boundary, adjust if necessary
--this function is to stop plane moving cross the boundary
function xMoveFilter(limitSignal,oldX)
    if limitSignal == -1 and oldX > 0 then
        return oldX
    elseif limitSignal == -1 and oldX < 0 then
        return 0
    elseif limitSignal == 1 and oldX >0 then
        return 0
    elseif limitSignal ==1 and oldX <0 then
        return oldX
    end
        return 0
end
--this function is to determine whether plane is over the broundary
function XoverLimit(obj)
    local vec3 = obj:getPosition()
    if vec3.x < Xmin then
        return -1
    elseif vec3.x > Xmax then
        return 1
    else
        return 0
    end
end
--this function is for debug used to display plane position
function printPosition(obj)
    local vec3 = obj:getPosition()
    dPrintf("position x: " .. vec3.x)
    dPrintf("position y: " .. vec3.y)
    dPrintf("position z: " .. vec3.z)
    
end    
function velocityCap(v,vmax)
    if (v>vmax) then
        return vmax
    elseif (v < -vmax) then
        return -vmax
    else return v
    end
end

-------BELOW IS planeTouchMove.lua--------------

mouse=OgreKit.Mouse()
scene = OgreKit.getActiveScene()
play = scene:getObject("plane")
logicM = OgreKit.LogicManager()
myLogicObject = logicM:getObject("plane")
mySensor = myLogicObject:getSensor("Collision")
maxVelocity=0.08


mouse:capture()
--print current plane posistion on screen
printPosition(play)
--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)and (not(play.touchBoundary))) then
      velocityY=velocityCap((mouse.yrel) * Sensitivity, maxVelocity)
      velocityX=velocityCap((mouse.xrel) * Sensitivity, maxVelocity)
      --check if plane over screen boundary 
      limitSignal = XoverLimit(play)
      --the X Y directions are swapped as the screen is in landscape
      if limitSignal==0  then
      --when plane is inside boundary
        play:translate(-velocityY* Invert,-velocityX * Invert,0)
      else
      --when plane touches boundary it can only move away from boundrary
        newY = xMoveFilter(limitSignal,-velocityY * Invert)
        play:translate(newY,-velocityX * Invert,0)
      end
end




    

Monday, September 23, 2013

Blender 3D Gamekit Plane Shoot Bullet IOS Android Tutorial

This is a follow up to the plane arcade game tutorial posted before. This time I added plane shooting bullet. For how to run it on real android device such as nexus 7, and ios devices, such as iPad. Please go to my youtube channel: http://www.youtube.com/user/hhhnzw. there are videos showing that.

1. if you continue from last tutorial first thing is to rename the Background image from Plane to background. it is confusing, as the aeroplane is also called plan.
2. Create an empty element. set its parent to plane. and move it to centre of the plane. and move down. so the Z axis' number is -0.1. Rename it as EmptyGunCentre.
3. Create a box, and scale smaller, it will become bullet. So pick a size as you think is proper. Rename it to bullet01.
4. Unwrap & export UV map from the box. and paint it to look like a bullet.
5.load the edited uv map in blender, and apply it to bullet element.
6. Put bullet on to layer 2, HIDDEN layer.
7. Pick the EmptyGunCentre, go to game logic editor to set it up like image below:
8. Turn on the hidden layer and pick the bullet. Then go to physics tab. Change type to dynamic. Change the min max velocity to 3.5. And lock Z axis.
9. Now pack the content in, and save the file. Test it on PC first. Then follow my other videos to run it on Android and IOS devices.

Blender file can be downloaded from link below:





Saturday, September 7, 2013

How to Test Blender GameKit on Real IOS Device Tutorial

Finally, I figured out how to test the Blender3D GameKit on Real IOS devices, such as iphone 5 and iPad 4 in the video. This is using latest xcode 4.6 and ios 6.1 build. Took a while to work out this.

1. go to gamekit on google code site to get the source. copy the svn script and run it in a terminal. It will download the whole package onto your hard disk.
2. go to apple developer site register yourself and pay $99 to get the iOS developer licence. So you can test applications on your iOS devices.
3. go to mac application shop download Xcode. Currently using 4.6
4. open xcode and go to preference -> download install the command tools.
5. search cmake and install.
6. search xquartz and install.
7. open cmake. point source to gamekit-read-only you downloaded before. point target to a folder under it. normally named build.
8. Click configure once. And wait for the settings to come up. Turn on OGREKIT_BUILD_IPHONE,Turn on OGREKIT_BUILD_GLESRS.Turn off OGREKIT_BUILD_GLRS
9. click configure again. only one red line. and then click again. there will be no red lines.
10. click generate. This will generate a xcode project for you named ogrekit.xproject in the build folder.
11. link your iPhone, iPad to computer and start Xcode. this will bring you to a button to set your device for development. click and finish the process.
12. copy your own blender file for testing into iphoneDemo folder.
13. open ogrekit.xproject in xcode and drag the file under iphoneDemo.
14. open main.mm under iphoneDemo folder. edit the name of the blender file to the one you just copied.

const gkString gkDefaultBlend   = "planeTouchMoveIOS.blend";

 go to screen size to annotate them. It is not needed and will mess screen settings. 

// iPad
    //m_prefs.winsize.x        = 768;
    //m_prefs.winsize.y        = 1024;
    // iPhone
//960x640, 480x320
    //m_prefs.winsize.x        = 960;
    //m_prefs.winsize.y        = 640;

//m_prefs.winsize.x        = 320;
    //m_prefs.winsize.y        = 480;

Also search scale. and go to a line that defines scale, annotate it. replace it with:

//CGFloat screenScale = [[UIScreen mainScreen] scale];
    CGFloat screenScale = 1;

15. change the target to buildAll->your device name. and Command + B to build. for the first time it will take a while. but afterwards will be much faster.
16. After succeed the build. Make sure you have your device connected. Change the target to IphoneDemo->your device and click run. 
17. wait for several minutes. the files will be compiled and uploaded on to your device. The App will start running by itself.
18. for ipad just go to the summary page and change the target device to ipad.


Wednesday, June 19, 2013

ios 3D game Test on Simulator


  
ios game 'switch' using Blender 3D 2.6 and gamekit game engine
build iOS iPhone ipad game using free Blender 3D and GameKit,
Just a little programming knowledge required.

Game Engine iOS Build Tutorial


this video showing how to build blender 3d gamekit ( free game engine )iPhone ios application for running blender 3D game on iOS devices.
download cmake from cmake.org.in xcode project setting, change code signing to no, i missed that in the video.

The goal of gamekit is to create a basic game engine that allows fast prototyping build around open source software free for commercial use.

Using Ogre or Irrlicht for graphics, Bullet for physics, OpenAL for sound
OgreKit is most actively developed and in svn/trunk, the suspended Irrlicht version is in svn/branches/IrrKit.
Engine is written in C++ and the game logic can be done in C++, Lua scripting or logic bricks