Tuesday, February 28, 2012

一些 android 游戏引擎

WiEngine.....

详情请登录微云:http://www.wiyun.com/web/wiengine

WiEngine -- 微云游戏引擎 Android版是一个适用于Android系统的2D游戏引擎。
WiEngine参考吸取了iPhone平台著名引擎cocos2d的设计理念,针对Android系统结构的
特点进行了大量的适配开发,设计修改和性能增强工作。

http://blog.csdn.net/cping1982/article/details/5788921 
或许您还不知道的八款Android开源游戏引擎 
很多初学Android游戏开发的朋友,往往会显得有些无所适从,他们常常不知道该从何处入手,每当遇到自己无法解决的难题时,又往往会一边羡慕于iPhone下有诸如Cocos2d-iphone之类的免费游戏引擎可供使用,一边自暴自弃的抱怨Android平台游戏开发难度太高,又连个像样的游戏引擎也没有,甚至误以为使用Java语言开发游戏是一件费力不讨好且没有出路的事情。

事实上,这种想法完全是没有必要且不符合实际的,作为能和苹果iOS分庭抗礼的Android(各种意义上),当然也会有相当数量的游戏引擎存在。仅仅因为我们处于这个狭小的天地间,与外界接触不够,所以对它们的存在茫然不知罢了。

下面我就罗列出八款常见的Android游戏引擎,以供有需要者参考(收费,下载量过小,不公布源码,以及鄙人不知道(-_-)的引擎不在此列)。


1、Angle 


Angle是一款专为Android平台设计的,敏捷且适合快速开发的2D游戏引擎,基于OpenGL ES技术开发。该引擎全部用Java代码编写,并且可以根据自己的需要替换里面的实现,缺陷在于文档不足,而且下载的代码中仅仅包含有少量的示例教程。

最低运行环境要求不详。

项目地址:http://code.google.com/p/angle/ 

2、Rokon
 


rokon是一款Android 2D游戏引擎,基于OpenGL ES技术开发,物理引擎为Box2D,因此能够实现一些较为复杂的物理效果,该项目最新版本为 2.0.3 (09/07/10)。总体来说,此引擎最大的优点在于其开发文档相当之完备,并且项目作者对反馈Bug的修正非常之神速,所以该框架的使用在目前也最为广泛,有人干脆将它称为Cocos2d-iPhone引擎的Android版(业务逻辑和编码风格上也确实很像)。附带一提,国内某个需要注册会员才能下载的Android游戏框架衍生于此框架,所以大家也不要刻板的认为收费便一定是好的,免费就一定不好。

最低运行环境要求为Android 1.5。

项目地址:http://code.google.com/p/rokon/ 

3、LGame
 


LGame是一款国人开发的Java游戏引擎,有Android及PC(J2SE)两个开发版本,目前最高版本同为0.2.6(31/07/10)。其底层绘图器LGrpaphics封装有J2SE以及J2ME提供的全部Graphics API(PC版采用Graphics2D封装,Android版采用Canvas模拟实现),所以能够将J2SE或J2ME开发经验直接套用其中,两版本间主要代码能够相互移植。Android版内置有Admob接口,可以不必配置XML直接硬编码Admob广告信息。

该引擎除了基本的音效、图形、物理、精灵等常用组件以外,也内置有Ioc、xml、http等常用Java组件的封装,代价是jar体积较为庞大,PC版已突破1.2MB,Android版有所简化也在500KB左右。此外,该引擎还内置有按照1:1实现的J2ME精灵类及相关组件,可以将绝大多数J2ME游戏平移到Android或PC版中。唯一遗憾的是,该项目作者是个极其懒惰的家伙,开发文档从去年说到今年依旧没有提供,只有游戏示例可供下载。

最低运行环境要求为Android 1.1。

项目地址:http://code.google.com/p/loon-simple/ 

4、AndEngine
 

andengine同样是一款基于OpenGL ES技术的Android游戏引擎,物理引擎同样为Box2D(标配|||)。该框架性能普通,文档缺乏,但示例较为丰富。

最低运行环境要求不详。

项目地址(未直接提供jar下载,源码可通过svn提取):http://code.google.com/p/andengine/ 


5、libgdx
 


libgdx是一款基于OpenGL ES技术开发的Android游戏引擎,支持Android平台下的2D游戏开发,物理引擎采用Box2D实现。单就性能角度来说,堪称是一款非常强大的Android游戏引擎,但缺陷在于精灵类等相关组件在使用上不够简化,而且文档也较为匮乏。

最低运行环境要求不详。

项目地址:http://code.google.com/p/libgdx/ 

6、jPCT
 


