예제 #1
0
    def test_pose3d_invert(self):
        # rotation matrix has to be orthogonal
        col1 = m3d.Vector3(1, 0, 0)
        col2 = m3d.Vector3(0, math.cos(2), math.sin(2))
        col3 = m3d.Vector3(0, -math.sin(2), math.cos(2))
        rotation = m3d.Matrix3x3(col1, col2, col3)
        translation = m3d.Vector3(1234, 123, 798.1)
        pose = m3d.Pose3D()
        pose.translation = translation
        pose.rotation = rotation

        inverted_pose = ~pose
        original = ~inverted_pose

        self.assertEqual(pose.rotation.c1.x, original.rotation.c1.x)
        self.assertEqual(pose.rotation.c1.y, original.rotation.c1.y)
        self.assertEqual(pose.rotation.c1.z, original.rotation.c1.z)
        self.assertEqual(pose.rotation.c2.x, original.rotation.c2.x)
        self.assertEqual(pose.rotation.c2.y, original.rotation.c2.y)
        self.assertEqual(pose.rotation.c2.z, original.rotation.c2.z)
        self.assertEqual(pose.rotation.c3.x, original.rotation.c3.x)
        self.assertEqual(pose.rotation.c3.y, original.rotation.c3.y)
        self.assertEqual(pose.rotation.c3.z, original.rotation.c3.z)

        self.assertAlmostEqual(pose.translation.x, original.translation.x, places=9)
        self.assertAlmostEqual(pose.translation.y, original.translation.y, places=9)
        self.assertAlmostEqual(pose.translation.z, original.translation.z, places=9)
예제 #2
0
    def test_pose3d_mul(self):
        # the multiplication transforms a vector in local coordinates to global coordinates.
        # syntax pose2d(robot) in global coordinates * a vector in the robots coordinate system
        glob_robot_pose = m3d.Pose3D()
        glob_robot_pose.translation = m3d.Vector3(100, 0, 0)
        glob_robot_pose.rotation = m3d.Matrix3x3.eye()

        rel_ball_position = m3d.Vector3(100, 10, 0)
        glob_ball_pos = glob_robot_pose * rel_ball_position
        self.assertEqual(glob_ball_pos.x, 200)
        self.assertEqual(glob_ball_pos.y, 10)
        self.assertEqual(glob_ball_pos.z, 0)
예제 #3
0
 def test_init(self):
     col1 = m3d.Vector3(1, 2, 3)
     col2 = m3d.Vector3(4, 5, 6)
     col3 = m3d.Vector3(7, 8, 9)
     matrix = m3d.Matrix3x3(col1, col2, col3)
     self.assertEqual(matrix.c1.x, 1)
     self.assertEqual(matrix.c1.y, 2)
     self.assertEqual(matrix.c1.z, 3)
     self.assertEqual(matrix.c2.x, 4)
     self.assertEqual(matrix.c2.y, 5)
     self.assertEqual(matrix.c2.z, 6)
     self.assertEqual(matrix.c3.x, 7)
     self.assertEqual(matrix.c3.y, 8)
     self.assertEqual(matrix.c3.z, 9)
예제 #4
0
 def test_transpose(self):
     col1 = m3d.Vector3(1, 2, 3)
     col2 = m3d.Vector3(4, 5, 6)
     col3 = m3d.Vector3(7, 8, 9)
     matrix = m3d.Matrix3x3(col1, col2, col3)
     matrix = matrix.transpose()
     self.assertEqual(matrix.c1.x, 1)
     self.assertEqual(matrix.c1.y, 4)
     self.assertEqual(matrix.c1.z, 7)
     self.assertEqual(matrix.c2.x, 2)
     self.assertEqual(matrix.c2.y, 5)
     self.assertEqual(matrix.c2.z, 8)
     self.assertEqual(matrix.c3.x, 3)
     self.assertEqual(matrix.c3.y, 6)
     self.assertEqual(matrix.c3.z, 9)
