added very quick/basic testfile+Makefile for vectormath under PS3 Linux
This commit is contained in:
128
Extras/vectormathlibrary/Makefile
Normal file
128
Extras/vectormathlibrary/Makefile
Normal file
@@ -0,0 +1,128 @@
|
||||
# Makefile for testsuite for the PPU SIMD math library
|
||||
# Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms,
|
||||
# with or without modification, are permitted provided that the
|
||||
# following conditions are met:
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
# * Neither the name of the Sony Computer Entertainment Inc nor the names
|
||||
# of its contributors may be used to endorse or promote products derived
|
||||
# from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
TESTS = main_vmtest
|
||||
|
||||
STATIC_TESTS = $(TESTS)
|
||||
SHARED_TESTS = $(TESTS:=.shared)
|
||||
ALL_TESTS = $(STATIC_TESTS) $(SHARED_TESTS)
|
||||
|
||||
INCLUDES_PPU = -I../simdmathlibrary -Iother/rs6000
|
||||
|
||||
ARCH_PPU = 64
|
||||
CROSS_PPU = ppu-
|
||||
AR_PPU = $(CROSS_PPU)ar
|
||||
CC_PPU = $(CROSS_PPU)gcc
|
||||
CXX_PPU = $(CROSS_PPU)g++
|
||||
TEST_CMD_PPU =
|
||||
|
||||
ARCH_CFLAGS_PPU = -m$(ARCH_PPU) -maltivec -mabi=altivec
|
||||
CFLAGS_PPU = $(INCLUDES_PPU) -O2 -W -Wall $(ARCH_CFLAGS_PPU)
|
||||
STATIC_LDFLAGS_PPU = -static
|
||||
SHARED_LDFLAGS_PPU = -Wl,-rpath=..
|
||||
LDFLAGS_PPU = $(ARCH_CFLAGS_PPU) -L../simdmathlibrary/ppu -l$(LIB_BASE) -lm
|
||||
|
||||
MAKE_DEFS = \
|
||||
LIB_BASE='$(LIB_BASE)' \
|
||||
LIB_NAME='$(LIB_NAME)' \
|
||||
STATIC_LIB='$(STATIC_LIB)' \
|
||||
SHARED_LIB='$(SHARED_LIB)' \
|
||||
ARCH_PPU='$(ARCH_PPU)' \
|
||||
ARCH_CFLAGS_PPU='$(ARCH_CFLAGS_PPU)' \
|
||||
CROSS_PPU='$(CROSS_PPU)' \
|
||||
AR_PPU='$(AR_PPU)' \
|
||||
CC_PPU='$(CC_PPU)' \
|
||||
CXX_PPU='$(CXX_PPU)' \
|
||||
TEST_CMD_PPU='$(TEST_CMD_PPU)'
|
||||
|
||||
LIB_BASE = simdmath
|
||||
LIB_NAME = lib$(LIB_BASE)
|
||||
STATIC_LIB = $(LIB_NAME).a
|
||||
SHARED_LIB = $(LIB_NAME).so
|
||||
|
||||
TEST_CMD = $(TEST_CMD_PPU)
|
||||
|
||||
#COMMON_OBJS = testutils.o
|
||||
|
||||
|
||||
all: $(ALL_TESTS)
|
||||
|
||||
|
||||
$(STATIC_TESTS): %: %.o ../simdmathlibrary/ppu/$(STATIC_LIB) $(COMMON_OBJS)
|
||||
$(CC_PPU) $*.o $(COMMON_OBJS) $(LDFLAGS_PPU) $(STATIC_LDFLAGS_PPU) -o $@
|
||||
|
||||
$(SHARED_TESTS): %.shared: %.o ../simdmathlibrary/ppu/$(SHARED_LIB) $(COMMON_OBJS)
|
||||
$(CC_PPU) $*.o $(COMMON_OBJS) $(LDFLAGS_PPU) $(SHARED_LDFLAGS_PPU) -o $@
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
rm -f $(STATIC_TESTS) $(SHARED_TESTS)
|
||||
rm -f core*
|
||||
|
||||
check: $(ALL_TESTS)
|
||||
for test in $(ALL_TESTS); do \
|
||||
echo "TEST $${test}"; \
|
||||
if $(TEST_CMD) ./$${test}; then \
|
||||
pass="$$pass $$test"; \
|
||||
else \
|
||||
fail="$$fail $$test"; \
|
||||
fi \
|
||||
done; \
|
||||
echo; echo "PASS:$$pass"; echo "FAIL:$$fail"; \
|
||||
test -z "$$fail"
|
||||
|
||||
static_check:
|
||||
$(MAKE) $(MAKE_DEFS) ALL_TESTS="$(STATIC_TESTS)" check
|
||||
|
||||
shared_check:
|
||||
$(MAKE) $(MAKE_DEFS) ALL_TESTS="$(SHARED_TESTS)" check
|
||||
|
||||
../$(STATIC_LIB):
|
||||
cd ../;$(MAKE) $(MAKE_DEFS) $(STATIC_LIB)
|
||||
|
||||
../$(SHARED_LIB):
|
||||
cd ../;$(MAKE) $(MAKE_DEFS) $(SHARED_LIB)
|
||||
|
||||
%.o: %.c common-test.h testutils.h
|
||||
$(CC_PPU) $(CFLAGS_PPU) -c $<
|
||||
|
||||
#----------
|
||||
# C++
|
||||
#----------
|
||||
%.o: %.C
|
||||
$(CXX_PPU) $(CFLAGS_PPU) -c $<
|
||||
|
||||
%.o: %.cpp
|
||||
$(CXX_PPU) $(CFLAGS_PPU) -c $<
|
||||
|
||||
%.o: %.cc
|
||||
$(CXX_PPU) $(CFLAGS_PPU) -c $<
|
||||
|
||||
%.o: %.cxx
|
||||
$(CXX_PPU) $(CFLAGS_PPU) -c $<
|
||||
|
||||
163
Extras/vectormathlibrary/main_vmtest.cpp
Normal file
163
Extras/vectormathlibrary/main_vmtest.cpp
Normal file
@@ -0,0 +1,163 @@
|
||||
|
||||
///Testfile to test differences between vectormath and Bullet LinearMath
|
||||
|
||||
#ifdef __PPU__
|
||||
#include "include/vectormath/ppu/cpp/vectormath_aos.h"
|
||||
#elif defined __SPU__
|
||||
#include "include/vectormath/spu/cpp/vectormath_aos.h"
|
||||
#else
|
||||
#include "include/vectormath/SSE/cpp/vectormath_aos.h"
|
||||
//#include "include/vectormath/scalar/cpp/vectormath_aos.h"
|
||||
#endif
|
||||
|
||||
#include "../../src/LinearMath/btTransform.h"
|
||||
#include <stdio.h>
|
||||
|
||||
//Bullet, a btVector can be used for both points and vectors.
|
||||
//it is up to the user/developer to use the right multiplication: btTransform for points, and btQuaternion or btMatrix3x3 for vectors.
|
||||
void BulletTest()
|
||||
{
|
||||
|
||||
printf("Bullet Linearmath\n");
|
||||
|
||||
btTransform tr;
|
||||
tr.setIdentity();
|
||||
|
||||
tr.setOrigin(btVector3(10,0,0));
|
||||
//initialization
|
||||
btVector3 pointA(0,0,0);
|
||||
btVector3 pointB,pointC,pointD,pointE;
|
||||
//assignment
|
||||
pointB = pointA;
|
||||
//in-place initialization
|
||||
pointB.setValue(1,2,3);
|
||||
//transform over tr
|
||||
pointB = tr * pointA;
|
||||
printf("pointB = tr * pointA = (%f,%f,%f)\n",pointB.getX(),pointB.getY(),pointB.getZ());
|
||||
//transform over tr
|
||||
pointE = tr(pointA);
|
||||
//inverse transform
|
||||
pointC = tr.inverse() * pointA;
|
||||
printf("pointC = tr.inverse() * pointA = (%f,%f,%f)\n",pointC.getX(),pointC.getY(),pointC.getZ());
|
||||
//inverse transform
|
||||
pointD = tr.invXform( pointA );
|
||||
btScalar x;
|
||||
//dot product
|
||||
x = pointD.dot(pointE);
|
||||
//square length
|
||||
x = pointD.length2();
|
||||
//length
|
||||
x = pointD.length();
|
||||
|
||||
const btVector3& constPointD = pointD;
|
||||
|
||||
//get a normalized vector from constPointD, without changing constPointD
|
||||
btVector3 norm = constPointD.normalized();
|
||||
|
||||
//in-place normalize pointD
|
||||
pointD.normalize();
|
||||
|
||||
//quaternions & matrices
|
||||
btQuaternion quat(0,0,0,1);
|
||||
btQuaternion quat1(btVector3(0,1,0),90.f * SIMD_RADS_PER_DEG);
|
||||
btMatrix3x3 mat0(quat1);
|
||||
btMatrix3x3 mat1 = mat0.inverse();
|
||||
btMatrix3x3 mat2 = mat0.transpose();
|
||||
btTransform tr1(mat2,btVector3(0,10,0));
|
||||
btTransform tr2 =tr1.inverse();
|
||||
btVector3 pt0(1,1,1);
|
||||
btVector3 pt1 = tr2 * pt0;
|
||||
|
||||
printf("btVector3 pt1 = tr2 * pt0 = (%f,%f,%f)\n",pt1.getX(),pt1.getY(),pt1.getZ());
|
||||
|
||||
|
||||
btVector3 pt2 = tr2.getBasis() * pt0;
|
||||
btVector3 pt3 = pt0 * tr2.getBasis();
|
||||
btVector3 pt4 = tr2.getBasis().inverse() * pt0;
|
||||
btTransform tr3 = tr2.inverseTimes(tr2);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
//vectormath makes a difference between point and vector.
|
||||
void VectormathTest()
|
||||
{
|
||||
|
||||
printf("Vectormath\n");
|
||||
|
||||
Vectormath::Aos::Transform3 tr;
|
||||
tr = Vectormath::Aos::Transform3::identity();
|
||||
|
||||
tr.setTranslation(Vectormath::Aos::Vector3(10,0,0));
|
||||
//initialization
|
||||
Vectormath::Aos::Point3 pointA(0,0,0);
|
||||
Vectormath::Aos::Point3 pointB,pointC,pointE;
|
||||
Vectormath::Aos::Vector3 pointD;
|
||||
//assignment
|
||||
pointB = pointA;
|
||||
//in-place initialization
|
||||
pointB = Vectormath::Aos::Point3(1,2,3); //or
|
||||
pointB.setElem(0,1); //or
|
||||
pointB.setX(1);
|
||||
|
||||
//transform over tr
|
||||
pointB = tr * pointA;
|
||||
|
||||
printf("pointB = tr * pointA = (%f,%f,%f)\n",(float)pointB.getX(),(float)pointB.getY(),(float)pointB.getZ());
|
||||
//transform over tr
|
||||
//pointE = tr(pointA);
|
||||
//inverse transform
|
||||
pointC = Vectormath::Aos::inverse(tr) * pointA;
|
||||
printf("Vectormath::Aos::inverse(tr) * pointA = (%f,%f,%f)\n",(float)pointC.getX(),(float)pointC.getY(),(float)pointC.getZ());
|
||||
|
||||
|
||||
|
||||
btScalar x;
|
||||
//dot product
|
||||
x = Vectormath::Aos::dot(Vectormath::Aos::Vector3(pointD),Vectormath::Aos::Vector3(pointE));
|
||||
//square length
|
||||
x = Vectormath::Aos::lengthSqr(Vectormath::Aos::Vector3(pointD));
|
||||
//length
|
||||
x = Vectormath::Aos::length(Vectormath::Aos::Vector3(pointD));
|
||||
|
||||
const Vectormath::Aos::Vector3& constPointD = (Vectormath::Aos::Vector3&)pointD;
|
||||
|
||||
//get a normalized vector from constPointD, without changing constPointD
|
||||
Vectormath::Aos::Vector3 norm = Vectormath::Aos::normalize(constPointD);
|
||||
|
||||
//in-place normalize pointD
|
||||
pointD = Vectormath::Aos::normalize(Vectormath::Aos::Vector3(pointD));
|
||||
|
||||
//quaternions & matrices
|
||||
Vectormath::Aos::Quat quat(0,0,0,1);
|
||||
Vectormath::Aos::Quat quat1;
|
||||
quat1 = Vectormath::Aos::Quat::rotationY(90.f * SIMD_RADS_PER_DEG);
|
||||
|
||||
Vectormath::Aos::Matrix3 mat0(quat1);
|
||||
|
||||
Vectormath::Aos::Matrix3 mat1 = Vectormath::Aos::inverse(mat0);
|
||||
Vectormath::Aos::Matrix3 mat2 = Vectormath::Aos::transpose(mat0);
|
||||
Vectormath::Aos::Transform3 tr1(mat2,Vectormath::Aos::Vector3(0,10,0));
|
||||
Vectormath::Aos::Transform3 tr2 = Vectormath::Aos::inverse(tr1);
|
||||
Vectormath::Aos::Point3 pt0(1,1,1);
|
||||
Vectormath::Aos::Point3 pt1 = tr2 * pt0;
|
||||
printf("Vectormath::Aos::Vector3 pt1 = tr2 * pt0; = (%f,%f,%f)\n",(float)pt1.getX(),(float)pt1.getY(),(float)pt1.getZ());
|
||||
|
||||
Vectormath::Aos::Vector3 pt2 = tr2.getUpper3x3() * Vectormath::Aos::Vector3(pt0);
|
||||
//Vectormath::Aos::Vector3 pt3 = pt0 * tr2.getUpper3x3();
|
||||
Vectormath::Aos::Vector3 pt3 = Vectormath::Aos::inverse(tr2.getUpper3x3()) * Vectormath::Aos::Vector3(pt0);
|
||||
Vectormath::Aos::Vector3 pt4 = Vectormath::Aos::inverse(tr2.getUpper3x3()) * Vectormath::Aos::Vector3(pt0);
|
||||
Vectormath::Aos::Transform3 tr3 = Vectormath::Aos::inverse(tr2) * tr2;
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
BulletTest();
|
||||
|
||||
VectormathTest();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user