jPCT是一款基于OpenGL技术开发的3D图形引擎(PC环境为标准OpenGL,Android为OpenGL ES), 以Java语言为基础的,拥有功能强大的Java 3D解决方案。该引擎与LGame(此为2D游戏引擎)相类似,目前拥有PC(J2SE)以及Android两个开发版本。

jPCT的最大优势之一,就在于它惊人的向下兼容性。在PC环境中,jPCT甚至可以运行在JVM1.1环境之中,因为jPCT内部提供的图形渲染接口完全符合所有的Java 1.1规范(就连已经消失的Microsoft VM乃至更古老的Netscape 4 VM也不例外)。

最低运行环境要求为Android 1.5。

项目地址:http://www.jpct.net/jpct-ae/ 

7、Alien3d
 

Alien3d是一款体积非常之小的Android 3D游戏引擎,基于OpenGL ES技术开发。为了压缩体积,它根据不同功能采用多jar方式发布(包括alien3d-engine.jar,alien3d-tiled.jar,alien3d-sprites.jar,alien3d-shapes.jar,alien3d-particles2d.jar,),事实上它的核心文件大约只有40KB,所有相关jar的总和也不足150KB。

最低运行环境要求为Android 1.5。

项目地址:http://code.google.com/p/alien3d/ 

8、Catcake
 


Catcake是一款跨平台的Java 3D图形引擎,目前支持PC(J2SE)及Android环境运行(已有iPhone版规划)。该引擎在易用性和运行性能上皆有出色的表现,支持常见的游戏开发功能,诸如精灵动画,音频处理和视频播放等。

最低运行环境要求为Android 1.6。

项目地址:http://code.google.com/p/catcake/ 

Thursday, February 23, 2012

git over ssh workflow

source1. cd the project directory
2. git init
3. git add .
4. git commit -m "comments"

target1. git clone ssh://username@domain:port/home/username/path_to_project local_project

done.

Monday, February 20, 2012

volume render tetrahedral mesh with VTK/python


import vtk
import numpy as np

# create source
points = vtk.vtkPoints()
h = 1.0;
points.InsertNextPoint(0.0, 0.0, 0.0)
points.InsertNextPoint(0.0, h, 0.0)
n = 6;
angle_step = 2.0 * np.pi / n;
r = 0.5 * h;

for i in range(n):
points.InsertNextPoint(r * np.cos(i * angle_step), h * 0.5, r * np.sin(i * angle_step))

scalars = vtk.vtkDoubleArray()
for i in range(n + 2):
scalars.InsertTuple1(i, i * 255.0 / (n + 2))


tetra = vtk.vtkTetra()
cellArray = vtk.vtkCellArray()

trangle = vtk.vtkTriangle()


for i in range(n):
tetra.GetPointIds().SetId(0, 0)
tetra.GetPointIds().SetId(1, 1)
tetra.GetPointIds().SetId(3, i + 2)
tetra.GetPointIds().SetId(2, (i + 1) % n + 2)
cellArray.InsertNextCell(tetra)
#
# trangle.GetPointIds().SetId(0, 0)
# trangle.GetPointIds().SetId(1, 1)
# trangle.GetPointIds().SetId(2, i + 2)
# cellArray.InsertNextCell(trangle)
ug = vtk.vtkUnstructuredGrid()
ug.SetPoints(points)
ug.GetPointData().SetScalars(scalars);

ug.SetCells(vtk.VTK_TETRA, cellArray)

trianglePolyData = vtk.vtkPolyData()
trianglePolyData.SetPoints( points )
trianglePolyData.SetPolys( cellArray )

writer = vtk.vtkUnstructuredGridWriter();
#writer.SetFileName("Triangle.vtp");
writer.SetFileName("test.vtk");
writer.SetInput(ug);
writer.Write();


source = vtk.vtkConeSource()
source.SetCenter(0,0,0)
source.SetResolution(100)

# mapper
mapper = vtk.vtkDataSetMapper()
mapper.SetInput(ug)
#mapper.SetInput(trianglePolyData)

## volume mapper
volumeMapper = vtk.vtkUnstructuredGridVolumeRayCastMapper()
#volumeMapper = vtk.vtkSmartVolumeMapper()
tri = vtk.vtkDataSetTriangleFilter()
tri.SetInput(ug)
volumeMapper.SetInput(tri.GetOutput())

##create the volumeproperty object to define how our volume looks
colorTF = vtk.vtkColorTransferFunction()
colorTF.AddRGBPoint(0.0, 0.0, 0.0, 0.0)
colorTF.AddRGBPoint(64.0, 1.0, 0.0, 0.0)
colorTF.AddRGBPoint(128.0, 0.0, 0.0, 1.0)
colorTF.AddRGBPoint(192.0, 0.0, 0.5, 0.0)
colorTF.AddRGBPoint(255.0, 0.0, 1.0, 0.0)

