* New demo showing an OpenGL animated Haiku logo. Could be a good base for

future 3d demos i have in mind and the missing ones (ie: 3dmov and 3dmix).
 Makes for a nice Haiku sample code too, without legacy.
 Not in the image yet, waiting for the green light. Enjoy!

 ps: Will commit the Blender object files and export script later.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32027 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Alexandre Deckner
2009-07-31 15:38:12 +00:00
parent 9c1f8bf0c7
commit bee3c7a915
38 changed files with 3430 additions and 0 deletions
+1
View File
@@ -22,6 +22,7 @@ HaikuSubInclude expander ;
HaikuSubInclude fontdemo ;
HaikuSubInclude glteapot ;
HaikuSubInclude gradients ;
HaikuSubInclude haiku3d ;
HaikuSubInclude icon-o-matic ;
HaikuSubInclude installedpackages ;
HaikuSubInclude installer ;
+49
View File
@@ -0,0 +1,49 @@
/*
* Copyright 2009, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Alexandre Deckner <[email protected]>
*/
#include <Alert.h>
#include "App.h"
#include "MainWindow.h"
App::App()
:
BApplication("application/x-vnd.Haiku3d")
{
BRect frame(50, 50, 640 + 50, 480 + 50);
const char *title = "Hauku3d";
fMainWindow = new MainWindow(frame, title);
}
App::~App()
{
}
void App::AboutRequested()
{
BAlert* alert;
alert = new BAlert("About", "A little 3d demo", "ok");
alert->Go(NULL);
}
void App::MessageReceived(BMessage *message)
{
}
int
main(int argc, char** argv)
{
App app;
app.Run();
return 0;
}
+26
View File
@@ -0,0 +1,26 @@
/*
* Copyright 2008, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Alexandre Deckner <[email protected]>
*/
#ifndef _APP_H
#define _APP_H
#include <Application.h>
class App: public BApplication {
protected:
BWindow* fMainWindow;
public:
App();
~App();
virtual void AboutRequested();
virtual void MessageReceived(BMessage *message);
};
#endif /* _APP_H */
+26
View File
@@ -0,0 +1,26 @@
/*
* Copyright 2008, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Alexandre Deckner <[email protected]>
*/
#include "Camera.h"
Camera::Camera(const Vector3& position, const Quaternion& orientation,
float fov, float near, float far)
:
fPosition(position),
fOrientation(orientation),
fFieldOfView(fov),
fNear(near),
fFar(far)
{
}
Camera::~Camera()
{
}
+72
View File
@@ -0,0 +1,72 @@
/*
* Copyright 2009, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Alexandre Deckner <[email protected]>
*/
#ifndef _CAMERA_H
#define _CAMERA_H
#include "Vector3.h"
#include "Quaternion.h"
class Camera {
public:
Camera(const Vector3& position,
const Quaternion& orientation, float fov = 50.0f, float near = 1.0f,
float far = 100.0f);
virtual ~Camera();
const Vector3& Position() const;
const Quaternion& Orientation() const;
float FieldOfView() const;
float Near() const;
float Far() const;
protected:
Vector3 fPosition;
Quaternion fOrientation;
float fFieldOfView;
float fNear;
float fFar;
bool fOrtho;
};
inline const Vector3&
Camera::Position() const
{
return fPosition;
}
inline const Quaternion&
Camera::Orientation() const
{
return fOrientation;
}
inline float
Camera::FieldOfView() const
{
return fFieldOfView;
}
inline float
Camera::Near() const
{
return fNear;
}
inline float
Camera::Far() const
{
return fFar;
}
#endif /* _CAMERA_H */
+89
View File
@@ -0,0 +1,89 @@
/*
* Copyright 2009, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Alexandre Deckner [email protected]
*
* Copyright Be, Inc. (for the temporary icon)
*/
resource(1, "BEOS:APP_SIG") #'MIMS' "application/x-vnd.Haiku3d";
resource app_version {
major = 1,
middle = 0,
minor = 0,
variety = B_APPV_BETA,
internal = 0,
short_info = "Haiku3d",
long_info = "Haiku3d ©2009 Haiku, Inc."
};
resource(101, "BEOS:L:STD_ICON") #'ICON' array {
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00FFFFFFFFFFFFFFFFFF"
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF005D00FFFFFFFFFFFFFFFF"
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF005D5D00FFFFFFFFFFFFFFFF"
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF005D5D5D00FFFFFFFFFFFFFFFF"
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF003F5D5D5D5D00FFFFFFFFFFFFFF"
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF003F5D5D5D5D00FFFFFFFFFFFFFF"
$"FFFFFFFF000000FFFFFFFFFFFFFFFFFFFF00FA3F5D5D5D5D5D00FFFFFFFFFFFF"
$"FFFFFF005E5E5E0000FFFFFFFFFFFFFFFF00FA3F5D5D5D5D5D00FFFFFFFFFFFF"
$"FFFF005E5E5E5E5E5E0000FFFFFFFFFF00FAFA3F5D5D5D5D5D00FFFFFFFFFFFF"
$"FF005E5E5E5E5E5E5E5E5E00FFFFFFFF00FAFAFA3F5D5D5D5D5D00FFFFFFFFFF"
$"005E5E5E5E5E5E5E5E5EB200FFFFFF00FAFAFAFA3F5D5D5D5D5D00FFFFFFFFFF"
$"00B2B25E5E5E5E5E5EB22100FFFF00FAFAFAFAFA3F5D5D5D5D5D5D00FFFFFFFF"
$"002121B2B25E5E5EB2212400FFFF00FAFAFAFAFAFA3F5D5D5D5D5D00FFFFFFFF"
$"0021212021B2B2B221242500FF00FAFAFAFAFAFAFA3F5D5D5D5D5D5D00FFFFFF"
$"002121202121BE2124252500FF00FAFAFAFAFAFAFAFA3F5D5D5D5D5D00FFFFFF"
$"002121202121BE212425250000FAFAFAFAFAFAFAFAFA3F5D5D5D5D5D00FFFFFF"
$"002121202121BE212425250000FAFAFAFAFAFAFAFAFA3F5D5D5D5D5D5D00FFFF"
$"002121202121BE2124252500FF0000FAFAFA00000000003F5D5D5D5D5D0011FF"
$"002121202121BE2124252500FFFFFF0000002FEB2F302F00005D5D5D5D001111"
$"002121202121BE2124252500FFFFFF002F2B2B2B2D2D2F302F005D5D00111111"
$"002121202121BE2124252500FFFF002F2B2A2B2A2C2C2BEB2F2F0000111111FF"
$"002121202121BE2124252500FFFF002B2B2B2A2B2B2B2D2D2F2F00111111FFFF"
$"002121202121BE2124252500FF002F2B2B2A5A2B2B2B2C2D2DEB3000FFFFFFFF"
$"002121202121BE212425250011002F2B2B5A3F5A2B2C2C2D2D2F2F00FFFFFFFF"
$"002121202121BE212425250011002F2C2C2A5A2C2B2C2C2DEB2F2F00FFFFFFFF"
$"002121202121BE21242500111100302E2B2C2B2B2C2C2D2CEB2F2F0011FFFFFF"
$"FF0000212120BE2124001111FF002F2F2D2C2C2C2C2D2D2E2EEB30001111FFFF"
$"FFFFFF000021BE21001111FFFFFF00302D2D2D2C2D2DEBEB2F2F00111111FFFF"
$"FFFFFFFFFF0000001111FFFFFFFF00302EEBEBEBEBEBEB2FEB3000111111FFFF"
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00302F2FEB2FEB2F2F2F0011111111FFFF"
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000302F2F302F000011111111FFFFFF"
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000011111111FFFFFFFFFF"
};
resource(101, "BEOS:M:STD_ICON") #'MICN' array {
$"FFFFFFFFFFFFFFFFFFFFFF0000FFFFFF"
$"FFFFFFFFFFFFFFFFFFFF005D5D00FFFF"
$"FFFF000000FFFFFFFF005D5D5D00FFFF"
$"FF005E5E5E00FFFF00FA5D5D5D00FFFF"
$"005E5E5E5E5E00FF00FAFA5D5D5D00FF"
$"00215E5E5E250000FAFAFA5D5D5D00FF"
$"0021212025250000FAFAFA5D5D5D5D00"
$"00202121242500FAFAFAFAFA5D5D5D00"
$"00212021252400FAFA000000005D5D00"
$"00212120252500FA002B2D2F30000000"
$"00202121242500002B2B2B2D2D2F0011"
$"00212021252400002B5A2C2C2D2F00FF"
$"00212120250000002D2B2B2D2D2F0011"
$"00002120001111002F2E2C2E2E2F0011"
$"FFFF00001111FFFF0030EB2F2F001111"
$"FFFFFFFFFFFFFFFFFF00000000111111"
};
resource(1, "texture") #'PNG ' import "./data/texture.png";
resource(2, "LetterH") import "./data/LetterH.hk3d.bin";
resource(3, "LetterA") import "./data/LetterA.hk3d.bin";
resource(4, "LetterI") import "./data/LetterI.hk3d.bin";
resource(5, "LetterK") import "./data/LetterK.hk3d.bin";
resource(6, "LetterU") import "./data/LetterU.hk3d.bin";
+27
View File
@@ -0,0 +1,27 @@
SubDir HAIKU_TOP src apps haiku3d ;
SEARCH_SOURCE += [ FDirName $(SUBDIR) mesh ] ;
SEARCH_SOURCE += [ FDirName $(SUBDIR) texture ] ;
UsePrivateHeaders shared ;
Application Haiku3d :
App.cpp
Camera.cpp
MainWindow.cpp
MathUtils.cpp
Mesh.cpp
MeshInstance.cpp
RenderView.cpp
Texture.cpp
# mesh
StaticMesh.cpp
# texture
BitmapTexture.cpp
VideoFileTexture.cpp
: be game GL media translation
: Haiku3d.rdef
;
+60
View File
@@ -0,0 +1,60 @@
/*
* Copyright 2009, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Alexandre Deckner <[email protected]>
*/
#include "MainWindow.h"
#include "RenderView.h"
#include <Application.h>
#include <MenuBar.h>
#include <MenuItem.h>
#include <stdio.h>
MainWindow::MainWindow(BRect frame, const char* title)
:
BDirectWindow(frame, title, B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, 0)
{
fRenderView = new RenderView(Bounds());
fRenderView->SetViewColor(0, 0, 0);
AddChild(fRenderView);
Show();
}
MainWindow::~MainWindow()
{
}
bool
MainWindow::QuitRequested()
{
be_app->Lock();
if (be_app->CountWindows() < 2)
be_app_messenger.SendMessage(B_QUIT_REQUESTED);
be_app->Unlock();
return true;
}
void
MainWindow::MessageReceived(BMessage *message)
{
switch (message->what) {
default:
BDirectWindow::MessageReceived(message);
}
}
void
MainWindow::DirectConnected(direct_buffer_info* info)
{
fRenderView->DirectConnected(info);
}
+28
View File
@@ -0,0 +1,28 @@
/*
* Copyright 2009, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Alexandre Deckner <[email protected]>
*/
#ifndef _MAINWINDOW_H
#define _MAINWINDOW_H
#include <DirectWindow.h>
class RenderView;
class MainWindow: public BDirectWindow {
public:
MainWindow(BRect frame, const char* title);
~MainWindow();
virtual bool QuitRequested();
virtual void MessageReceived(BMessage *message);
virtual void DirectConnected(direct_buffer_info* info);
protected:
RenderView* fRenderView;
};
#endif /* _MAINWINDOW_H */
+55
View File
@@ -0,0 +1,55 @@
/*
* Copyright 2008, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Alexandre Deckner <[email protected]>
*/
// Some math utils, useful for animation
#include "MathUtils.h"
float
MathUtils::EaseInOutCubic(float t /*time*/, float b /*begin*/, float c /*distance*/, float d /*duration*/)
{
t /= d / 2.0;
if (t < 1.0)
return c / 2.0 * t * t * t + b;
t -= 2.0;
return c / 2.0 * (t * t * t + 2.0) + b;
}
float
MathUtils::EaseInOutQuart(float t /*time*/, float b /*begin*/, float c /*distance*/, float d /*duration*/)
{
t /= d / 2;
if (t < 1)
return c / 2 * t * t * t * t + b;
t -= 2;
return -c / 2 * (t * t * t * t - 2) + b;
}
float
MathUtils::EaseInOutQuint(float t /*time*/, float b /*begin*/, float c /*distance*/, float d /*duration*/)
{
t /= d / 2;
if (t < 1)
return c / 2 * t * t * t * t * t + b;
t -= 2;
return c / 2 *(t * t * t * t * t + 2) + b;
}
float
MathUtils::EaseInOutSine(float t /*time*/, float b /*begin*/, float c /*distance*/, float d /*duration*/)
{
return -c / 2 * (cos(3.14159 * t / d) - 1) + b;
}
+21
View File
@@ -0,0 +1,21 @@
/*
* Copyright 2009, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Alexandre Deckner <[email protected]>
*/
#ifndef _MATH_UTILS_H
#define _MATH_UTILS_H
class MathUtils
{
public:
static float EaseInOutCubic(float time, float begin, float distance, float duration);
static float EaseInOutQuart(float time, float begin, float distance, float duration);
static float EaseInOutQuint(float time, float begin, float distance, float duration);
static float EaseInOutSine(float time, float begin, float distance, float duration);
};
#endif /* _MATH_UTILS_H */
+14
View File
@@ -0,0 +1,14 @@
/*
* Copyright 2009, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Alexandre Deckner <[email protected]>
*/
#include "Mesh.h"
Mesh::~Mesh()
{
}
+39
View File
@@ -0,0 +1,39 @@
/*
* Copyright 2009, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Alexandre Deckner <[email protected]>
*/
#ifndef _MESH_H
#define _MESH_H
#include <Referenceable.h>
#include <SupportDefs.h>
#include "Vector3.h"
struct Vertex {
Vector3 p;
float u;
float v;
};
struct Face {
Vertex v[4];
uint16 vertexCount;
};
class Mesh : public Referenceable {
public:
virtual ~Mesh();
virtual Face& GetFace(uint32 index) const = 0;
virtual uint32 FaceCount() const = 0;
};
#endif /* _MESH_H */
+183
View File
@@ -0,0 +1,183 @@
/*
* Copyright 2008, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Alexandre Deckner <[email protected]>
*/
#include "MeshInstance.h"
#include "MathUtils.h"
#include <opengl/GL/gl.h>
//#include <stdio.h> // debug
MeshInstance::MeshInstance(Mesh* mesh, Texture* texture,
const Vector3& position, const Quaternion& orientation, float animOffset)
:
fMeshReference(mesh),
fTextureReference(texture),
fPosition(position),
fOrientation(orientation),
fScale(1.0f),
fTime(0.0f),
fAnimOffset(animOffset),
fDoubleSided(true),
fDrawNormals(false)
{
}
MeshInstance::~MeshInstance()
{
}
void
MeshInstance::Update(float dt)
{
fTextureReference->Update(dt);
float animDuration = 4.0f;
fTime += dt;
if (fTime >= fAnimOffset) {
float animTime = (fTime - fAnimOffset);
float rotAngle = MathUtils::EaseInOutQuart(animTime, 0,
3 * 2 * 3.14159, animDuration);
fOrientation = Quaternion(Vector3(0.0f, 1.0f, 0.0f), rotAngle);
}
if (fTime >= fAnimOffset + animDuration) {
fOrientation = Quaternion(Vector3(0.0f, 1.0f, 0.0f), 0.0);
}
if (fTime >= animDuration * 6) {
fTime = 0.0;
}
}
void
MeshInstance::Render()
{
if (fMeshReference->FaceCount() == 0)
return;
glPushMatrix();
glTranslatef(fPosition.x(), fPosition.y(), fPosition.z());
float mat[4][4];
fOrientation.toOpenGLMatrix(mat);
glMultMatrixf((GLfloat*) mat);
glScalef(fScale, fScale, fScale);
glBindTexture(GL_TEXTURE_2D, fTextureReference->Id());
int lastVertexCount = 0;
//int batchCount = 0;
for(uint32 i = 0; i < fMeshReference->FaceCount(); i++) {
const Face& face = fMeshReference->GetFace(i);
// switch face mode
if (face.vertexCount != lastVertexCount) {
if (lastVertexCount != 0)
glEnd();
if (face.vertexCount == 3)
glBegin(GL_TRIANGLES);
else
glBegin(GL_QUADS);
//batchCount++;
}
// calculate normal
Vector3 lu(face.v[0].p - face.v[1].p);
Vector3 lv(face.v[1].p - face.v[2].p);
Vector3 normal(lu.cross(lv));
if (normal.length() <= 0.000001)
normal.setValue(0, 0, -1.0);
normal.normalize();
// draw face
glNormal3f(normal.x(), normal.y(), normal.z());
glTexCoord2f(face.v[0].u, face.v[0].v);
glVertex3f(face.v[0].p.x(), face.v[0].p.y(), face.v[0].p.z());
glNormal3f(normal.x(), normal.y(), normal.z());
glTexCoord2f(face.v[1].u, face.v[1].v);
glVertex3f(face.v[1].p.x(), face.v[1].p.y(), face.v[1].p.z());
glNormal3f(normal.x(), normal.y(), normal.z());
glTexCoord2f(face.v[2].u, face.v[2].v);
glVertex3f(face.v[2].p.x(), face.v[2].p.y(), face.v[2].p.z());
if (face.vertexCount == 4) {
glNormal3f(normal.x(), normal.y(), normal.z());
glTexCoord2f(face.v[3].u, face.v[3].v);
glVertex3f(face.v[3].p.x(), face.v[3].p.y(), face.v[3].p.z());
}
if (fDoubleSided) {
if (face.vertexCount == 4) {
glNormal3f(-normal.x(), -normal.y(), -normal.z());
glTexCoord2f(face.v[3].u, face.v[3].v);
glVertex3f(face.v[3].p.x(), face.v[3].p.y(), face.v[3].p.z());
}
glNormal3f(-normal.x(), -normal.y(), -normal.z());
glTexCoord2f(face.v[2].u, face.v[2].v);
glVertex3f(face.v[2].p.x(), face.v[2].p.y(), face.v[2].p.z());
glNormal3f(-normal.x(), -normal.y(), -normal.z());
glTexCoord2f(face.v[1].u, face.v[1].v);
glVertex3f(face.v[1].p.x(), face.v[1].p.y(), face.v[1].p.z());
glNormal3f(-normal.x(), -normal.y(), -normal.z());
glTexCoord2f(face.v[0].u, face.v[0].v);
glVertex3f(face.v[0].p.x(), face.v[0].p.y(), face.v[0].p.z());
}
lastVertexCount = face.vertexCount;
}
glEnd();
//printf("batchCount %d\n", batchCount);
if (fDrawNormals) {
glBegin(GL_LINES);
for(uint32 i = 0; i < fMeshReference->FaceCount(); i++) {
const Face& face = fMeshReference->GetFace(i);
if (face.vertexCount == 4) {
// calculate normal
Vector3 lu(face.v[0].p - face.v[1].p);
Vector3 lv(face.v[1].p - face.v[2].p);
Vector3 normal(lu.cross(lv));
if (normal.length() <= 0.000001)
normal.setValue(0, 0, -1.0);
normal.normalize();
// center of the face
Vector3 g;
if (face.vertexCount == 4)
g = (face.v[0].p + face.v[1].p + face.v[2].p + face.v[3].p)
/ 4.0;
else
g = (face.v[0].p + face.v[1].p + face.v[2].p) / 3.0;
Vector3 h(g + normal);
glVertex3f(g.x(), g.y(), g.z());
glVertex3f(h.x(), h.y(), h.z());
}
}
glEnd();
}
glPopMatrix();
}
+44
View File
@@ -0,0 +1,44 @@
/*
* Copyright 2009, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Alexandre Deckner <alex@zappotek.com>
*/
#ifndef _MESH_INSTANCE_H
#define _MESH_INSTANCE_H
#include "Mesh.h"
#include "Texture.h"
#include "Vector3.h"
#include "Quaternion.h"
class MeshInstance {
public:
MeshInstance(Mesh* mesh, Texture* texture,
const Vector3& position, const Quaternion& orientation,
float animOffset);
~MeshInstance();
void Update(float dt);
void Render();
protected:
Reference<Mesh> fMeshReference;
Reference<Texture> fTextureReference;
Vector3 fPosition;
Quaternion fOrientation;
float fScale;
// TODO: manage the animation externally
float fTime;
float fAnimOffset;
bool fDoubleSided;
bool fDrawNormals;
};
#endif /* _MESH_INSTANCE_H */
+407
View File
@@ -0,0 +1,407 @@
/*
* Copyright 2008 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Alexandre Deckner
*
*/
/*
*
* This is a refactored and stripped down version of bullet-2.66 src\LinearMath\btQuaternion.h
* The dependancies on base class btQuadWord have been removed for simplification.
* Added gl matrix conversion method.
*
*/
/*
Copyright (c) 2003-2006 Gino van den Bergen / Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef __QUATERNION_H__
#define __QUATERNION_H__
#include "Vector3.h"
#include <SupportDefs.h> //pout FLT_EPSILON
class Quaternion {
protected:
float m_x;
float m_y;
float m_z;
float m_w;
public:
Quaternion() {}
Quaternion(const Quaternion& q)
{
*((Quaternion*)this) = q;
}
Quaternion(const float& x, const float& y, const float& z,const float& w)
{
m_x = x, m_y = y, m_z = z, m_w = w;
}
Quaternion(const Vector3& axis, const float& angle)
{
setRotation(axis, angle);
}
Quaternion(const float& yaw, const float& pitch, const float& roll)
{
setEuler(yaw, pitch, roll);
}
inline const float& x() const { return m_x; }
inline const float& y() const { return m_y; }
inline const float& z() const { return m_z; }
inline const float& w() const { return m_w; }
void setValue(const float& x, const float& y, const float& z)
{
m_x=x;
m_y=y;
m_z=z;
m_w = 0.f;
}
void setValue(const float& x, const float& y, const float& z,const float& w)
{
m_x=x;
m_y=y;
m_z=z;
m_w=w;
}
void setRotation(const Vector3& axis, const float& angle)
{
float d = axis.length();
assert(d != 0.0f);
float s = sin(angle * 0.5f) / d;
setValue(axis.x() * s, axis.y() * s, axis.z() * s,
cos(angle * 0.5f));
}
void setEuler(const float& yaw, const float& pitch, const float& roll)
{
float halfYaw = yaw * 0.5f;
float halfPitch = pitch * 0.5f;
float halfRoll = roll * 0.5f;
float cosYaw = cos(halfYaw);
float sinYaw = sin(halfYaw);
float cosPitch = cos(halfPitch);
float sinPitch = sin(halfPitch);
float cosRoll = cos(halfRoll);
float sinRoll = sin(halfRoll);
setValue(cosRoll * sinPitch * cosYaw + sinRoll * cosPitch * sinYaw,
cosRoll * cosPitch * sinYaw - sinRoll * sinPitch * cosYaw,
sinRoll * cosPitch * cosYaw - cosRoll * sinPitch * sinYaw,
cosRoll * cosPitch * cosYaw + sinRoll * sinPitch * sinYaw);
}
Quaternion& operator+=(const Quaternion& q)
{
m_x += q.x(); m_y += q.y(); m_z += q.z(); m_w += q.m_w;
return *this;
}
Quaternion& operator-=(const Quaternion& q)
{
m_x -= q.x(); m_y -= q.y(); m_z -= q.z(); m_w -= q.m_w;
return *this;
}
Quaternion& operator*=(const float& s)
{
m_x *= s; m_y *= s; m_z *= s; m_w *= s;
return *this;
}
Quaternion& operator*=(const Quaternion& q)
{
setValue(m_w * q.x() + m_x * q.m_w + m_y * q.z() - m_z * q.y(),
m_w * q.y() + m_y * q.m_w + m_z * q.x() - m_x * q.z(),
m_w * q.z() + m_z * q.m_w + m_x * q.y() - m_y * q.x(),
m_w * q.m_w - m_x * q.x() - m_y * q.y() - m_z * q.z());
return *this;
}
float dot(const Quaternion& q) const
{
return m_x * q.x() + m_y * q.y() + m_z * q.z() + m_w * q.m_w;
}
float length2() const
{
return dot(*this);
}
float length() const
{
return sqrt(length2());
}
Quaternion& normalize()
{
return *this /= length();
}
inline Quaternion
operator*(const float& s) const
{
return Quaternion(x() * s, y() * s, z() * s, m_w * s);
}
Quaternion operator/(const float& s) const
{
assert(s != 0.0f);
return *this * (1.0f / s);
}
Quaternion& operator/=(const float& s)
{
assert(s != 0.0f);
return *this *= 1.0f / s;
}
Quaternion normalized() const
{
return *this / length();
}
float angle(const Quaternion& q) const
{
float s = sqrt(length2() * q.length2());
assert(s != 0.0f);
return acos(dot(q) / s);
}
float getAngle() const
{
float s = 2.0f * acos(m_w);
return s;
}
Quaternion inverse() const
{
return Quaternion(m_x, m_y, m_z, -m_w);
}
inline Quaternion
operator+(const Quaternion& q2) const
{
const Quaternion& q1 = *this;
return Quaternion(q1.x() + q2.x(), q1.y() + q2.y(), q1.z() + q2.z(), q1.m_w + q2.m_w);
}
inline Quaternion
operator-(const Quaternion& q2) const
{
const Quaternion& q1 = *this;
return Quaternion(q1.x() - q2.x(), q1.y() - q2.y(), q1.z() - q2.z(), q1.m_w - q2.m_w);
}
inline Quaternion operator-() const
{
const Quaternion& q2 = *this;
return Quaternion( - q2.x(), - q2.y(), - q2.z(), - q2.m_w);
}
inline Quaternion farthest( const Quaternion& qd) const
{
Quaternion diff,sum;
diff = *this - qd;
sum = *this + qd;
if( diff.dot(diff) > sum.dot(sum) )
return qd;
return (-qd);
}
Quaternion slerp(const Quaternion& q, const float& t) const
{
float theta = angle(q);
if (theta != 0.0f)
{
float d = 1.0f / sin(theta);
float s0 = sin((1.0f - t) * theta);
float s1 = sin(t * theta);
return Quaternion((m_x * s0 + q.x() * s1) * d,
(m_y * s0 + q.y() * s1) * d,
(m_z * s0 + q.z() * s1) * d,
(m_w * s0 + q.m_w * s1) * d);
}
else
{
return *this;
}
}
void toOpenGLMatrix(float m[4][4]){
float wx, wy, wz, xx, yy, yz, xy, xz, zz, x2, y2, z2;
// calculate coefficients
x2 = m_x + m_x; y2 = m_y + m_y;
z2 = m_z + m_z;
xx = m_x * x2; xy = m_x * y2; xz = m_x * z2;
yy = m_y * y2; yz = m_y * z2; zz = m_z * z2;
wx = m_w * x2; wy = m_w * y2; wz = m_w * z2;
m[0][0] = 1.0 - (yy + zz); m[1][0] = xy - wz;
m[2][0] = xz + wy; m[3][0] = 0.0;
m[0][1] = xy + wz; m[1][1] = 1.0 - (xx + zz);
m[2][1] = yz - wx; m[3][1] = 0.0;
m[0][2] = xz - wy; m[1][2] = yz + wx;
m[2][2] = 1.0 - (xx + yy); m[3][2] = 0.0;
m[0][3] = 0; m[1][3] = 0;
m[2][3] = 0; m[3][3] = 1;
}
};
inline Quaternion
operator-(const Quaternion& q)
{
return Quaternion(-q.x(), -q.y(), -q.z(), -q.w());
}
inline Quaternion
operator*(const Quaternion& q1, const Quaternion& q2) {
return Quaternion(q1.w() * q2.x() + q1.x() * q2.w() + q1.y() * q2.z() - q1.z() * q2.y(),
q1.w() * q2.y() + q1.y() * q2.w() + q1.z() * q2.x() - q1.x() * q2.z(),
q1.w() * q2.z() + q1.z() * q2.w() + q1.x() * q2.y() - q1.y() * q2.x(),
q1.w() * q2.w() - q1.x() * q2.x() - q1.y() * q2.y() - q1.z() * q2.z());
}
inline Quaternion
operator*(const Quaternion& q, const Vector3& w)
{
return Quaternion( q.w() * w.x() + q.y() * w.z() - q.z() * w.y(),
q.w() * w.y() + q.z() * w.x() - q.x() * w.z(),
q.w() * w.z() + q.x() * w.y() - q.y() * w.x(),
-q.x() * w.x() - q.y() * w.y() - q.z() * w.z());
}
inline Quaternion
operator*(const Vector3& w, const Quaternion& q)
{
return Quaternion( w.x() * q.w() + w.y() * q.z() - w.z() * q.y(),
w.y() * q.w() + w.z() * q.x() - w.x() * q.z(),
w.z() * q.w() + w.x() * q.y() - w.y() * q.x(),
-w.x() * q.x() - w.y() * q.y() - w.z() * q.z());
}
inline float
dot(const Quaternion& q1, const Quaternion& q2)
{
return q1.dot(q2);
}
inline float
length(const Quaternion& q)
{
return q.length();
}
inline float
angle(const Quaternion& q1, const Quaternion& q2)
{
return q1.angle(q2);
}
inline Quaternion
inverse(const Quaternion& q)
{
return q.inverse();
}
inline Quaternion
slerp(const Quaternion& q1, const Quaternion& q2, const float& t)
{
return q1.slerp(q2, t);
}
inline Quaternion
shortestArcQuat(const Vector3& v0, const Vector3& v1) // Game Programming Gems 2.10. make sure v0,v1 are normalized
{
Vector3 c = v0.cross(v1);
float d = v0.dot(v1);
if (d < -1.0 + FLT_EPSILON)
return Quaternion(0.0f, 1.0f, 0.0f, 0.0f); // just pick any vector
float s = sqrt((1.0f + d) * 2.0f);
float rs = 1.0f / s;
return Quaternion(c.x() * rs, c.y() * rs, c.z() * rs, s * 0.5f);
}
inline Quaternion
shortestArcQuatNormalize2(Vector3& v0, Vector3& v1)
{
v0.normalize();
v1.normalize();
return shortestArcQuat(v0, v1);
}
#endif
+264
View File
@@ -0,0 +1,264 @@
/*
* Copyright 2008, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Alexandre Deckner <alex@zappotek.com>
*/
#include "RenderView.h"
#include "BitmapTexture.h"
#include "Camera.h"
#include "MeshInstance.h"
#include "StaticMesh.h"
#include "VideoFileTexture.h"
#include <opengl/GL/gl.h>
#include <opengl/GL/glu.h>
#include <TranslationKit.h>
#include <TranslationUtils.h>
RenderView::RenderView(BRect frame)
:
BGLView(frame, "renderView", B_FOLLOW_ALL, B_WILL_DRAW,
BGL_RGB | BGL_DOUBLE | BGL_DEPTH),
fMainCamera(NULL),
fRenderThread(-1),
fStopRendering(false),
fRes(0, 0),
fNextRes(0, 0),
fLastFrameTime(0)
{
}
RenderView::~RenderView()
{
_StopRenderThread();
if (fRenderThread >= 0)
wait_for_thread(fRenderThread, NULL);
_DeleteScene();
}
void
RenderView::AttachedToWindow()
{
BGLView::AttachedToWindow();
_CreateScene();
_InitGL();
if (_CreateRenderThread() != B_OK)
printf("Error trying to start the render thread!\n");
}
uint32
RenderView::_CreateRenderThread()
{
fRenderThread = spawn_thread(RenderView::_RenderThreadEntry,
"renderThread",
B_NORMAL_PRIORITY,
this);
if (fRenderThread < 0)
return fRenderThread;
return resume_thread(fRenderThread);
}
void
RenderView::_StopRenderThread()
{
LockGL();
fStopRendering = true;
UnlockGL();
}
int32
RenderView::_RenderThreadEntry(void *pointer)
{
return reinterpret_cast<RenderView*>(pointer)->_RenderLoop();
}
int32
RenderView::_RenderLoop()
{
fLastFrameTime = system_time();
while (_Render()) {
snooze(10000);
}
return B_OK;
}
void RenderView::_InitGL(void)
{
LockGL();
float position[] = {0.0, 3.0, 6.0, 0.0};
float local_view[] = {0.0, 0.0};
glLightfv(GL_LIGHT0, GL_POSITION, position);
glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, local_view);
float white[3] = {1.0, 1.0, 1.0};
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_SPECULAR, white);
glLightfv(GL_LIGHT0, GL_DIFFUSE, white);
glLightfv(GL_LIGHT0, GL_AMBIENT, white);
glMaterialf(GL_FRONT, GL_SHININESS, 0.6 * 128.0);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_TEXTURE_2D);
fNextRes.Set(Bounds().Width(), Bounds().Height());
_UpdateViewport();
UnlockGL();
}
void
RenderView::_CreateScene()
{
Texture *texture = new BitmapTexture(
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "texture"));
float spacing = 1.6f;
float timeSpacing = 5.0f;
float yOffset = -1.0f;
float zOffset = -16;
Mesh* mesh = new StaticMesh("LetterH");
MeshInstance *instance = new MeshInstance(mesh, texture,
Vector3(-3.6 * spacing, yOffset, zOffset),
Quaternion(0, 0, 0, 1), 0.0f);
fMeshInstances.push_back(instance);
mesh->ReleaseReference();
mesh = new StaticMesh("LetterA");
instance = new MeshInstance(mesh, texture,
Vector3(-1.6 * spacing, yOffset, zOffset),
Quaternion(0, 0, 0, 1), 1.0f * timeSpacing);
fMeshInstances.push_back(instance);
mesh->ReleaseReference();
mesh = new StaticMesh("LetterI");
instance = new MeshInstance(mesh, texture,
Vector3(0 * spacing, yOffset, zOffset),
Quaternion(0, 0, 0, 1), 2.0f * timeSpacing);
fMeshInstances.push_back(instance);
mesh->ReleaseReference();
mesh = new StaticMesh("LetterK");
instance = new MeshInstance(mesh, texture,
Vector3(1.5 * spacing, yOffset, zOffset),
Quaternion(0, 0, 0, 1), 3.0f * timeSpacing);
fMeshInstances.push_back(instance);
mesh->ReleaseReference();
mesh = new StaticMesh("LetterU");
instance = new MeshInstance(mesh, texture,
Vector3(3.4 * spacing, yOffset, zOffset),
Quaternion(0, 0, 0, 1), 4.0f * timeSpacing);
fMeshInstances.push_back(instance);
mesh->ReleaseReference();
fMainCamera = new Camera(Vector3(0, 0, 0), Quaternion(0, 0, 0, 1), 50);
texture->ReleaseReference();
}
void
RenderView::_DeleteScene()
{
MeshInstanceList::iterator it = fMeshInstances.begin();
for(; it != fMeshInstances.end(); it++) {
delete (*it);
}
fMeshInstances.clear();
}
void
RenderView::_UpdateViewport()
{
if (fNextRes != fRes && fNextRes.x >= 1.0 && fNextRes.y >= 1.0) {
glViewport(0, 0, (GLint)fNextRes.x + 1, (GLint)fNextRes.y + 1);
fRes = fNextRes;
_UpdateCamera();
}
}
void
RenderView::_UpdateCamera()
{
// TODO: take camera orientation into account
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(fMainCamera->FieldOfView(), fNextRes.x / fNextRes.y,
fMainCamera->Near(), fMainCamera->Far());
glMatrixMode(GL_MODELVIEW);
}
bool
RenderView::_Render()
{
LockGL();
_UpdateViewport();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
bigtime_t time = system_time();
float deltaTime = 0.000001 * (float)(time - fLastFrameTime);
fLastFrameTime = time;
MeshInstanceList::iterator it = fMeshInstances.begin();
for(; it != fMeshInstances.end(); it++) {
(*it)->Update(deltaTime);
(*it)->Render();
}
if (fStopRendering) {
UnlockGL();
return false;
}
UnlockGL();
SwapBuffers(false); // true = vsync
return true;
}
void
RenderView::FrameResized(float width, float height)
{
LockGL();
fNextRes.Set(width, height);
UnlockGL();
BGLView::FrameResized(width, height);
}
void
RenderView::ErrorCallback(uint32 error)
{
fprintf(stderr, "OpenGL error (%li): %s\n", error, gluErrorString(error));
}
+53
View File
@@ -0,0 +1,53 @@
/*
* Copyright 2009, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Alexandre Deckner <alex@zappotek.com>
*/
#ifndef _RENDERVIEW_H
#define _RENDERVIEW_H
#include <GLView.h>
#include <vector>
class Camera;
class MeshInstance;
class RenderView : public BGLView {
public:
RenderView(BRect frame);
~RenderView();
virtual void AttachedToWindow();
virtual void FrameResized(float width, float height);
virtual void ErrorCallback(uint32 error);
protected:
void _InitGL();
void _CreateScene();
void _DeleteScene();
void _UpdateViewport();
void _UpdateCamera();
bool _Render();
uint32 _CreateRenderThread();
void _StopRenderThread();
static int32 _RenderThreadEntry(void *pointer);
int32 _RenderLoop();
Camera* fMainCamera;
typedef std::vector<MeshInstance*> MeshInstanceList;
MeshInstanceList fMeshInstances;
thread_id fRenderThread;
bool fStopRendering;
BPoint fRes, fNextRes;
bigtime_t fLastFrameTime;
};
#endif /* _RENDERVIEW_H */
+34
View File
@@ -0,0 +1,34 @@
/*
* Copyright 2008, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Alexandre Deckner <alex@zappotek.com>
*/
#include "Texture.h"
#include <opengl/GL/gl.h>
Texture::Texture()
:
fId(0)
{
}
Texture::~Texture()
{
if (glIsTexture(fId)) {
GLuint ids[1] = {fId};
glDeleteTextures(1, ids);
}
}
GLuint
Texture::Id()
{
return fId;
}
+29
View File
@@ -0,0 +1,29 @@
/*
* Copyright 2009, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Alexandre Deckner <alex@zappotek.com>
*/
#ifndef _TEXTURE_H
#define _TEXTURE_H
#include <Referenceable.h>
#include <opengl/GL/gl.h>
class Texture : public Referenceable {
public:
Texture();
virtual ~Texture();
GLuint Id();
virtual void Update(float dt) {};
protected:
GLuint fId;
};
#endif /* _TEXTURE_H */
+353
View File
@@ -0,0 +1,353 @@
/*
* Copyright 2008 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Alexandre Deckner
*
*/
/*
*
* This is a refactored and stripped down version of bullet-2.66 src\LinearMath\btVector3.h
* The dependancies on base class btQuadWord have been removed for simplification.
*
*/
/*
Copyright (c) 2003-2006 Gino van den Bergen / Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef __VECTOR3_H__
#define __VECTOR3_H__
#include "assert.h"
#include "math.h"
///Vector3 can be used to represent 3D points and vectors.
class Vector3 {
protected:
float m_x;
float m_y;
float m_z;
public:
inline Vector3() {}
inline Vector3(const Vector3& v)
{
*((Vector3*)this) = v;
}
inline Vector3(const float& x, const float& y, const float& z)
{
m_x = x, m_y = y, m_z = z;
}
inline const float& x() const { return m_x; }
inline const float& y() const { return m_y; }
inline const float& z() const { return m_z; }
inline void setValue(const float& x, const float& y, const float& z)
{
m_x=x;
m_y=y;
m_z=z;
}
inline Vector3& operator+=(const Vector3& v)
{
m_x += v.x(); m_y += v.y(); m_z += v.z();
return *this;
}
inline Vector3& operator-=(const Vector3& v)
{
m_x -= v.x(); m_y -= v.y(); m_z -= v.z();
return *this;
}
inline Vector3& operator*=(const float& s)
{
m_x *= s; m_y *= s; m_z *= s;
return *this;
}
inline Vector3& operator/=(const float& s)
{
assert(s != 0.0f);
return *this *= 1.0f / s;
}
inline float dot(const Vector3& v) const
{
return m_x * v.x() + m_y * v.y() + m_z * v.z();
}
inline float length2() const
{
return dot(*this);
}
inline float length() const
{
return sqrt(length2());
}
inline float distance2(const Vector3& v) const;
inline float distance(const Vector3& v) const;
inline Vector3& normalize()
{
return *this /= length();
}
inline Vector3 normalized() const;
inline Vector3 rotate( const Vector3& wAxis, const float angle );
inline float angle(const Vector3& v) const
{
float s = sqrt(length2() * v.length2());
assert(s != 0.0f);
return acos(dot(v) / s);
}
inline Vector3 absolute() const
{
return Vector3(
fabs(m_x),
fabs(m_y),
fabs(m_z));
}
inline Vector3 cross(const Vector3& v) const
{
return Vector3(
m_y * v.z() - m_z * v.y(),
m_z * v.x() - m_x * v.z(),
m_x * v.y() - m_y * v.x());
}
inline float triple(const Vector3& v1, const Vector3& v2) const
{
return m_x * (v1.y() * v2.z() - v1.z() * v2.y()) +
m_y * (v1.z() * v2.x() - v1.x() * v2.z()) +
m_z * (v1.x() * v2.y() - v1.y() * v2.x());
}
inline int minAxis() const
{
return m_x < m_y ? (m_x < m_z ? 0 : 2) : (m_y < m_z ? 1 : 2);
}
inline int maxAxis() const
{
return m_x < m_y ? (m_y < m_z ? 2 : 1) : (m_x < m_z ? 2 : 0);
}
inline int furthestAxis() const
{
return absolute().minAxis();
}
inline int closestAxis() const
{
return absolute().maxAxis();
}
inline void setInterpolate3(const Vector3& v0, const Vector3& v1, float rt)
{
float s = 1.0f - rt;
m_x = s * v0.x() + rt * v1.x();
m_y = s * v0.y() + rt * v1.y();
m_z = s * v0.z() + rt * v1.z();
//don't do the unused w component
// m_co[3] = s * v0[3] + rt * v1[3];
}
inline Vector3 lerp(const Vector3& v, const float& t) const
{
return Vector3(m_x + (v.x() - m_x) * t,
m_y + (v.y() - m_y) * t,
m_z + (v.z() - m_z) * t);
}
inline Vector3& operator*=(const Vector3& v)
{
m_x *= v.x(); m_y *= v.y(); m_z *= v.z();
return *this;
}
};
inline Vector3
operator+(const Vector3& v1, const Vector3& v2)
{
return Vector3(v1.x() + v2.x(), v1.y() + v2.y(), v1.z() + v2.z());
}
inline Vector3
operator*(const Vector3& v1, const Vector3& v2)
{
return Vector3(v1.x() * v2.x(), v1.y() * v2.y(), v1.z() * v2.z());
}
inline Vector3
operator-(const Vector3& v1, const Vector3& v2)
{
return Vector3(v1.x() - v2.x(), v1.y() - v2.y(), v1.z() - v2.z());
}
inline Vector3
operator-(const Vector3& v)
{
return Vector3(-v.x(), -v.y(), -v.z());
}
inline Vector3
operator*(const Vector3& v, const float& s)
{
return Vector3(v.x() * s, v.y() * s, v.z() * s);
}
inline Vector3
operator*(const float& s, const Vector3& v)
{
return v * s;
}
inline Vector3
operator/(const Vector3& v, const float& s)
{
assert(s != 0.0f);
return v * (1.0f / s);
}
inline Vector3
operator/(const Vector3& v1, const Vector3& v2)
{
return Vector3(v1.x() / v2.x(),v1.y() / v2.y(),v1.z() / v2.z());
}
inline float
dot(const Vector3& v1, const Vector3& v2)
{
return v1.dot(v2);
}
inline float
distance2(const Vector3& v1, const Vector3& v2)
{
return v1.distance2(v2);
}
inline float
distance(const Vector3& v1, const Vector3& v2)
{
return v1.distance(v2);
}
inline float
angle(const Vector3& v1, const Vector3& v2)
{
return v1.angle(v2);
}
inline Vector3
cross(const Vector3& v1, const Vector3& v2)
{
return v1.cross(v2);
}
inline float
triple(const Vector3& v1, const Vector3& v2, const Vector3& v3)
{
return v1.triple(v2, v3);
}
inline Vector3
lerp(const Vector3& v1, const Vector3& v2, const float& t)
{
return v1.lerp(v2, t);
}
inline bool operator==(const Vector3& p1, const Vector3& p2)
{
return p1.x() == p2.x() && p1.y() == p2.y() && p1.z() == p2.z();
}
inline float Vector3::distance2(const Vector3& v) const
{
return (v - *this).length2();
}
inline float Vector3::distance(const Vector3& v) const
{
return (v - *this).length();
}
inline Vector3 Vector3::normalized() const
{
return *this / length();
}
inline Vector3 Vector3::rotate( const Vector3& wAxis, const float angle )
{
// wAxis must be a unit lenght vector
Vector3 o = wAxis * wAxis.dot( *this );
Vector3 x = *this - o;
Vector3 y;
y = wAxis.cross( *this );
return ( o + x * cos( angle ) + y * sin( angle ) );
}
#endif //__VECTOR3_H__
+193
View File
@@ -0,0 +1,193 @@
33
4
0.026275 1.929266 0.142702 0.812137 0.849682
0.025358 2.624107 0.142703 0.819405 0.868483
-1.134064 -0.009465 0.142702 0.764105 0.811047
-0.838689 -0.009465 0.142702 0.771154 0.807535
4
0.026275 1.929266 0.142702 0.812137 0.849682
0.859859 0.010343 0.142702 0.811899 0.787878
1.177288 0.010343 0.142702 0.819474 0.784105
0.025358 2.624107 0.142703 0.819405 0.868483
4
-0.838689 -0.009465 0.142702 0.890886 0.846817
-1.134064 -0.009465 0.142702 0.890895 0.850372
-1.134064 -0.009465 -0.157297 0.883074 0.850400
-0.838689 -0.009465 -0.157297 0.883065 0.846844
4
0.026275 1.929266 0.142702 0.890716 0.784105
-0.838689 -0.009465 0.142702 0.890886 0.846817
-0.838689 -0.009465 -0.157297 0.883065 0.846844
0.026275 1.929266 -0.157298 0.882895 0.784132
4
-1.134064 -0.009465 0.142702 0.882895 0.784132
0.025358 2.624107 0.142703 0.882665 0.869135
0.025358 2.624107 -0.157298 0.874844 0.869107
-1.134064 -0.009465 -0.157297 0.875074 0.784105
4
0.859859 0.010343 0.142702 0.827295 0.868483
0.026275 1.929266 0.142702 0.827409 0.910442
0.026275 1.929266 -0.157298 0.819588 0.910469
0.859859 0.010343 -0.157298 0.819474 0.868510
4
1.177288 0.010343 0.142702 0.890726 0.907075
0.859859 0.010343 0.142702 0.890716 0.910895
0.859859 0.010343 -0.157298 0.882895 0.910868
1.177288 0.010343 -0.157298 0.882905 0.907048
4
0.025358 2.624107 0.142703 0.890880 0.850427
1.177288 0.010343 0.142702 0.890726 0.907075
1.177288 0.010343 -0.157298 0.882905 0.907048
0.025358 2.624107 -0.157298 0.883059 0.850400
4
-1.134064 -0.009465 -0.157297 0.819474 0.841541
0.025358 2.624107 -0.157298 0.874775 0.784105
0.026275 1.929266 -0.157298 0.867507 0.802906
-0.838689 -0.009465 -0.157297 0.826524 0.845052
4
1.177288 0.010343 -0.157298 0.874844 0.868483
0.859859 0.010343 -0.157298 0.867268 0.864709
0.026275 1.929266 -0.157298 0.867507 0.802906
0.025358 2.624107 -0.157298 0.874775 0.784105
4
1.535371 0.250764 0.228401 0.499244 0.606206
1.715217 0.082734 0.228401 0.526322 0.580249
1.754225 0.186795 0.228401 0.530271 0.590785
1.590723 0.318781 0.228401 0.505058 0.613280
4
1.535371 0.250764 0.228401 0.499244 0.606206
1.590723 0.318781 0.228401 0.505058 0.613280
1.395498 0.456165 0.228401 0.472996 0.635023
1.348583 0.386538 0.228401 0.467749 0.627685
4
1.348583 0.386538 0.228401 0.467749 0.627685
1.395498 0.456165 0.228401 0.472996 0.635023
1.188316 0.556125 0.228402 0.438971 0.653078
1.162431 0.490136 0.228402 0.435539 0.644698
4
1.162431 0.490136 0.228402 0.435539 0.644698
1.188316 0.556125 0.228402 0.438971 0.653078
1.035126 0.610117 0.228402 0.412175 0.661945
1.012306 0.543007 0.228402 0.413342 0.653381
4
1.012306 0.543007 0.228402 0.413342 0.653381
1.035126 0.610117 0.228402 0.412175 0.661945
0.916419 0.821496 0.228402 0.392680 0.696659
0.785817 0.467855 0.228402 0.371231 0.640220
4
0.785817 0.467855 0.228402 0.371231 0.640220
0.916419 0.821496 0.228402 0.392680 0.696659
0.765917 1.009250 0.228402 0.367963 0.726674
0.560418 0.461997 0.228402 0.337492 0.640896
4
0.412807 0.633303 0.228402 0.314888 0.669849
0.568306 1.165478 0.228402 0.337968 0.751512
0.431738 1.238529 0.228401 0.315540 0.763509
0.280950 0.527645 0.228402 0.288318 0.650039
3
-1.356235 0.706943 0.228402 0.022724 0.678666
-1.324781 0.790708 0.228402 0.027071 0.689145
-1.444222 0.763836 0.228402 0.009094 0.686371
3
-0.213920 1.329425 0.228401 0.210324 0.778437
-0.304249 1.098594 0.228402 0.194670 0.739709
-0.022174 1.339750 0.228401 0.239356 0.779313
4
-0.734788 0.460804 0.228402 0.120687 0.639881
-0.638044 0.516145 0.228402 0.135756 0.648970
-0.514361 0.698029 0.228402 0.162622 0.689490
-0.979733 0.536230 0.228402 0.083737 0.650630
3
-0.514361 0.698029 0.228402 0.162622 0.689490
-0.304249 1.098594 0.228402 0.194670 0.739709
-0.570561 1.204075 0.228401 0.152573 0.756212
4
-0.257244 0.449873 0.228402 0.202390 0.638905
-0.304249 1.098594 0.228402 0.194670 0.739709
-0.514361 0.698029 0.228402 0.162622 0.689490
-0.552190 0.464998 0.228402 0.162144 0.637293
3
0.215441 1.299339 0.228401 0.284114 0.772676
0.256344 1.144662 0.228402 0.290012 0.742359
0.431738 1.238529 0.228401 0.315540 0.763509
4
-0.257244 0.449873 0.228402 0.202390 0.638905
0.107318 1.279300 0.228401 0.260622 0.770205
-0.022174 1.339750 0.228401 0.239356 0.779313
-0.304249 1.098594 0.228402 0.194670 0.739709
4
0.055479 0.482123 0.228402 0.252109 0.643382
0.256344 1.144662 0.228402 0.290012 0.742359
0.107318 1.279300 0.228401 0.260622 0.770205
-0.257244 0.449873 0.228402 0.202390 0.638905
4
0.431738 1.238529 0.228401 0.315540 0.763509
0.256344 1.144662 0.228402 0.290012 0.742359
0.055479 0.482123 0.228402 0.252109 0.643382
0.280950 0.527645 0.228402 0.288318 0.650039
3
0.560418 0.461997 0.228402 0.337492 0.640896
0.412807 0.633303 0.228402 0.314888 0.669849
0.370147 0.492156 0.228402 0.311978 0.644211
4
0.560418 0.461997 0.228402 0.337492 0.640896
0.765917 1.009250 0.228402 0.367963 0.726674
0.568306 1.165478 0.228402 0.337968 0.751512
0.412807 0.633303 0.228402 0.314888 0.669849
4
-0.751135 1.144997 0.228401 0.121279 0.747329
-0.979733 0.536230 0.228402 0.083737 0.650630
-0.514361 0.698029 0.228402 0.162622 0.689490
-0.570561 1.204075 0.228401 0.152573 0.756212
4
-0.751135 1.144997 0.228401 0.121279 0.747329
-1.105109 0.939104 0.228402 0.064785 0.714335
-1.065350 0.826734 0.228402 0.072134 0.691785
-0.979733 0.536230 0.228402 0.083737 0.650630
4
-0.979733 0.536230 0.228402 0.083737 0.650630
-1.065350 0.826734 0.228402 0.072134 0.691785
-1.194371 0.872022 0.228402 0.047669 0.703318
-1.223251 0.624486 0.228402 0.045383 0.664305
4
-1.356235 0.706943 0.228402 0.022724 0.678666
-1.223251 0.624486 0.228402 0.045383 0.664305
-1.194371 0.872022 0.228402 0.047669 0.703318
-1.324781 0.790708 0.228402 0.027071 0.689145
3
-0.213920 1.329425 0.228401 0.210324 0.778437
-0.433769 1.262431 0.228401 0.180772 0.768254
-0.304249 1.098594 0.228402 0.194670 0.739709
Binary file not shown.
+205
View File
@@ -0,0 +1,205 @@
35
4
-0.585155 2.545548 0.153761 0.703908 0.578770
-0.902892 2.545549 0.153761 0.715955 0.578811
-0.902893 0.002049 0.153761 0.715659 0.686230
-0.585155 0.002048 0.153761 0.703612 0.686189
4
0.903000 2.545548 0.153761 0.691566 0.578770
0.585263 2.545549 0.153761 0.703612 0.578811
0.585263 0.002048 0.153761 0.703316 0.686230
0.903000 0.002048 0.153761 0.691270 0.686189
4
-0.585155 0.002048 0.153761 0.798693 0.578770
-0.902893 0.002049 0.153761 0.798730 0.592189
-0.902893 0.002049 -0.146239 0.787356 0.592228
-0.585155 0.002048 -0.146239 0.787319 0.578809
4
-0.585155 2.545548 0.153761 0.763979 0.578809
-0.585155 0.002048 0.153761 0.763683 0.686228
-0.585155 0.002048 -0.146239 0.752309 0.686189
-0.585155 2.545548 -0.146239 0.752605 0.578770
4
-0.902892 2.545549 0.153761 0.798730 0.619182
-0.585155 2.545548 0.153761 0.798693 0.632601
-0.585155 2.545548 -0.146239 0.787319 0.632562
-0.902892 2.545549 -0.146239 0.787356 0.619143
4
-0.902893 0.002049 0.153761 0.775353 0.578770
-0.902892 2.545549 0.153761 0.775649 0.686189
-0.902892 2.545549 -0.146239 0.764275 0.686228
-0.902893 0.002049 -0.146239 0.763979 0.578809
4
0.585263 0.002048 0.153761 0.787023 0.578770
0.585263 2.545549 0.153761 0.787319 0.686189
0.585263 2.545549 -0.146239 0.775945 0.686228
0.585263 0.002049 -0.146239 0.775649 0.578809
4
0.585263 2.545549 0.153761 0.798693 0.605685
0.903000 2.545548 0.153761 0.798730 0.619104
0.903000 2.545548 -0.146239 0.787356 0.619143
0.585263 2.545549 -0.146239 0.787319 0.605724
4
0.903000 2.545548 0.153761 0.752309 0.578809
0.903000 0.002048 0.153761 0.752014 0.686228
0.903000 0.002048 -0.146239 0.740639 0.686189
0.903000 2.545548 -0.146239 0.740935 0.578770
4
0.903000 0.002048 0.153761 0.798693 0.592228
0.585263 0.002048 0.153761 0.798730 0.605647
0.585263 0.002049 -0.146239 0.787356 0.605685
0.903000 0.002048 -0.146239 0.787319 0.592266
4
-0.902893 0.002049 -0.146239 0.740344 0.578770
-0.902892 2.545549 -0.146239 0.740639 0.686189
-0.585155 2.545548 -0.146239 0.728593 0.686230
-0.585155 0.002048 -0.146239 0.728297 0.578811
4
0.585263 0.002049 -0.146239 0.728001 0.578770
0.585263 2.545549 -0.146239 0.728297 0.686189
0.903000 2.545548 -0.146239 0.716250 0.686230
0.903000 0.002048 -0.146239 0.715955 0.578811
4
-1.618295 1.082143 0.239460 0.040080 0.887095
-1.845677 1.176358 0.239460 0.007364 0.899381
-1.845678 1.065225 0.239460 0.006105 0.889319
-1.646252 0.999025 0.239460 0.037117 0.879587
4
-1.618295 1.082143 0.239460 0.040080 0.887095
-1.646252 0.999025 0.239460 0.037117 0.879587
-1.415226 0.938906 0.239460 0.075052 0.868767
-1.395736 1.020569 0.239460 0.076610 0.875614
4
-1.395736 1.020569 0.239460 0.076610 0.875614
-1.415226 0.938906 0.239460 0.075052 0.868767
-1.186141 0.918025 0.239460 0.112665 0.863203
-1.185065 0.988900 0.239460 0.112844 0.870357
4
-1.185065 0.988900 0.239460 0.112844 0.870357
-1.186141 0.918025 0.239460 0.112665 0.863203
-1.023746 0.921236 0.239460 0.142248 0.863737
-1.025933 0.992086 0.239460 0.140312 0.871305
4
-1.025933 0.992086 0.239460 0.140312 0.871305
-1.023746 0.921236 0.239460 0.142248 0.863737
-0.838399 0.764972 0.239460 0.170922 0.841464
-0.840232 1.141953 0.239460 0.171142 0.895661
4
-0.840232 1.141953 0.239460 0.171142 0.895661
-0.838399 0.764972 0.239460 0.170922 0.841464
-0.631572 0.641988 0.239460 0.205783 0.819473
-0.631230 1.226553 0.239460 0.204792 0.910231
4
-0.432883 1.117957 0.239460 0.234051 0.885910
-0.391698 0.565060 0.239460 0.245083 0.807750
-0.238178 0.544592 0.239460 0.271095 0.804352
-0.346500 1.263173 0.239460 0.254684 0.917359
3
1.249456 1.669926 0.239460 0.515680 0.984007
1.249403 1.580450 0.239460 0.514866 0.974790
1.351814 1.647535 0.239460 0.524084 0.981095
3
0.398306 0.686102 0.239460 0.375191 0.826273
0.401868 0.933951 0.239460 0.371063 0.868469
0.222383 0.609132 0.239460 0.346508 0.814543
4
0.581153 1.682280 0.239460 0.409385 0.985220
0.509988 1.596504 0.239460 0.399835 0.975509
0.458015 1.382780 0.239460 0.384537 0.926374
0.836988 1.697627 0.239460 0.448545 0.990012
3
0.458015 1.382780 0.239460 0.384537 0.926374
0.401868 0.933951 0.239460 0.371063 0.868469
0.688259 0.928655 0.239460 0.421756 0.866541
4
0.130154 1.524901 0.239460 0.331196 0.959238
0.401868 0.933951 0.239460 0.371063 0.868469
0.458015 1.382780 0.239460 0.384537 0.926374
0.411645 1.614262 0.239460 0.369667 0.974116
3
-0.014298 0.563570 0.239460 0.301447 0.805930
-0.106890 0.694049 0.239460 0.284502 0.829689
-0.238178 0.544592 0.239460 0.271095 0.804352
4
0.130154 1.524901 0.239460 0.331196 0.959238
0.079912 0.620284 0.239460 0.323904 0.817443
0.222383 0.609132 0.239460 0.346508 0.814543
0.401868 0.933951 0.239460 0.371063 0.868469
4
-0.151352 1.384938 0.239460 0.284985 0.937050
-0.106890 0.694049 0.239460 0.284502 0.829689
0.079912 0.620284 0.239460 0.323904 0.817443
0.130154 1.524901 0.239460 0.331196 0.959238
4
-0.238178 0.544592 0.239460 0.271095 0.804352
-0.106890 0.694049 0.239460 0.284502 0.829689
-0.151352 1.384938 0.239460 0.284985 0.937050
-0.346500 1.263173 0.239460 0.254684 0.917359
3
-0.631230 1.226553 0.239460 0.204792 0.910231
-0.432883 1.117957 0.239460 0.234051 0.885910
-0.442479 1.265096 0.239460 0.231409 0.913484
4
-0.631230 1.226553 0.239460 0.204792 0.910231
-0.631572 0.641988 0.239460 0.205783 0.819473
-0.391698 0.565060 0.239460 0.245083 0.807750
-0.432883 1.117957 0.239460 0.234051 0.885910
4
0.836608 1.047355 0.239460 0.445860 0.887296
0.836988 1.697627 0.239460 0.448545 0.990012
0.458015 1.382780 0.239460 0.384537 0.926374
0.688259 0.928655 0.239460 0.421756 0.866541
4
0.836608 1.047355 0.239460 0.445860 0.887296
1.095794 1.364391 0.239460 0.484801 0.934893
1.019124 1.455657 0.239460 0.475830 0.954877
0.836988 1.697627 0.239460 0.448545 0.990012
4
0.836988 1.697627 0.239460 0.448545 0.990012
1.019124 1.455657 0.239460 0.475830 0.954877
1.155831 1.458537 0.239460 0.499868 0.955892
1.095991 1.700460 0.239460 0.491813 0.988271
4
1.249456 1.669926 0.239460 0.515680 0.984007
1.095991 1.700460 0.239460 0.491813 0.988271
1.155831 1.458537 0.239460 0.499868 0.955892
1.249403 1.580450 0.239460 0.514866 0.974790
3
0.398306 0.686102 0.239460 0.375191 0.826273
0.580653 0.825999 0.239460 0.396027 0.843207
0.401868 0.933951 0.239460 0.371063 0.868469
Binary file not shown.
+37
View File
@@ -0,0 +1,37 @@
6
4
0.159896 2.544313 0.140078 0.751209 0.688067
-0.157841 2.544313 0.140078 0.777327 0.688116
-0.157842 0.000813 0.140078 0.776686 0.816933
0.159895 0.000813 0.140078 0.750567 0.816884
4
0.159895 0.000813 0.140078 0.879353 0.688067
-0.157842 0.000813 0.140078 0.879433 0.704159
-0.157842 0.000813 -0.159922 0.854772 0.704206
0.159895 0.000813 -0.159922 0.854692 0.688114
4
0.159896 2.544313 0.140078 0.829390 0.688114
0.159895 0.000813 0.140078 0.828748 0.816930
0.159895 0.000813 -0.159922 0.804088 0.816884
0.159896 2.544313 -0.159922 0.804729 0.688067
4
-0.157841 2.544313 0.140078 0.879433 0.704252
0.159896 2.544313 0.140078 0.879353 0.720344
0.159896 2.544313 -0.159922 0.854692 0.720298
-0.157841 2.544313 -0.159922 0.854772 0.704206
4
-0.157842 0.000813 0.140078 0.854051 0.688067
-0.157841 2.544313 0.140078 0.854692 0.816884
-0.157841 2.544313 -0.159922 0.830031 0.816930
-0.157842 0.000813 -0.159922 0.829390 0.688114
4
-0.157842 0.000813 -0.159922 0.803446 0.688067
-0.157841 2.544313 -0.159922 0.804088 0.816884
0.159896 2.544313 -0.159922 0.777969 0.816933
0.159895 0.000813 -0.159922 0.777327 0.688116
Binary file not shown.
+149
View File
@@ -0,0 +1,149 @@
25
4
-0.199403 1.388241 0.140078 0.764164 0.508161
-0.405399 1.189603 0.140078 0.756940 0.501238
0.525260 0.023520 0.140078 0.789355 0.460367
0.918858 0.023520 0.140077 0.803117 0.460325
4
-0.516491 1.413274 0.140078 0.753079 0.509070
-0.199403 1.388241 0.140078 0.764164 0.508161
0.935562 2.545427 0.140078 0.803972 0.548499
0.560064 2.545427 0.140078 0.790842 0.548540
3
-0.516491 1.413274 0.140078 0.753079 0.509070
-0.405399 1.189603 0.140078 0.756940 0.501238
-0.199403 1.388241 0.140078 0.764164 0.508161
4
-0.516491 1.072834 0.140078 0.753043 0.497167
-0.405399 1.189603 0.140078 0.756940 0.501238
-0.516491 1.413274 0.140078 0.753079 0.509070
-0.834228 1.077333 0.140078 0.741934 0.497359
4
-0.516491 0.000247 0.140078 0.752928 0.459665
-0.516491 1.072834 0.140078 0.753043 0.497167
-0.834228 1.077333 0.140078 0.741934 0.497359
-0.834229 0.000247 0.140078 0.741818 0.459699
4
-0.516491 2.543747 0.140078 0.753201 0.548596
-0.834228 2.543748 0.140078 0.742091 0.548630
-0.834228 1.077333 0.140078 0.741934 0.497359
-0.516491 1.413274 0.140078 0.753079 0.509070
4
-0.834228 2.543748 0.140078 0.814674 0.529173
-0.834228 2.543748 -0.159922 0.804185 0.529205
-0.834228 1.077333 -0.159922 0.804062 0.489131
-0.834228 1.077333 0.140078 0.814551 0.489099
4
-0.834228 1.077333 0.140078 0.814551 0.489099
-0.834228 1.077333 -0.159922 0.804062 0.489131
-0.834229 0.000247 -0.159922 0.803972 0.459697
-0.834229 0.000247 0.140078 0.814461 0.459665
4
-0.516491 1.072834 0.140078 0.715879 0.559137
-0.516491 1.072834 -0.159922 0.715847 0.548648
-0.405399 1.189603 -0.159922 0.721482 0.548630
-0.405399 1.189603 0.140078 0.721514 0.559120
4
-0.405399 1.189603 0.140078 0.741818 0.600795
-0.405399 1.189603 -0.159922 0.731329 0.600827
0.525260 0.023520 -0.159923 0.731169 0.548663
0.525260 0.023520 0.140078 0.741658 0.548630
4
0.525260 0.023520 0.140078 0.721546 0.559149
0.525260 0.023520 -0.159923 0.721514 0.548660
0.918858 0.023520 -0.159923 0.731137 0.548630
0.918858 0.023520 0.140077 0.731169 0.559120
4
0.918858 0.023520 0.140077 0.825146 0.590927
0.918858 0.023520 -0.159923 0.814656 0.590894
-0.199404 1.388241 -0.159923 0.814846 0.529205
-0.199403 1.388241 0.140078 0.825335 0.529237
4
-0.199403 1.388241 0.140078 0.752308 0.605335
-0.199404 1.388241 -0.159923 0.741818 0.605303
0.935562 2.545427 -0.159923 0.741992 0.548630
0.935562 2.545427 0.140078 0.752482 0.548663
4
0.935562 2.545427 0.140078 0.814656 0.592876
0.935562 2.545427 -0.159923 0.804167 0.592908
0.560064 2.545427 -0.159923 0.804139 0.583861
0.560064 2.545427 0.140078 0.814628 0.583829
4
0.560064 2.545427 0.140078 0.814628 0.583829
0.560064 2.545427 -0.159923 0.804139 0.583861
-0.516491 1.413274 -0.159922 0.803972 0.529237
-0.516491 1.413274 0.140078 0.814461 0.529205
4
-0.516491 2.543747 -0.159922 0.679665 0.548663
-0.516491 2.543747 0.140078 0.690154 0.548630
-0.516491 1.413274 0.140078 0.690248 0.579204
-0.516491 1.413274 -0.159922 0.679759 0.579236
4
-0.516491 0.000247 0.140078 0.762971 0.577670
-0.516491 0.000247 -0.159923 0.752482 0.577638
-0.516491 1.072834 -0.159922 0.752571 0.548630
-0.516491 1.072834 0.140078 0.763060 0.548663
4
-0.516491 2.543747 0.140078 0.770748 0.548654
-0.516491 2.543747 -0.159922 0.770715 0.559143
-0.834228 2.543748 -0.159922 0.763060 0.559120
-0.834228 2.543748 0.140078 0.763092 0.548630
4
-0.834229 0.000247 0.140078 0.698049 0.548654
-0.834229 0.000247 -0.159922 0.698016 0.559143
-0.516491 0.000247 -0.159923 0.690248 0.559120
-0.516491 0.000247 0.140078 0.690280 0.548630
4
0.525260 0.023520 -0.159923 0.727202 0.547929
-0.405399 1.189603 -0.159922 0.694786 0.507058
-0.199404 1.388241 -0.159923 0.702010 0.500134
0.918858 0.023520 -0.159923 0.740964 0.547971
4
0.935562 2.545427 -0.159923 0.741818 0.459796
-0.199404 1.388241 -0.159923 0.702010 0.500134
-0.516491 1.413274 -0.159922 0.690926 0.499225
0.560064 2.545427 -0.159923 0.728689 0.459756
3
-0.405399 1.189603 -0.159922 0.694786 0.507058
-0.516491 1.413274 -0.159922 0.690926 0.499225
-0.199404 1.388241 -0.159923 0.702010 0.500134
4
-0.516491 1.413274 -0.159922 0.690926 0.499225
-0.405399 1.189603 -0.159922 0.694786 0.507058
-0.516491 1.072834 -0.159922 0.690890 0.511128
-0.834228 1.077333 -0.159922 0.679781 0.510937
4
-0.834228 1.077333 -0.159922 0.679781 0.510937
-0.516491 1.072834 -0.159922 0.690890 0.511128
-0.516491 0.000247 -0.159923 0.690775 0.548630
-0.834229 0.000247 -0.159922 0.679665 0.548596
4
-0.834228 1.077333 -0.159922 0.679781 0.510937
-0.834228 2.543748 -0.159922 0.679938 0.459665
-0.516491 2.543747 -0.159922 0.691047 0.459699
-0.516491 1.413274 -0.159922 0.690926 0.499225
Binary file not shown.
+529
View File
@@ -0,0 +1,529 @@
89
4
-0.588498 2.595606 0.148832 0.885616 0.535726
-0.906235 2.595606 0.148832 0.872935 0.535763
-0.906236 0.981284 0.148831 0.872737 0.474841
-0.588498 0.981284 0.148831 0.885419 0.474804
4
0.906170 0.981285 0.148831 0.945072 0.474631
0.906170 2.595606 0.148831 0.945270 0.535553
0.588433 2.595606 0.148831 0.932589 0.535590
0.588433 0.981284 0.148831 0.932391 0.474668
4
-0.588498 0.981284 0.148831 0.885419 0.474804
-0.906236 0.981284 0.148831 0.872737 0.474841
-0.895665 0.790879 0.148831 0.873136 0.467654
-0.580013 0.827225 0.148831 0.885738 0.468989
4
0.895600 0.790880 0.148831 0.944627 0.467447
0.906170 0.981285 0.148831 0.945072 0.474631
0.588433 0.981284 0.148831 0.932391 0.474668
0.579948 0.827225 0.148831 0.932034 0.468855
4
-0.580013 0.827225 0.148831 0.885738 0.468989
-0.895665 0.790879 0.148831 0.873136 0.467654
-0.849188 0.587542 0.148832 0.874966 0.459975
-0.549093 0.691948 0.148831 0.886956 0.463880
4
0.849122 0.587543 0.148831 0.942747 0.459779
0.895600 0.790880 0.148831 0.944627 0.467447
0.579948 0.827225 0.148831 0.932034 0.468855
0.549028 0.691948 0.148831 0.930783 0.463753
4
-0.549093 0.691948 0.148831 0.886956 0.463880
-0.849188 0.587542 0.148832 0.874966 0.459975
-0.762931 0.402596 0.148832 0.878386 0.452985
-0.491701 0.568101 0.148831 0.889231 0.459200
4
0.762866 0.402596 0.148831 0.939282 0.452809
0.849122 0.587543 0.148831 0.942747 0.459779
0.549028 0.691948 0.148831 0.930783 0.463753
0.491636 0.568101 0.148831 0.928477 0.459086
4
-0.491701 0.568101 0.148831 0.889231 0.459200
-0.762931 0.402596 0.148832 0.878386 0.452985
-0.624774 0.235340 0.148832 0.883879 0.446658
-0.404857 0.464673 0.148831 0.892685 0.455287
4
0.624709 0.235340 0.148831 0.933748 0.446513
0.762866 0.402596 0.148831 0.939282 0.452809
0.491636 0.568101 0.148831 0.928477 0.459086
0.404791 0.464673 0.148831 0.924999 0.455193
4
-0.404857 0.464673 0.148831 0.892685 0.455287
-0.624774 0.235340 0.148832 0.883879 0.446658
-0.440822 0.098173 0.148832 0.891204 0.441460
-0.287177 0.376292 0.148832 0.897371 0.451938
4
0.440757 0.098173 0.148831 0.926389 0.441358
0.624709 0.235340 0.148831 0.933748 0.446513
0.404791 0.464673 0.148831 0.924999 0.455193
0.287112 0.376292 0.148831 0.920291 0.451871
4
-0.287177 0.376292 0.148832 0.897371 0.451938
-0.440822 0.098173 0.148832 0.891204 0.441460
-0.210181 0.017583 0.148831 0.900400 0.438392
-0.148895 0.329355 0.148831 0.902884 0.450150
4
0.210115 0.017583 0.148831 0.917174 0.438343
0.440757 0.098173 0.148831 0.926389 0.441358
0.287112 0.376292 0.148831 0.920291 0.451871
0.148830 0.329354 0.148831 0.914766 0.450116
4
-0.148895 0.329355 0.148831 0.902884 0.450150
-0.210181 0.017583 0.148831 0.900400 0.438392
-0.000033 0.000020 0.148831 0.908785 0.437705
-0.000033 0.317757 0.148831 0.908824 0.449695
4
-0.000033 0.000020 0.148831 0.908785 0.437705
0.210115 0.017583 0.148831 0.917174 0.438343
0.148830 0.329354 0.148831 0.914766 0.450116
-0.000033 0.317757 0.148831 0.908824 0.449695
4
-0.588498 2.595606 0.148832 0.957272 0.526924
-0.588498 0.981284 0.148831 0.957470 0.587842
-0.588498 0.981284 -0.151169 0.945496 0.587877
-0.588498 2.595606 -0.151169 0.945299 0.526958
4
0.588433 0.981284 -0.151169 0.957730 0.546342
0.588433 0.981284 0.148831 0.969704 0.546377
0.588433 2.595606 0.148831 0.969506 0.607295
0.588433 2.595606 -0.151169 0.957533 0.607261
4
-0.906235 2.595606 0.148832 0.896836 0.535763
-0.588498 2.595606 0.148832 0.896875 0.547754
-0.588498 2.595606 -0.151169 0.884901 0.547789
-0.906235 2.595606 -0.151168 0.884862 0.535798
4
0.588433 2.595606 -0.151169 0.800243 0.535763
0.588433 2.595606 0.148831 0.812217 0.535798
0.906170 2.595606 0.148831 0.812178 0.547789
0.906170 2.595606 -0.151169 0.800205 0.547754
4
-0.906236 0.981284 0.148831 0.969598 0.465971
-0.906235 2.595606 0.148832 0.969795 0.526889
-0.906235 2.595606 -0.151168 0.957822 0.526924
-0.906236 0.981284 -0.151169 0.957624 0.466005
4
0.906170 2.595606 -0.151169 0.945559 0.437705
0.906170 2.595606 0.148831 0.957533 0.437739
0.906170 0.981285 0.148831 0.957335 0.498658
0.906170 0.981285 -0.151169 0.945362 0.498623
4
-0.895665 0.790879 0.148831 0.969574 0.458781
-0.906236 0.981284 0.148831 0.969598 0.465971
-0.906236 0.981284 -0.151169 0.957624 0.466005
-0.895665 0.790879 -0.151169 0.957601 0.458816
4
0.906170 0.981285 -0.151169 0.945362 0.498623
0.906170 0.981285 0.148831 0.957335 0.498658
0.895600 0.790880 0.148831 0.957312 0.505847
0.895600 0.790880 -0.151169 0.945338 0.505812
4
-0.588498 0.981284 0.148831 0.957470 0.587842
-0.580013 0.827225 0.148831 0.957489 0.593652
-0.580013 0.827226 -0.151169 0.945515 0.593687
-0.588498 0.981284 -0.151169 0.945496 0.587877
4
0.579948 0.827225 -0.151169 0.957749 0.540532
0.579948 0.827225 0.148831 0.969723 0.540567
0.588433 0.981284 0.148831 0.969704 0.546377
0.588433 0.981284 -0.151169 0.957730 0.546342
4
-0.849188 0.587542 0.148832 0.969549 0.451089
-0.895665 0.790879 0.148831 0.969574 0.458781
-0.895665 0.790879 -0.151169 0.957601 0.458816
-0.849188 0.587542 -0.151169 0.957576 0.451123
4
0.895600 0.790880 -0.151169 0.945338 0.505812
0.895600 0.790880 0.148831 0.957312 0.505847
0.849122 0.587543 0.148831 0.957287 0.513540
0.849122 0.587543 -0.151169 0.945313 0.513505
4
-0.580013 0.827225 0.148831 0.957489 0.593652
-0.549093 0.691948 0.148831 0.957505 0.598744
-0.549094 0.691948 -0.151169 0.945532 0.598779
-0.580013 0.827226 -0.151169 0.945515 0.593687
4
0.549028 0.691948 -0.151169 0.957766 0.535440
0.549028 0.691948 0.148831 0.969739 0.535475
0.579948 0.827225 0.148831 0.969723 0.540567
0.579948 0.827225 -0.151169 0.957749 0.540532
4
-0.762931 0.402596 0.148832 0.969527 0.444074
-0.849188 0.587542 0.148832 0.969549 0.451089
-0.849188 0.587542 -0.151169 0.957576 0.451123
-0.762931 0.402596 -0.151169 0.957553 0.444108
4
0.849122 0.587543 -0.151169 0.945313 0.513505
0.849122 0.587543 0.148831 0.957287 0.513540
0.762866 0.402596 0.148831 0.957264 0.520555
0.762866 0.402596 -0.151169 0.945291 0.520520
4
-0.549093 0.691948 0.148831 0.957505 0.598744
-0.491701 0.568101 0.148831 0.957520 0.603394
-0.491701 0.568101 -0.151169 0.945547 0.603429
-0.549094 0.691948 -0.151169 0.945532 0.598779
4
0.491636 0.568101 -0.151169 0.957781 0.530791
0.491636 0.568101 0.148831 0.969754 0.530825
0.549028 0.691948 0.148831 0.969739 0.535475
0.549028 0.691948 -0.151169 0.957766 0.535440
4
-0.624774 0.235340 0.148832 0.969506 0.437705
-0.762931 0.402596 0.148832 0.969527 0.444074
-0.762931 0.402596 -0.151169 0.957553 0.444108
-0.624774 0.235340 -0.151169 0.957533 0.437739
4
0.762866 0.402596 -0.151169 0.945291 0.520520
0.762866 0.402596 0.148831 0.957264 0.520555
0.624709 0.235340 0.148831 0.957243 0.526924
0.624709 0.235340 -0.151169 0.945270 0.526889
4
-0.491701 0.568101 0.148831 0.957520 0.603394
-0.404857 0.464673 0.148831 0.957533 0.607261
-0.404857 0.464673 -0.151169 0.945559 0.607295
-0.491701 0.568101 -0.151169 0.945547 0.603429
4
0.404791 0.464673 -0.151169 0.957793 0.526924
0.404791 0.464673 0.148831 0.969767 0.526958
0.491636 0.568101 0.148831 0.969754 0.530825
0.491636 0.568101 -0.151169 0.957781 0.530791
4
-0.440822 0.098173 0.148832 0.884731 0.576341
-0.624774 0.235340 0.148832 0.884711 0.582565
-0.624774 0.235340 -0.151169 0.872737 0.582531
-0.440822 0.098173 -0.151169 0.872757 0.576306
4
0.624709 0.235340 -0.151169 0.872889 0.535763
0.624709 0.235340 0.148831 0.884862 0.535798
0.440757 0.098173 0.148831 0.884838 0.543344
0.440757 0.098173 -0.151169 0.872865 0.543309
4
-0.404857 0.464673 0.148831 0.872638 0.535763
-0.287177 0.376292 0.148832 0.872653 0.540204
-0.287177 0.376292 -0.151169 0.860679 0.540239
-0.404857 0.464673 -0.151169 0.860665 0.535798
4
0.287112 0.376293 -0.151169 0.860750 0.561912
0.287112 0.376292 0.148831 0.872723 0.561877
0.404791 0.464673 0.148831 0.872737 0.566318
0.404791 0.464673 -0.151169 0.860764 0.566353
4
-0.210181 0.017583 0.148831 0.884758 0.568097
-0.440822 0.098173 0.148832 0.884731 0.576341
-0.440822 0.098173 -0.151169 0.872757 0.576306
-0.210181 0.017583 -0.151169 0.872784 0.568062
4
0.440757 0.098173 -0.151169 0.872865 0.543309
0.440757 0.098173 0.148831 0.884838 0.543344
0.210115 0.017583 0.148831 0.884809 0.552365
0.210115 0.017583 -0.151169 0.872835 0.552330
4
-0.287177 0.376292 0.148832 0.872653 0.540204
-0.148895 0.329355 0.148831 0.872669 0.545423
-0.148896 0.329355 -0.151169 0.860696 0.545457
-0.287177 0.376292 -0.151169 0.860679 0.540239
4
0.148830 0.329355 -0.151169 0.860733 0.556693
0.148830 0.329354 0.148831 0.872706 0.556658
0.287112 0.376292 0.148831 0.872723 0.561877
0.287112 0.376293 -0.151169 0.860750 0.561912
4
-0.000033 0.000020 0.148831 0.884783 0.560315
-0.210181 0.017583 0.148831 0.884758 0.568097
-0.210181 0.017583 -0.151169 0.872784 0.568062
-0.000033 0.000020 -0.151169 0.872809 0.560281
4
0.210115 0.017583 -0.151169 0.872835 0.552330
0.210115 0.017583 0.148831 0.884809 0.552365
-0.000033 0.000020 0.148831 0.884783 0.560315
-0.000033 0.000020 -0.151169 0.872809 0.560281
4
-0.148895 0.329355 0.148831 0.872669 0.545423
-0.000033 0.317757 0.148831 0.872688 0.551040
-0.000033 0.317757 -0.151169 0.860714 0.551075
-0.148896 0.329355 -0.151169 0.860696 0.545457
4
-0.000033 0.317757 -0.151169 0.860714 0.551075
-0.000033 0.317757 0.148831 0.872688 0.551040
0.148830 0.329354 0.148831 0.872706 0.556658
0.148830 0.329355 -0.151169 0.860733 0.556693
4
-0.906236 0.981284 -0.151169 0.872540 0.474631
-0.906235 2.595606 -0.151168 0.872737 0.535553
-0.588498 2.595606 -0.151169 0.860056 0.535590
-0.588498 0.981284 -0.151169 0.859858 0.474668
4
0.588433 2.595606 -0.151169 0.813083 0.535726
0.906170 2.595606 -0.151169 0.800402 0.535763
0.906170 0.981285 -0.151169 0.800205 0.474841
0.588433 0.981284 -0.151169 0.812886 0.474804
4
-0.895665 0.790879 -0.151169 0.872094 0.467447
-0.906236 0.981284 -0.151169 0.872540 0.474631
-0.588498 0.981284 -0.151169 0.859858 0.474668
-0.580013 0.827226 -0.151169 0.859501 0.468855
4
0.588433 0.981284 -0.151169 0.812886 0.474804
0.906170 0.981285 -0.151169 0.800205 0.474841
0.895600 0.790880 -0.151169 0.800603 0.467654
0.579948 0.827225 -0.151169 0.813206 0.468989
4
-0.849188 0.587542 -0.151169 0.870215 0.459779
-0.895665 0.790879 -0.151169 0.872094 0.467447
-0.580013 0.827226 -0.151169 0.859501 0.468855
-0.549094 0.691948 -0.151169 0.858250 0.463753
4
0.579948 0.827225 -0.151169 0.813206 0.468989
0.895600 0.790880 -0.151169 0.800603 0.467654
0.849122 0.587543 -0.151169 0.802433 0.459975
0.549028 0.691948 -0.151169 0.814423 0.463880
4
-0.762931 0.402596 -0.151169 0.866749 0.452809
-0.849188 0.587542 -0.151169 0.870215 0.459779
-0.549094 0.691948 -0.151169 0.858250 0.463753
-0.491701 0.568101 -0.151169 0.855945 0.459086
4
0.549028 0.691948 -0.151169 0.814423 0.463880
0.849122 0.587543 -0.151169 0.802433 0.459975
0.762866 0.402596 -0.151169 0.805853 0.452985
0.491636 0.568101 -0.151169 0.816698 0.459200
4
-0.624774 0.235340 -0.151169 0.861215 0.446513
-0.762931 0.402596 -0.151169 0.866749 0.452809
-0.491701 0.568101 -0.151169 0.855945 0.459086
-0.404857 0.464673 -0.151169 0.852466 0.455193
4
0.491636 0.568101 -0.151169 0.816698 0.459200
0.762866 0.402596 -0.151169 0.805853 0.452985
0.624709 0.235340 -0.151169 0.811347 0.446658
0.404791 0.464673 -0.151169 0.820152 0.455287
4
-0.440822 0.098173 -0.151169 0.853856 0.441358
-0.624774 0.235340 -0.151169 0.861215 0.446513
-0.404857 0.464673 -0.151169 0.852466 0.455193
-0.287177 0.376292 -0.151169 0.847758 0.451871
4
0.404791 0.464673 -0.151169 0.820152 0.455287
0.624709 0.235340 -0.151169 0.811347 0.446658
0.440757 0.098173 -0.151169 0.818672 0.441460
0.287112 0.376293 -0.151169 0.824838 0.451938
4
-0.210181 0.017583 -0.151169 0.844641 0.438343
-0.440822 0.098173 -0.151169 0.853856 0.441358
-0.287177 0.376292 -0.151169 0.847758 0.451871
-0.148896 0.329355 -0.151169 0.842234 0.450116
4
0.287112 0.376293 -0.151169 0.824838 0.451938
0.440757 0.098173 -0.151169 0.818672 0.441460
0.210115 0.017583 -0.151169 0.827867 0.438392
0.148830 0.329355 -0.151169 0.830351 0.450150
4
-0.000033 0.000020 -0.151169 0.836252 0.437705
-0.210181 0.017583 -0.151169 0.844641 0.438343
-0.148896 0.329355 -0.151169 0.842234 0.450116
-0.000033 0.317757 -0.151169 0.836291 0.449695
4
0.148830 0.329355 -0.151169 0.830351 0.450150
0.210115 0.017583 -0.151169 0.827867 0.438392
-0.000033 0.000020 -0.151169 0.836252 0.437705
-0.000033 0.317757 -0.151169 0.836291 0.449695
4
0.034168 1.768577 0.235689 0.022855 0.519429
-0.002803 1.967752 0.235689 0.017107 0.550231
-0.079495 1.917906 0.235689 0.008921 0.544536
-0.035731 1.750589 0.235689 0.017117 0.515965
4
0.034168 1.768577 0.235689 0.022855 0.519429
-0.035731 1.750589 0.235689 0.017117 0.515965
0.026403 1.564192 0.235689 0.028101 0.486168
0.091501 1.587370 0.235689 0.032789 0.488397
4
0.091501 1.587370 0.235689 0.032789 0.488397
0.026403 1.564192 0.235689 0.028101 0.486168
0.114746 1.396734 0.235689 0.040638 0.458863
0.164140 1.427781 0.235689 0.045455 0.462413
4
0.164140 1.427781 0.235689 0.045455 0.462413
0.114746 1.396734 0.235689 0.040638 0.458863
0.189801 1.286104 0.235689 0.052423 0.441934
0.237714 1.319393 0.235689 0.056569 0.445848
4
0.237714 1.319393 0.235689 0.056569 0.445848
0.189801 1.286104 0.235689 0.052423 0.441934
0.165097 1.088106 0.235689 0.050980 0.408209
0.424431 1.258461 0.235689 0.088029 0.433570
4
0.424431 1.258461 0.235689 0.088029 0.433570
0.165097 1.088106 0.235689 0.050980 0.408209
0.172995 0.890212 0.235689 0.052695 0.376649
0.576558 1.152173 0.235689 0.112141 0.416703
4
0.590581 0.966584 0.235689 0.109054 0.385642
0.227498 0.690170 0.235689 0.060276 0.345169
0.282232 0.575044 0.235688 0.068968 0.326220
0.729540 0.972106 0.235689 0.138969 0.386326
3
1.726082 0.053175 0.235689 0.302215 0.240005
1.664310 0.013078 0.235689 0.292163 0.233479
1.756541 -0.027506 0.235688 0.307172 0.226875
3
0.665372 0.199277 0.235688 0.130859 0.264620
0.838012 0.307988 0.235689 0.156084 0.284693
0.533348 0.286158 0.235688 0.110213 0.278758
4
1.434852 0.519913 0.235689 0.256080 0.310926
1.343737 0.530551 0.235689 0.243769 0.313077
1.172933 0.470555 0.235689 0.206746 0.300377
1.560193 0.350244 0.235689 0.275219 0.288348
3
1.172933 0.470555 0.235689 0.206746 0.300377
0.838012 0.307988 0.235689 0.156084 0.284693
0.962813 0.107973 0.235688 0.179615 0.251607
4
1.123955 0.760559 0.235689 0.202338 0.352716
0.838012 0.307988 0.235689 0.156084 0.284693
1.172933 0.470555 0.235689 0.206746 0.300377
1.311882 0.606383 0.235689 0.228519 0.332128
3
0.395746 0.429056 0.235688 0.083146 0.305039
0.444260 0.551479 0.235689 0.092973 0.326465
0.282232 0.575044 0.235688 0.068968 0.326220
4
1.123955 0.760559 0.235689 0.202338 0.352716
0.477142 0.389480 0.235688 0.100227 0.295153
0.533348 0.286158 0.235688 0.110213 0.278758
0.838012 0.307988 0.235689 0.156084 0.284693
4
0.901101 0.892049 0.235689 0.166416 0.373942
0.444260 0.551479 0.235689 0.092973 0.326465
0.477142 0.389480 0.235688 0.100227 0.295153
1.123955 0.760559 0.235689 0.202338 0.352716
4
0.282232 0.575044 0.235688 0.068968 0.326220
0.444260 0.551479 0.235689 0.092973 0.326465
0.901101 0.892049 0.235689 0.166416 0.373942
0.729540 0.972106 0.235689 0.138969 0.386326
3
0.576558 1.152173 0.235689 0.112141 0.416703
0.590581 0.966584 0.235689 0.109054 0.385642
0.687818 1.039204 0.235689 0.125522 0.402614
4
0.576558 1.152173 0.235689 0.112141 0.416703
0.172995 0.890212 0.235689 0.052695 0.376649
0.227498 0.690170 0.235689 0.060276 0.345169
0.590581 0.966584 0.235689 0.109054 0.385642
4
1.111268 0.058838 0.235688 0.202163 0.240926
1.560193 0.350244 0.235689 0.275219 0.288348
1.172933 0.470555 0.235689 0.206746 0.300377
0.962813 0.107973 0.235688 0.179615 0.251607
4
1.111268 0.058838 0.235688 0.202163 0.240926
1.446309 0.022174 0.235689 0.256686 0.234960
1.474903 0.116021 0.235689 0.265098 0.251842
1.560193 0.350244 0.235689 0.275219 0.288348
4
1.560193 0.350244 0.235689 0.275219 0.288348
1.474903 0.116021 0.235689 0.265098 0.251842
1.538208 0.022970 0.235689 0.277547 0.233210
1.678319 0.172777 0.235689 0.294442 0.259468
4
1.726082 0.053175 0.235689 0.302215 0.240005
1.678319 0.172777 0.235689 0.294442 0.259468
1.538208 0.022970 0.235689 0.277547 0.233210
1.664310 0.013078 0.235689 0.292163 0.233479
3
0.665372 0.199277 0.235688 0.130859 0.264620
0.843705 0.136187 0.235688 0.154058 0.255124
0.838012 0.307988 0.235689 0.156084 0.284693
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

+165
View File
@@ -0,0 +1,165 @@
/*
* Copyright 2008, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Alexandre Deckner <alex@zappotek.com>
*/
#include "StaticMesh.h"
#include <Application.h>
#include <Resources.h>
#include <Roster.h>
#include <File.h>
#include <String.h>
#include <stdlib.h>
#include <stdio.h>
StaticMesh::StaticMesh(const char* name)
:
fFaces(NULL),
fFaceCount(0)
{
// TODO : move that in a utility class
//BString fileName;
//fileName << "data/" << name << ".hk3d";
//_LoadText(fileName);
//fileName << ".bin";
//_WriteBinary(fileName);
_ReadResource(name);
}
StaticMesh::~StaticMesh()
{
delete [] fFaces;
}
void
StaticMesh::_ReadText(const char* fileName)
{
FILE* f = fopen(fileName, "r");
if (f == NULL) {
printf("Mesh::_ReadText, error accessing %s\n", fileName);
return;
}
fscanf(f, "%lu", &fFaceCount);
fFaces = new Face[fFaceCount];
for (uint32 i = 0; i < fFaceCount; i++) {
uint32 vertexCount = 0;
fscanf(f, "%lu", &vertexCount);
fFaces[i].vertexCount = vertexCount;
for (uint32 vi = 0; vi < vertexCount; vi++) {
float x, y, z, u, v;
fscanf(f, "%f %f %f %f %f", &x, &y, &z, &v, &u);
fFaces[i].v[vi].p.setValue(x, y, z);
fFaces[i].v[vi].u = v;
fFaces[i].v[vi].v = 1.0 - u;
}
}
fclose(f);
printf("Mesh::_ReadText, loaded %s (%lu faces)\n", fileName, fFaceCount);
}
void
StaticMesh::_WriteBinary(const char* fileName)
{
BFile file(fileName, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
if (file.InitCheck() != B_OK) {
printf("Mesh::_WriteBinary, error accessing %s\n", fileName);
return;
}
file.Write(&fFaceCount, sizeof(uint32));
for (uint32 i = 0; i < fFaceCount; i++) {
file.Write(&fFaces[i].vertexCount, sizeof(uint16));
for (uint32 vi = 0; vi < fFaces[i].vertexCount; vi++) {
file.Write(&fFaces[i].v[vi], sizeof(Vertex));
}
}
printf("Mesh::_WriteBinary, wrote %s (%lu faces)\n", fileName, fFaceCount);
}
void
StaticMesh::_ReadBinary(const char* fileName)
{
BFile file(fileName, B_READ_ONLY);
if (file.InitCheck() != B_OK) {
printf("Mesh::_ReadBinary, error accessing %s\n", fileName);
return;
}
file.Read(&fFaceCount, sizeof(uint32));
fFaces = new Face[fFaceCount];
for (uint32 i = 0; i < fFaceCount; i++) {
file.Read(&fFaces[i].vertexCount, sizeof(uint16));
for (uint32 vi = 0; vi < fFaces[i].vertexCount; vi++) {
file.Read(&fFaces[i].v[vi], sizeof(Vertex));
}
}
printf("Mesh::_ReadBinary, loaded %s (%lu faces)\n", fileName, fFaceCount);
}
void
StaticMesh::_ReadResource(const char* resourceName)
{
// TODO: factorize with _ReadBinary
app_info info;
be_app->GetAppInfo(&info);
BFile file(&info.ref, B_READ_ONLY);
BResources res;
if (res.SetTo(&file) != B_OK) {
printf("Mesh::_ReadResource, error accessing resources data\n");
return;
}
size_t size;
const void* data = res.LoadResource(B_RAW_TYPE, resourceName, &size);
if (data == NULL) {
printf("Mesh::_ReadResource, can't access resource %s\n", resourceName);
return;
}
BMemoryIO memoryIO(data, size);
memoryIO.Read(&fFaceCount, sizeof(uint32));
fFaces = new Face[fFaceCount];
for (uint32 i = 0; i < fFaceCount; i++) {
memoryIO.Read(&fFaces[i].vertexCount, sizeof(uint16));
for (uint32 vi = 0; vi < fFaces[i].vertexCount; vi++) {
memoryIO.Read(&fFaces[i].v[vi], sizeof(Vertex));
}
}
printf("Mesh::_ReadResource, loaded %s (%lu faces)\n", resourceName,
fFaceCount);
}
Face&
StaticMesh::GetFace(uint32 index) const
{
return fFaces[index];
}
uint32
StaticMesh::FaceCount() const
{
return fFaceCount;
}
+33
View File
@@ -0,0 +1,33 @@
/*
* Copyright 2009, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Alexandre Deckner <alex@zappotek.com>
*/
#ifndef _STATICMESH_H
#define _STATICMESH_H
#include "Mesh.h"
#include "Vector3.h"
class StaticMesh : public Mesh {
public:
StaticMesh(const char* fileName);
virtual ~StaticMesh();
virtual Face& GetFace(uint32 index) const;
virtual uint32 FaceCount() const;
protected:
void _ReadText(const char* fileName);
void _WriteBinary(const char* fileName);
void _ReadBinary(const char* fileName);
void _ReadResource(const char* resourceName);
Face* fFaces;
uint32 fFaceCount;
};
#endif /* _STATICMESH_H */
@@ -0,0 +1,52 @@
/*
* Copyright 2009, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Alexandre Deckner <alex@zappotek.com>
*/
#include "BitmapTexture.h"
#include <Bitmap.h>
#include <opengl/GL/gl.h>
#include <opengl/GL/glu.h>
#include <stdio.h>
BitmapTexture::BitmapTexture(BBitmap* bitmap)
:
Texture()
{
_Load(bitmap);
}
BitmapTexture::~BitmapTexture()
{
}
void
BitmapTexture::_Load(BBitmap* bitmap) {
if (bitmap == NULL)
return;
glGenTextures(1, &fId);
glBindTexture(GL_TEXTURE_2D, fId);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 4,
(int) bitmap->Bounds().Width() + 1,
(int) bitmap->Bounds().Height() + 1,
0, GL_BGRA, GL_UNSIGNED_BYTE,
bitmap->Bits());
printf("BitmapTexture::_Load, loaded texture %u (%li, %li, %libits)\n",
fId, (int32) bitmap->Bounds().Width(),
(int32) bitmap->Bounds().Height(),
8 * bitmap->BytesPerRow() / (int)bitmap->Bounds().Width());
delete bitmap;
}
+24
View File
@@ -0,0 +1,24 @@
/*
* Copyright 2009, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Alexandre Deckner <alex@zappotek.com>
*/
#ifndef _BITMAP_TEXTURE_H
#define _BITMAP_TEXTURE_H
#include "Texture.h"
class BBitmap;
class BitmapTexture : public Texture {
public:
BitmapTexture(BBitmap* bitmap);
virtual ~BitmapTexture();
protected:
void _Load(BBitmap* bitmap);
};
#endif /* _BITMAP_TEXTURE_H */
@@ -0,0 +1,136 @@
/*
* Copyright 2008, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Alexandre Deckner <alex@zappotek.com>
*/
#include "VideoFileTexture.h"
#include <Bitmap.h>
#include <Entry.h>
#include <MediaFile.h>
#include <MediaTrack.h>
#include <opengl/GL/gl.h>
#include <opengl/GL/glu.h>
#include <string.h>
#include <stdio.h>
VideoFileTexture::VideoFileTexture(const char* fileName)
:
Texture(),
fMediaFile(NULL),
fVideoTrack(NULL),
fVideoBitmap(NULL)
{
_Load(fileName);
}
VideoFileTexture::~VideoFileTexture()
{
delete fVideoBitmap;
if (fMediaFile != NULL) {
fMediaFile->ReleaseAllTracks();
fMediaFile->CloseFile();
delete fMediaFile;
}
}
void
VideoFileTexture::_Load(const char* fileName)
{
BEntry entry(fileName);
entry_ref ref;
entry.GetRef(&ref);
fMediaFile = new BMediaFile(&ref);
status_t err = fMediaFile->InitCheck();
if (err != B_OK) {
printf("cannot contruct BMediaFile object -- %s\n", strerror(err));
return;
}
int32 trackCount = fMediaFile->CountTracks();
for (int32 i = 0; i < trackCount; i++) {
BMediaTrack* track = fMediaFile->TrackAt(i);
if (track == NULL) {
printf("cannot contruct BMediaTrack object\n");
return;
}
// get the encoded format
media_format format;
err = track->EncodedFormat(&format);
if (err != B_OK) {
printf("BMediaTrack::EncodedFormat error -- %s\n", strerror(err));
return;
}
if (format.type == B_MEDIA_ENCODED_VIDEO) {
fVideoTrack = track;
// allocate a bitmap large enough to contain the decoded frame.
BRect bounds(0.0, 0.0,
format.u.encoded_video.output.display.line_width - 1.0,
format.u.encoded_video.output.display.line_count - 1.0);
fVideoBitmap = new BBitmap(bounds, B_RGB32);
// specifiy the decoded format. we derive this information from
// the encoded format.
memset(&format, 0, sizeof(media_format));
format.u.raw_video.last_active = (int32) (bounds.Height() - 1.0);
format.u.raw_video.orientation = B_VIDEO_TOP_LEFT_RIGHT;
format.u.raw_video.pixel_width_aspect = 1;
format.u.raw_video.pixel_height_aspect = 3;
format.u.raw_video.display.format = fVideoBitmap->ColorSpace();
format.u.raw_video.display.line_width = (int32) bounds.Width();
format.u.raw_video.display.line_count = (int32) bounds.Height();
format.u.raw_video.display.bytes_per_row =
fVideoBitmap->BytesPerRow();
err = fVideoTrack->DecodedFormat(&format);
if (err != B_OK) {
printf("error with BMediaTrack::DecodedFormat() -- %s\n",
strerror(err));
return;
}
// Create Texture
glGenTextures(1, &fId);
glBindTexture(GL_TEXTURE_2D, fId);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 4,
(int) fVideoBitmap->Bounds().Width() + 1,
(int) fVideoBitmap->Bounds().Height() + 1,
0, GL_BGRA, GL_UNSIGNED_BYTE, fVideoBitmap->Bits());
}
}
}
void
VideoFileTexture::Update(float /*dt*/) {
// TODO loop
int64 frameCount = 0;
media_header mh;
status_t err =
fVideoTrack->ReadFrames(fVideoBitmap->Bits(), &frameCount, &mh);
if (err) {
printf("BMediaTrack::ReadFrames error -- %s\n", strerror(err));
return;
}
glBindTexture(GL_TEXTURE_2D, fId);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,
(int)fVideoBitmap->Bounds().Width() + 1,
(int)fVideoBitmap->Bounds().Height() + 1,
GL_BGRA, GL_UNSIGNED_BYTE, fVideoBitmap->Bits());
}
@@ -0,0 +1,33 @@
/*
* Copyright 2009, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Alexandre Deckner <alex@zappotek.com>
*/
#ifndef _VIDEO_FILE_TEXTURE_H
#define _VIDEO_FILE_TEXTURE_H
#include "Texture.h"
class BMediaFile;
class BMediaTrack;
class BBitmap;
class VideoFileTexture : public Texture {
public:
VideoFileTexture(const char* fileName);
virtual ~VideoFileTexture();
virtual void Update(float dt);
protected:
void _Load(const char* fileName);
BMediaFile* fMediaFile;
BMediaTrack* fVideoTrack;
BBitmap* fVideoBitmap;
};
#endif /* _VIDEO_TEXTURE_H */