예제 #5
0
    def test_matrix_multiplication(self):
        col1 = m3d.Vector3(1, 2, 3)
        col2 = m3d.Vector3(4, 5, 6)
        col3 = m3d.Vector3(7, 8, 9)
        matrix1 = m3d.Matrix3x3(col1, col2, col3)

        col1 = m3d.Vector3(2, 0, 0)
        col2 = m3d.Vector3(0, 2, 0)
        col3 = m3d.Vector3(0, 0, 2)
        matrix2 = m3d.Matrix3x3(col1, col2, col3)

        result1 = matrix1 * matrix2

        self.assertEqual(result1.c1.x, 2)
        self.assertEqual(result1.c1.y, 4)
        self.assertEqual(result1.c1.z, 6)
        self.assertEqual(result1.c2.x, 8)
        self.assertEqual(result1.c2.y, 10)
        self.assertEqual(result1.c2.z, 12)
        self.assertEqual(result1.c3.x, 14)
        self.assertEqual(result1.c3.y, 16)
        self.assertEqual(result1.c3.z, 18)

        result2 = matrix1 * m3d.Vector3(1, 1, 1)
        self.assertEqual(result2.x, 12)
        self.assertEqual(result2.y, 15)
        self.assertEqual(result2.z, 18)
예제 #6
0
    def test_sub(self):
        a = m3d.Vector3(100, 100, 100)
        b = m3d.Vector3(1000, 100, 10)
        c = m3d.Vector3(-100, -100, -100)
        d = m3d.Vector3(-5000, 5.3)
        e = m3d.Vector3(0.245, -32.28)
        f = m3d.Vector3()

        ab = a - b
        self.assertEqual(ab.x, -900)
        self.assertEqual(ab.y, 0)
        self.assertEqual(ab.z, 90)

        ac = a - c
        self.assertEqual(ac.x, 200)
        self.assertEqual(ac.y, 200)
        self.assertEqual(ac.z, 200)

        de = d - e
        self.assertEqual(de.x, -5000.245)
        self.assertEqual(de.y, 37.58)
        self.assertEqual(de.z, 0)

        cc = c - c
        self.assertEqual(cc.x, 0)
        self.assertEqual(cc.y, 0)
        self.assertEqual(cc.z, 0)

        ff = f - f
        self.assertEqual(ff.x, 0)
        self.assertEqual(ff.y, 0)
        self.assertEqual(ff.z, 0)
예제 #7
0
    def test_add(self):
        a = m3d.Vector3(100, 100, 100)
        b = m3d.Vector3(1000, 100, 10)
        c = m3d.Vector3(-100, -100, -100)
        d = m3d.Vector3(-5000, 5.3)
        e = m3d.Vector3(0.245, -32.28)
        f = m3d.Vector3()

        ab = a + b
        self.assertEqual(ab.x, 1100)
        self.assertEqual(ab.y, 200)
        self.assertEqual(ab.z, 110)

        ac = a + c
        self.assertEqual(ac.x, 0)
        self.assertEqual(ac.y, 0)
        self.assertEqual(ac.z, 0)

        de = d + e
        self.assertEqual(de.x, -4999.755)
        self.assertEqual(de.y, -26.98)
        self.assertEqual(de.z, 0)

        cc = c + c
        self.assertEqual(cc.x, -200)
        self.assertEqual(cc.y, -200)
        self.assertEqual(cc.z, -200)

        ff = f + f
        self.assertEqual(ff.x, 0)
        self.assertEqual(ff.y, 0)
        self.assertEqual(ff.z, 0)
예제 #8
0
    def test_mul(self):
        a = m3d.Vector3(50, -50, 50)
        b = m3d.Vector3(1, 0, 0)
        c = m3d.Vector3(0, 1, 1)
        d = m3d.Vector3(0.5, 7, 2)

        # scalar product
        ab = a * b
        ac = a * c
        ad = a * d

        self.assertEqual(ab, 50)
        self.assertEqual(ac, 0)
        self.assertEqual(ad, -225)

        e = 0.5
        f = 0
        g = -2

        ea = e * a  # Test for __rmul__
        ae = a * e
        fa = a * f
        ga = a * g

        self.assertEqual(ea.x, 25)
        self.assertEqual(ea.y, -25)
        self.assertEqual(ea.z, 25)

        self.assertEqual(ae.x, 25)
        self.assertEqual(ae.y, -25)
        self.assertEqual(ae.z, 25)

        self.assertEqual(fa.x, 0)
        self.assertEqual(fa.y, 0)
        self.assertEqual(fa.z, 0)

        self.assertEqual(ga.x, -100)
        self.assertEqual(ga.y, 100)
        self.assertEqual(ga.z, -100)