opacityTF = vtk.vtkPiecewiseFunction()
opacityTF.AddPoint(0.0, 0.8)
opacityTF.AddPoint(255.0, 1.0)

volumeProperty = vtk.vtkVolumeProperty()
volumeProperty.SetColor(colorTF)
volumeProperty.SetScalarOpacity(opacityTF)
volumeProperty.ShadeOff();
volumeProperty.SetInterpolationTypeToLinear()

##create a volume to render
theVolume = vtk.vtkVolume()
theVolume.SetMapper(volumeMapper)
theVolume.SetProperty(volumeProperty)

# actor
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetRepresentationToWireframe()

#===================================================

# create a rendering window and renderer
ren = vtk.vtkRenderer()
ren.SetBackground(.3, .6, .3); # Background color green
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)

# create a renderwindowinteractor
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

istyle = vtk.vtkInteractorStyleTrackballCamera()
iren.SetInteractorStyle(istyle)

# assign actor to the renderer
ren.AddViewProp(theVolume)
#ren.AddActor(actor)
#ren.AddActor(actor2)

# enable user interface interactor
iren.Initialize()
renWin.Render()
iren.Start()

Sunday, February 19, 2012

python VTK tricks

python 2.7.2 VTK 5.8
In python, vtkUnstructuredGrid.GetCell(n) always return a global static object. Assume that we have an unstructured grid object "ug". [ug.GetCell(i) for i in range(ug.GetNumberOfCells())] gives you a list of copies of the same, maybe global, cell object, which should be the copy of the last cell. If you wanna do sth with each single cell, do it before the return cell get override. Ex. [ map(ug.GetCell(i).GetPointId, range(4)) for i in range(ug.GetNumberOfCells())]

I did not test any other function such as GetFace.


su under windows(maybe win7+)

runas [{/profile|/noprofile}] [/env] [/netonly] [/smartcard] [/showtrustlevels] [/trustlevel] /user:UserAccountName program
 
Example: 
runas /noprofile /user:Administrator cmd 

Wednesday, February 8, 2012

cmake find module -> CmakeLists.txt -> your project

1. Find modules. CMake provides a lot of find modules by default such as vtk. However you might still need to write your own ones. You need to get those include dirs and libs. Here is a tiny example for voro++.


# - Try to find voro++
# Once done this will define
#  VORO++_FOUND - System has voro++
#  VORO++_INCLUDE_DIRS - The voro++ include directories
#  VORO++_LIBRARIES - The libraries needed to use voro++
#  VORO++_DEFINITIONS - Compiler switches required for using voro++

find_package(PkgConfig)
pkg_check_modules(PC_VORO++ QUIET voro++)
set(VORO++_DEFINITIONS ${PC_VORO++_CFLAGS_OTHER})

find_path(VORO++_INCLUDE_DIR voro++.hh
          HINTS ${PC_VORO++_INCLUDEDIR} ${PC_VORO++_INCLUDE_DIRS}
          PATH_SUFFIXES voro++ )

find_library(VORO++_LIBRARY NAMES voro++
             HINTS ${PC_VORO++_LIBDIR} ${PC_VORO++_LIBRARY_DIRS} )

set(VORO++_LIBRARIES ${VORO++_LIBRARY} )
set(VORO++_INCLUDE_DIRS ${VORO++_INCLUDE_DIR} )

include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set VORO++_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args(voro++  DEFAULT_MSG
                                  VORO++_LIBRARY VORO++_INCLUDE_DIR)

mark_as_advanced(VORO++_INCLUDE_DIR VORO++_LIBRARY )

2. Then you are going to add the modules above in your CMakeLists.txt.


cmake_minimum_required(VERSION 2.6.2)

PROJECT(vtk_tetrahedron)

if(NOT CMAKE_MODULE_PATH)
  set(CMAKE_MODULE_PATH)
endif()
list(APPEND CMAKE_MODULE_PATH /home/jesse/Jesse_Studio/cmake_find)
#        set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})

find_package(Eigen3 REQUIRED)
include_directories(${EIGEN3_INCLUDE_DIR})

find_package(Voro++ REQUIRED)
include_directories(${VORO++_INCLUDE_DIR})

add_executable(Tetrahedron Tetrahedron.cxx)

if(VTK_LIBRARIES)
    target_link_libraries(Tetrahedron ${VTK_LIBRARIES})
else()
    target_link_libraries(Tetrahedron vtkHybrid )
endif()

if(VORO++_LIBRARIES)
    target_link_libraries(Tetrahedron ${VORO++_LIBRARIES})
endif()

3. That's it. Use you cmake normally.