teienlib 0.0.1-x86-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +31 -0
- data/ext/teienlib/extconf.rb +35 -0
- data/ext/teienlib/interface/AnimationBlender.i +8 -0
- data/ext/teienlib/interface/CollisionChecker.i +22 -0
- data/ext/teienlib/interface/DebugDrawer.i +8 -0
- data/ext/teienlib/interface/MeshStrider.i +8 -0
- data/ext/teienlib/interface/Rakefile +27 -0
- data/ext/teienlib/interface/SoftBody.i +9 -0
- data/ext/teienlib/interface/teienlib.i +36 -0
- data/ext/teienlib/src/AnimationBlender.cc +141 -0
- data/ext/teienlib/src/AnimationBlender.h +41 -0
- data/ext/teienlib/src/Collision.cc +797 -0
- data/ext/teienlib/src/Collision.h +130 -0
- data/ext/teienlib/src/CollisionChecker.cc +67 -0
- data/ext/teienlib/src/CollisionChecker.h +33 -0
- data/ext/teienlib/src/DebugDrawer.h +66 -0
- data/ext/teienlib/src/MeshStrider.cc +112 -0
- data/ext/teienlib/src/MeshStrider.h +48 -0
- data/ext/teienlib/src/Shape.cc +9 -0
- data/ext/teienlib/src/Shape.h +186 -0
- data/ext/teienlib/src/SimpleCollisionLibrary.h +7 -0
- data/ext/teienlib/src/SoftBody.cc +148 -0
- data/ext/teienlib/src/SoftBody.h +14 -0
- data/ext/teienlib/src/Vector3D.h +92 -0
- data/lib/Teienlib.so +0 -0
- data/lib/teienlib/version.rb +3 -0
- data/lib/teienlib.rb +5 -0
- data/teienlib.gemspec +33 -0
- metadata +98 -0
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 abexsoft@gmail.com
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Teienlib
|
2
|
+
|
3
|
+
Teienlib is a ruby extension library set for Teien.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'teienlib'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install teienlib
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
see [INSTALL.md](https://github.com/abexsoft/teienlib/blob/master/INSTALL.md)
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require 'rake/clean'
|
3
|
+
|
4
|
+
DLEXT = RbConfig::MAKEFILE_CONFIG['DLEXT']
|
5
|
+
|
6
|
+
desc 'Compile a teienlib extension library'
|
7
|
+
task "compile" => ["lib/Teienlib.#{DLEXT}"]
|
8
|
+
|
9
|
+
## lib/*.#{DLEXT}
|
10
|
+
file "lib/Teienlib.#{DLEXT}" => "ext/teienlib/Teienlib.#{DLEXT}" do |f|
|
11
|
+
cp f.prerequisites, "lib/", :preserve => true
|
12
|
+
end
|
13
|
+
|
14
|
+
## ext/**/*.#{DLEXT}
|
15
|
+
file "ext/teienlib/Teienlib.#{DLEXT}" => FileList["ext/teienlib/Makefile"] do |f|
|
16
|
+
sh 'cd ext/teienlib/ && make clean && make'
|
17
|
+
end
|
18
|
+
CLEAN.include 'ext/Teienlib/*.{o,so,dll}'
|
19
|
+
|
20
|
+
## ext/**/Makefile
|
21
|
+
file 'ext/teienlib/Makefile' => FileList['ext/teienlib/interface/teienlib_wrap.cpp'] do
|
22
|
+
chdir('ext/teienlib/') { ruby 'extconf.rb' }
|
23
|
+
end
|
24
|
+
CLEAN.include 'ext/teienlib/Makefile'
|
25
|
+
|
26
|
+
## make wrappers with swig.
|
27
|
+
file 'ext/teienlib/interface/teienlib_wrap.cpp' do
|
28
|
+
chdir('ext/teienlib/interface') { sh 'rake' }
|
29
|
+
end
|
30
|
+
CLEAN.include 'ext/teienlib/interface/teienlib_wrap.{cpp,h,o}'
|
31
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
|
3
|
+
# set values of INC and LIB.
|
4
|
+
require 'BulletConfig'
|
5
|
+
require 'OgreConfig'
|
6
|
+
BULLET_INC = BulletConfig.getIncFlags()
|
7
|
+
BULLET_LIB = "-L" + BulletConfig.getDepsLibPath()
|
8
|
+
|
9
|
+
OGRE_INC = OgreConfig.getIncFlags()
|
10
|
+
OGRE_LIB = "-L" + OgreConfig.getDepsLibPath()
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
# set flags
|
15
|
+
$CFLAGS += " -g " + BULLET_INC + " " + OGRE_INC + " -I./src/"
|
16
|
+
|
17
|
+
if (/mingw/ =~ RUBY_PLATFORM)
|
18
|
+
$LDFLAGS += " -static-libgcc -static-libstdc++ " + BULLET_LIB + " " + OGRE_LIB + " -lws2_32 -lwinmm"
|
19
|
+
else
|
20
|
+
$LDFLAGS += " -static-libgcc -static-libstdc++ " + BULLET_LIB + " " + OGRE_LIB
|
21
|
+
end
|
22
|
+
|
23
|
+
$srcs = ["src/AnimationBlender.cc",
|
24
|
+
"src/MeshStrider.cc",
|
25
|
+
"src/SoftBody.cc",
|
26
|
+
"src/Collision.cc",
|
27
|
+
"src/Shape.cc",
|
28
|
+
"src/CollisionChecker.cc",
|
29
|
+
"src/DebugDrawer.cpp",
|
30
|
+
"interface/teienlib_wrap.cpp"]
|
31
|
+
|
32
|
+
$objs = $srcs.collect {|o| o.sub(/\.cpp|\.cc|\.cxx/, ".o")}
|
33
|
+
$cleanfiles = $objs
|
34
|
+
|
35
|
+
create_makefile('Teienlib')
|
@@ -0,0 +1,22 @@
|
|
1
|
+
%module(directors="1") "MiniatureGarden"
|
2
|
+
|
3
|
+
//#define DEBUG_FREEFUNC
|
4
|
+
|
5
|
+
//%import ../../bullet/interface/bullet_all.i
|
6
|
+
|
7
|
+
//%include cpointer.i
|
8
|
+
//%pointer_class(int, Intp);
|
9
|
+
|
10
|
+
%{
|
11
|
+
#include <btGImpactShape.h>
|
12
|
+
#include "CollisionChecker.h"
|
13
|
+
%}
|
14
|
+
|
15
|
+
%include CollisionChecker.h
|
16
|
+
|
17
|
+
%{
|
18
|
+
%}
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
SWIG = 'swig'
|
2
|
+
|
3
|
+
BULLET_TOP = `ruby -e "require 'BulletConfig'; print BulletConfig.getTopDir"`
|
4
|
+
BULLET_INC = `ruby -e "require 'BulletConfig'; print BulletConfig.getIncFlags"`
|
5
|
+
|
6
|
+
OGRE_TOP = `ruby -e "require 'OgreConfig'; print OgreConfig.getTopDir"`
|
7
|
+
OGRE_INC = `ruby -e "require 'OgreConfig'; print OgreConfig.getIncFlags"`
|
8
|
+
|
9
|
+
SWIGFLAGS = "-ruby -c++ #{BULLET_INC} #{OGRE_INC} -I../src/ -I#{BULLET_TOP}/bindings/bullet/interface -I#{OGRE_TOP}/bindings/ogre/interface"
|
10
|
+
|
11
|
+
|
12
|
+
TARGET = 'teienlib_wrap.cpp'
|
13
|
+
|
14
|
+
puts SWIGFLAGS
|
15
|
+
|
16
|
+
|
17
|
+
task :default => "#{TARGET}"
|
18
|
+
|
19
|
+
file "#{TARGET}" => "teienlib.i" do |t|
|
20
|
+
sh "#{SWIG} #{SWIGFLAGS} -o #{t.name} #{t.prerequisites[0]}"
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
task :clean do
|
25
|
+
sh "rm -f #{TARGET}"
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
%module(directors="1") "Teienlib"
|
2
|
+
|
3
|
+
//#define DEBUG_FREEFUNC
|
4
|
+
|
5
|
+
%import ogre_all.i
|
6
|
+
%import bullet_all.i
|
7
|
+
|
8
|
+
%{
|
9
|
+
#include "btMultimaterialTriangleMeshShape.h"
|
10
|
+
#include "btConvex2dShape.h"
|
11
|
+
#include "btBox2dShape.h"
|
12
|
+
#include "btHeightfieldTerrainShape.h"
|
13
|
+
#include "btMinkowskiSumShape.h"
|
14
|
+
#include "btConvexPointCloudShape.h"
|
15
|
+
#include "btTriangleIndexVertexMaterialArray.h"
|
16
|
+
#include "btGrahamScan2dConvexHull.h"
|
17
|
+
%}
|
18
|
+
|
19
|
+
|
20
|
+
%include cpointer.i
|
21
|
+
%pointer_class(int, Intp);
|
22
|
+
|
23
|
+
|
24
|
+
%include AnimationBlender.i
|
25
|
+
%include MeshStrider.i
|
26
|
+
%include SoftBody.i
|
27
|
+
%include CollisionChecker.i
|
28
|
+
%include DebugDrawer.i
|
29
|
+
|
30
|
+
|
31
|
+
%{
|
32
|
+
%}
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
|
@@ -0,0 +1,141 @@
|
|
1
|
+
#include "AnimationBlender.h"
|
2
|
+
|
3
|
+
AnimationBlender::AnimationBlender(Ogre::Entity *entity)
|
4
|
+
: mEntity(entity)
|
5
|
+
{
|
6
|
+
}
|
7
|
+
|
8
|
+
|
9
|
+
void
|
10
|
+
AnimationBlender::init(const Ogre::String &animation, bool l)
|
11
|
+
{
|
12
|
+
Ogre::AnimationStateSet *set = mEntity->getAllAnimationStates();
|
13
|
+
Ogre::AnimationStateIterator it = set->getAnimationStateIterator();
|
14
|
+
while(it.hasMoreElements())
|
15
|
+
{
|
16
|
+
Ogre::AnimationState *anim = it.getNext();
|
17
|
+
anim->setEnabled(false);
|
18
|
+
anim->setWeight(0);
|
19
|
+
anim->setTimePosition(0);
|
20
|
+
}
|
21
|
+
mSource = mEntity->getAnimationState( animation );
|
22
|
+
mSource->setEnabled(true);
|
23
|
+
mSource->setWeight(1);
|
24
|
+
mTimeleft = 0;
|
25
|
+
mDuration = 1;
|
26
|
+
mTarget = 0;
|
27
|
+
complete = false;
|
28
|
+
loop = l;
|
29
|
+
}
|
30
|
+
|
31
|
+
void
|
32
|
+
AnimationBlender::blend(const Ogre::String &animation, BlendingTransition transition, Ogre::Real duration, bool l )
|
33
|
+
{
|
34
|
+
loop = l;
|
35
|
+
if( transition == AnimationBlender::BlendSwitch )
|
36
|
+
{
|
37
|
+
if( mSource != 0 )
|
38
|
+
mSource->setEnabled(false);
|
39
|
+
mSource = mEntity->getAnimationState( animation );
|
40
|
+
mSource->setEnabled(true);
|
41
|
+
mSource->setWeight(1);
|
42
|
+
mSource->setTimePosition(0);
|
43
|
+
mTimeleft = 0;
|
44
|
+
}
|
45
|
+
else
|
46
|
+
{
|
47
|
+
Ogre::AnimationState *newTarget = mEntity->getAnimationState( animation );
|
48
|
+
if( mTimeleft > 0 )
|
49
|
+
{
|
50
|
+
// oops, weren't finished yet
|
51
|
+
if( newTarget == mTarget )
|
52
|
+
{
|
53
|
+
// nothing to do! (ignoring duration here)
|
54
|
+
}
|
55
|
+
else if( newTarget == mSource )
|
56
|
+
{
|
57
|
+
// going back to the source state, so let's switch
|
58
|
+
mSource = mTarget;
|
59
|
+
mTarget = newTarget;
|
60
|
+
mTimeleft = mDuration - mTimeleft; // i'm ignoring the new duration here
|
61
|
+
}
|
62
|
+
else
|
63
|
+
{
|
64
|
+
// ok, newTarget is really new, so either we simply replace the target with this one, or
|
65
|
+
// we make the target the new source
|
66
|
+
if( mTimeleft < mDuration * 0.5 )
|
67
|
+
{
|
68
|
+
// simply replace the target with this one
|
69
|
+
mTarget->setEnabled(false);
|
70
|
+
mTarget->setWeight(0);
|
71
|
+
}
|
72
|
+
else
|
73
|
+
{
|
74
|
+
// old target becomes new source
|
75
|
+
mSource->setEnabled(false);
|
76
|
+
mSource->setWeight(0);
|
77
|
+
mSource = mTarget;
|
78
|
+
}
|
79
|
+
mTarget = newTarget;
|
80
|
+
mTarget->setEnabled(true);
|
81
|
+
mTarget->setWeight( 1.0 - mTimeleft / mDuration );
|
82
|
+
mTarget->setTimePosition(0);
|
83
|
+
}
|
84
|
+
}
|
85
|
+
else
|
86
|
+
{
|
87
|
+
if( newTarget == mSource )
|
88
|
+
return;
|
89
|
+
// assert( target == 0, "target should be 0 when not blending" )
|
90
|
+
// mSource->setEnabled(true);
|
91
|
+
// mSource->setWeight(1);
|
92
|
+
mTransition = transition;
|
93
|
+
mTimeleft = mDuration = duration;
|
94
|
+
mTarget = newTarget;
|
95
|
+
mTarget->setEnabled(true);
|
96
|
+
mTarget->setWeight(0);
|
97
|
+
mTarget->setTimePosition(0);
|
98
|
+
}
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
102
|
+
void
|
103
|
+
AnimationBlender::addTime(Ogre::Real time )
|
104
|
+
{
|
105
|
+
if( mSource != 0 )
|
106
|
+
{
|
107
|
+
if( mTimeleft > 0 )
|
108
|
+
{
|
109
|
+
mTimeleft -= time;
|
110
|
+
if( mTimeleft < 0 )
|
111
|
+
{
|
112
|
+
// finish blending
|
113
|
+
mSource->setEnabled(false);
|
114
|
+
mSource->setWeight(0);
|
115
|
+
mSource = mTarget;
|
116
|
+
mSource->setEnabled(true);
|
117
|
+
mSource->setWeight(1);
|
118
|
+
mTarget = 0;
|
119
|
+
}
|
120
|
+
else
|
121
|
+
{
|
122
|
+
// still blending, advance weights
|
123
|
+
mSource->setWeight(mTimeleft / mDuration);
|
124
|
+
mTarget->setWeight(1.0 - mTimeleft / mDuration);
|
125
|
+
if(mTransition == AnimationBlender::BlendWhileAnimating)
|
126
|
+
mTarget->addTime(time);
|
127
|
+
}
|
128
|
+
}
|
129
|
+
if (mSource->getTimePosition() >= mSource->getLength())
|
130
|
+
{
|
131
|
+
complete = true;
|
132
|
+
}
|
133
|
+
else
|
134
|
+
{
|
135
|
+
complete = false;
|
136
|
+
}
|
137
|
+
mSource->addTime(time);
|
138
|
+
mSource->setLoop(loop);
|
139
|
+
}
|
140
|
+
}
|
141
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
/*
|
2
|
+
* This class is being presented in the following web site,
|
3
|
+
* http://www.ogre3d.org/tikiwiki/AnimationBlender.
|
4
|
+
*/
|
5
|
+
|
6
|
+
|
7
|
+
#include <Ogre.h>
|
8
|
+
|
9
|
+
class AnimationBlender
|
10
|
+
{
|
11
|
+
public:
|
12
|
+
enum BlendingTransition
|
13
|
+
{
|
14
|
+
BlendSwitch, // stop source and start dest
|
15
|
+
BlendWhileAnimating, // cross fade, blend source animation out while blending destination animation in
|
16
|
+
BlendThenAnimate // blend source to first frame of dest, when done, start dest anim
|
17
|
+
};
|
18
|
+
|
19
|
+
Ogre::Real mTimeleft, mDuration;
|
20
|
+
bool complete;
|
21
|
+
|
22
|
+
AnimationBlender(Ogre::Entity *);
|
23
|
+
~AnimationBlender() {}
|
24
|
+
|
25
|
+
Ogre::Real getProgress() { return mTimeleft/ mDuration; }
|
26
|
+
Ogre::AnimationState *getSource() { return mSource; }
|
27
|
+
Ogre::AnimationState *getTarget() { return mTarget; }
|
28
|
+
|
29
|
+
void init( const Ogre::String &animation, bool l=true );
|
30
|
+
void blend( const Ogre::String &animation, BlendingTransition transition, Ogre::Real duration, bool l=true );
|
31
|
+
void addTime(Ogre::Real );
|
32
|
+
|
33
|
+
private:
|
34
|
+
Ogre::Entity *mEntity;
|
35
|
+
Ogre::AnimationState *mSource;
|
36
|
+
Ogre::AnimationState *mTarget;
|
37
|
+
|
38
|
+
BlendingTransition mTransition;
|
39
|
+
|
40
|
+
bool loop;
|
41
|
+
};
|