예제 #9
0
파일: test_m2d.py 프로젝트: tarsoly/NaoTH
    def test_mul(self):
        a = m2d.Vector2(50, -50)
        b = m2d.Vector2(1, 0)
        c = m2d.Vector2(0, 1)
        d = m2d.Vector2(0.5, 7)

        # Scalarproduct
        ab = a * b
        ac = a * c
        ad = a * d

        self.assertEqual(ab, 50)
        self.assertEqual(ac, -50)
        self.assertEqual(ad, -325)

        e = 0.5
        f = 0
        g = -2

        ea = e * a  # Test for __rmul__
        ae = a * e
        fa = a * f
        ga = a * g

        self.assertEqual(ea.x, 25)
        self.assertEqual(ea.y, -25)

        self.assertEqual(ae.x, 25)
        self.assertEqual(ae.y, -25)

        self.assertEqual(fa.x, 0)
        self.assertEqual(fa.y, 0)

        self.assertEqual(ga.x, -100)
        self.assertEqual(ga.y, 100)

        # Negative Test
        with self.assertRaises(TypeError):
            t = m2d.Vector2(50, -50)
            z = m3d.Vector3(1, 0, 1)
            t * z
예제 #10
0
import math3d
import gfx
import stage
import stage_util

light_util = stage_util.CreateStageLightUtility()

dir_light = light_util.CreateHSDirectionalLightEntity( upper_color = gfx.Color(1.0, 1.0, 1.0, 1.0), lower_color = gfx.Color(0.1,0.1,0.1,1.0), dir = math3d.Vector3(2,-3,1) )
pnt_light = light_util.CreateHSPointLightEntity( upper_color = gfx.Color(1.00,0.86,0.51,1.0), lower_color = gfx.Color(0.1,0.1,0.1,1.0), pos = math3d.Vector3(0.0,3.5,8.0), attenu0=0.1, attenu1=0.1, attenu2=0.1 )
#dir_light = light_util.CreateHSDirectionalLightEntity( upper_color = gfx.Color(1.0,0.0,0.0,1.0), lower_color = gfx.Color(0.0,1.0,0.0,1.0), dir = math3d.Vector3(2,-3,1) )
예제 #11
0
import math3d
import gfx
import stage
import stage_util


#def run():

misc_util = stage_util.CreateStageMiscUtility()

static_box = misc_util.CreateStaticBox( edge_lengths = math3d.Vector3(10,1,10), diffuse_color = gfx.Color(1,1,1,1), pose = math3d.Matrix34Identity() )

for i in range(3):
	box_pose = math3d.Matrix34( math3d.Vector3(-2,2,0) + math3d.Vector3(i*2,i,0), math3d.Matrix33Identity() );
	misc_util.CreateStaticBox( edge_lengths = math3d.Vector3(1,1,1), diffuse_color = gfx.Color(0.5,0.5,1.0,1.0), pose = box_pose )

#return 1	# done - release the script

#ScriptBase.SetCallback( run )
예제 #12
0
import math3d
import gfx
import stage
import stage_util

misc_util = stage_util.CreateStageMiscUtility()

floor_pose = math3d.Matrix34(math3d.Vector3(0, -0.5, 0),
                             math3d.Matrix33Identity())
static_box = misc_util.CreateStaticBox(edge_lengths=math3d.Vector3(64, 1, 64),
                                       diffuse_color=gfx.Color(1, 1, 1, 1),
                                       pose=floor_pose)
misc_util.CreateStaticTriangleMeshFromMesh(
    mesh_path="models/Gerzi3DARTHouse.msh")

#return 1	# done - release the script

#ScriptBase.SetCallback( run )
예제 #13
0
import math3d
import gfx
import stage
import stage_util

misc_util = stage_util.CreateStageMiscUtility()


static_mesh = misc_util.CreateStaticTriangleMeshFromMesh( mesh_path="models/character_motion_collision_test.msh" )


for x in range(-1,2):
	for z in range(-1,2):
		if x == 0 and z == 0:
			continue

		box_pos    = math3d.Vector3( x*10.0, 2.0, z*10.0  )
		box_orient = math3d.Matrix33Identity()
		box_pose   = math3d.Matrix34( box_pos, box_orient )
		misc_util.CreateBoxFromMesh( mesh_path = "models/objects/wooden_crate_H0.25.msh", pose = box_pose )
예제 #14
0
import math3d
import gfx
import stage
import stage_util

light_util = stage_util.CreateStageLightUtility()

dir_light = light_util.CreateHSDirectionalLightEntity(
    upper_color=gfx.Color(1.0, 1.0, 1.0, 1.0),
    lower_color=gfx.Color(0.1, 0.1, 0.1, 1.0),
    dir=math3d.Vector3(2, -3, 1))
#dir_light = light_util.CreateHSDirectionalLightEntity( upper_color = gfx.Color(1.0,0.0,0.0,1.0), lower_color = gfx.Color(0.0,1.0,0.0,1.0), dir = math3d.Vector3(2,-3,1) )
예제 #15
0
import math3d
import gfx
import stage
import stage_util


#def run():

misc_util = stage_util.CreateStageMiscUtility()

misc_util.CreateSkybox()

# floor
#static_box = misc_util.CreateStaticBox( edge_lengths = math3d.Vector3(50,1,50), diffuse_color = gfx.Color(1,1,1,1), pose = math3d.Matrix34Identity() )

for x in range(-2,3):
	for y in range(-2,3):
		for z in range(-2,3):
			box_pos = math3d.Vector3(x,100+y,z)
			#box_orient = math3d.Matrix33Identity()
			box_orient = math3d.Matrix33RotationZ(x) * math3d.Matrix33RotationX(z)
			box_pose = math3d.Matrix34( box_pos, box_orient )
			misc_util.CreateBox( edge_lengths = math3d.Vector3(0.8,0.8,0.8), diffuse_color = gfx.Color(1.0,0.5,0.5,1.0), pose = box_pose )

#return 1	# done - release the script

#ScriptBase.SetCallback( run )
예제 #16
0
import math3d
import gfx
import stage
import stage_util
import random

#def run():

misc_util = stage_util.CreateStageMiscUtility()

# floor
floor_pose = math3d.Matrix34(math3d.Vector3(0.0, -0.5, 0.0),
                             math3d.Matrix33Identity())
static_box = misc_util.CreateStaticBox(edge_lengths=math3d.Vector3(80, 1, 80),
                                       diffuse_color=gfx.Color(1, 1, 1, 1),
                                       pose=floor_pose)

for x in range(-1, 2):
    for z in range(-1, 2):
        if x == 0 and z == 0:
            continue

        box_pos = math3d.Vector3(x * 35.0, 2.0, z * 35.0)
        box_orient = math3d.Matrix33Identity()
        box_pose = math3d.Matrix34(box_pos, box_orient)
        misc_util.CreateBox(edge_lengths=math3d.Vector3(0.8, 0.8, 0.8),
                            diffuse_color=gfx.Color(1.0, 0.3, 0.3, 1.0),
                            pose=box_pose)

        box_pos = math3d.Vector3(x * 5.0, 2.0, z * 5.0)
        box_orient = math3d.Matrix33Identity()
예제 #17
0
import math3d
import gfx
import stage
import stage_util

#def run():

misc_util = stage_util.CreateStageMiscUtility()

misc_util.CreateSkybox()

misc_util.CreateStaticBox(edge_lengths=math3d.Vector3(200, 1, 200),
                          diffuse_color=gfx.Color(0.50, 0.45, 0.45, 1.0),
                          pose=math3d.Matrix34(math3d.Vector3(0.0, -0.5, 0.0),
                                               math3d.Matrix33Identity()))

for x in range(-2, 3):
    for y in range(-2, 3):
        for z in range(-2, 3):
            box_pos = math3d.Vector3(x, 100 + y, z)
            #box_orient = math3d.Matrix33Identity()
            box_orient = math3d.Matrix33RotationZ(
                x) * math3d.Matrix33RotationX(z)
            box_pose = math3d.Matrix34(box_pos, box_orient)
            misc_util.CreateBox(edge_lengths=math3d.Vector3(0.8, 0.8, 0.8),
                                diffuse_color=gfx.Color(1.0, 0.5, 0.5, 1.0),
                                pose=box_pose)

#return 1	# done - release the script

#ScriptBase.SetCallback( run )
예제 #18
0
import math3d
import gfx
import stage
import stage_util
#import random

# Initialize the basic random number generator
#random.seed()

# Add a light
light_util = stage_util.CreateStageLightUtility()

dir_light = light_util.CreateHSDirectionalLightEntity(
    upper_color=gfx.Color(1.0, 1.0, 1.0, 1.0),
    lower_color=gfx.Color(0.1, 0.1, 0.1, 1.0),
    dir=math3d.Vector3(2, -3, 1))

#def run():

misc_util = stage_util.CreateStageMiscUtility()

misc_util.CreateSkybox()

# TODO: check if the floor surface have friction?

# building
misc_util.CreateEntity(name="building",
                       model="models/architecture/building.msh",
                       position=math3d.Vector3(0, 0, 0),
                       is_static=True,
                       shape="mesh")
예제 #19
0
 def test_neg(self):
     a = m3d.Vector3(100, 100, 100)
     b = -a
     self.assertEqual(b.x, -100)
     self.assertEqual(b.y, -100)
     self.assertEqual(b.z, -100)
예제 #20
0
import math3d
import gfx
import stage
import stage_util

#def run():

misc_util = stage_util.CreateStageMiscUtility()

misc_util.CreateSkybox(
    texture_path="textures/skygrad-sunny_cloudless-s1x256.jpg")

for x in range(-2, 3):
    for y in range(-2, 3):
        for z in range(-2, 3):
            box_pos = math3d.Vector3(x, 100 + y, z)
            #box_orient = math3d.Matrix33Identity()
            box_orient = math3d.Matrix33RotationZ(
                x) * math3d.Matrix33RotationX(z)
            box_pose = math3d.Matrix34(box_pos, box_orient)
            misc_util.CreateBox(edge_lengths=math3d.Vector3(0.8, 0.8, 0.8),
                                diffuse_color=gfx.Color(1.0, 0.5, 0.5, 1.0),
                                pose=box_pose)

#return 1	# done - release the script

#ScriptBase.SetCallback( run )
예제 #21
0
 def test_abs(self):
     a = m3d.Vector3(100, 0, 0)
     b = a.abs()
     self.assertEqual(b, 100)
예제 #22
0
import math3d
import gfx
import stage
import stage_util
import random

# Initialize the basic random number generator
random.seed()

# Add a light
light_util = stage_util.CreateStageLightUtility()

dir_light = light_util.CreateHSDirectionalLightEntity(
    upper_color=gfx.Color(1.0, 1.0, 1.0, 1.0),
    lower_color=gfx.Color(0.1, 0.1, 0.1, 1.0),
    dir=math3d.Vector3(2, -3, 1))

#def run():

misc_util = stage_util.CreateStageMiscUtility()

misc_util.CreateSkybox()

# terrain
terrain_05 = misc_util.CreateStaticTriangleMeshFromMesh(
    mesh_path="models/terrain/compact_003_05.msh")
terrain_06 = misc_util.CreateStaticTriangleMeshFromMesh(
    mesh_path="models/terrain/compact_003_06.msh")
terrain_09 = misc_util.CreateStaticTriangleMeshFromMesh(
    mesh_path="models/terrain/compact_003_09.msh")
terrain_15 = misc_util.CreateStaticTriangleMeshFromMesh(
예제 #23
0
import stage_util

#def run():

misc_util = stage_util.CreateStageMiscUtility()

#ground_box_pose = math3d.Matrix34( math3d.Vector3(0.0,-0.5,0.0), math3d.Matrix33Identity() )
#ground_box = misc_util.CreateStaticBox( edge_lengths = math3d.Vector3(200,1,200), diffuse_color = gfx.Color(0.7,0.7,0.7,1.0), pose=ground_box_pose )

ground_entity = misc_util.CreateStaticTriangleMeshFromMesh(
    mesh_path="models/ground.msh")
house_d00 = misc_util.CreateStaticTriangleMeshFromMesh(
    mesh_path="models/fachwerk.msh")
house_a00 = misc_util.CreateStaticTriangleMeshFromMesh(
    mesh_path="models/gerzi_house.msh",
    pose=math3d.Matrix34(math3d.Vector3(-10, 0, 16),
                         math3d.Matrix33Identity()))
house_0 = misc_util.CreateStaticTriangleMeshFromMesh(
    mesh_path="models/kosciol.msh",
    pose=math3d.Matrix34(math3d.Vector3(10, 0, 16), math3d.Matrix33Identity()))
house_3 = misc_util.CreateStaticTriangleMeshFromMesh(
    mesh_path="models/gerzi_chapel.msh",
    pose=math3d.Matrix34(math3d.Vector3(-25, 0, 20),
                         math3d.Matrix33Identity()))
house_b00 = misc_util.CreateStaticTriangleMeshFromMesh(
    mesh_path="models/fw65.msh",
    pose=math3d.Matrix34(math3d.Vector3(15, 0, 35),
                         math3d.Matrix33RotationY(1.5708)))
house_b01 = misc_util.CreateStaticTriangleMeshFromMesh(
    mesh_path="models/fw65.msh",
    pose=math3d.Matrix34(math3d.Vector3(15, 0, 45),