Adding StreamUtils for common debug output

This commit is contained in:
Andrew Meadows 2014-03-25 15:29:22 -07:00
parent 5934a17475
commit 06fbd49ffa
4 changed files with 124 additions and 2 deletions

View file

@ -0,0 +1,75 @@
//
// StreamUtils.cpp
//
// Created by Andrew Meadows on 2014.02.21
// Copyright (c) 2014 High Fidelity, Inc. All rights reserved.
//
#include <glm/gtc/type_ptr.hpp>
#include "StreamUtils.h"
const char* hex_digits = "0123456789abcdef";
void StreamUtil::dump(std::ostream& s, const QByteArray& buffer) {
int row_size = 32;
int i = 0;
while (i < buffer.size()) {
for(int j = 0; i < buffer.size() && j < row_size; ++j) {
char byte = buffer[i];
s << hex_digits[(byte >> 4) & 0x0f] << hex_digits[byte & 0x0f] << " ";
++i;
}
s << "\n";
}
}
std::ostream& operator<<(std::ostream& s, const glm::vec3& v) {
s << "<" << v.x << " " << v.y << " " << v.z << ">";
return s;
}
std::ostream& operator<<(std::ostream& s, const glm::quat& q) {
s << "<" << q.x << " " << q.y << " " << q.z << " " << q.w << ">";
return s;
}
std::ostream& operator<<(std::ostream& s, const glm::mat4& m) {
s << "[";
for (int j = 0; j < 4; ++j) {
s << " " << m[0][j] << " " << m[1][j] << " " << m[2][j] << " " << m[3][j] << ";";
}
s << " ]";
return s;
}
// less common utils can be enabled with DEBUG
#ifdef DEBUG
std::ostream& operator<<(std::ostream& s, const CollisionInfo& c) {
s << "{penetration=" << c._penetration
<< ", contactPoint=" << c._contactPoint
<< ", addedVelocity=" << c._addedVelocity
<< "}";
return s;
}
std::ostream& operator<<(std::ostream& s, const SphereShape& sphere) {
s << "{type='sphere', center=" << sphere.getPosition()
<< ", radius=" << sphere.getRadius()
<< "}";
return s;
}
std::ostream& operator<<(std::ostream& s, const CapsuleShape& capsule) {
s << "{type='capsule', center=" << capsule.getPosition()
<< ", radius=" << capsule.getRadius()
<< ", length=" << (2.f * capsule.getHalfHeight())
<< ", begin=" << capsule.getStartPoint()
<< ", end=" << capsule.getEndPoint()
<< "}";
return s;
}
#endif // DEBUG

View file

@ -0,0 +1,39 @@
//
// StreamUtils.h
//
// Created by Andrew Meadows on 2014.02.21
// Copyright (c) 2014 High Fidelity, Inc. All rights reserved.
//
#ifndef __tests__StreamUtils__
#define __tests__StreamUtils__
#include <iostream>
#include <QByteArray>
#include <glm/glm.hpp>
#include <glm/gtx/quaternion.hpp>
namespace StreamUtil {
// dump the buffer, 32 bytes per row, each byte in hex, separated by whitespace
void dump(std::ostream& s, const QByteArray& buffer);
}
std::ostream& operator<<(std::ostream& s, const glm::vec3& v);
std::ostream& operator<<(std::ostream& s, const glm::quat& q);
std::ostream& operator<<(std::ostream& s, const glm::mat4& m);
// less common utils can be enabled with DEBUG
#ifdef DEBUG
#include "CollisionInfo.h"
#include "SphereShape.h"
#include "CapsuleShape.h"
std::ostream& operator<<(std::ostream& s, const CollisionInfo& c);
std::ostream& operator<<(std::ostream& s, const SphereShape& shape);
std::ostream& operator<<(std::ostream& s, const CapsuleShape& capsule);
#endif // DEBUG
#endif // __tests__StreamUtils__

View file

@ -13,12 +13,17 @@
#include <CollisionInfo.h>
#include <SharedUtil.h>
#include <StreamUtils.h>
#include "CollisionInfoTests.h"
#include "PhysicsTestUtil.h"
/*
static glm::vec3 xAxis(1.f, 0.f, 0.f);
static glm::vec3 xZxis(0.f, 1.f, 0.f);
static glm::vec3 xYxis(0.f, 0.f, 1.f);
void CollisionInfoTests::rotateThenTranslate() {
CollisionInfo collision;
collision._penetration = xAxis;

View file

@ -16,11 +16,14 @@
#include <ShapeCollider.h>
#include <SharedUtil.h>
#include <SphereShape.h>
#include <StreamUtils.h>
#include "PhysicsTestUtil.h"
#include "ShapeColliderTests.h"
const glm::vec3 origin(0.f);
static const glm::vec3 xAxis(1.f, 0.f, 0.f);
static const glm::vec3 yAxis(0.f, 1.f, 0.f);
static const glm::vec3 zAxis(0.f, 0.f, 1.f);
void ShapeColliderTests::sphereMissesSphere() {
// non-overlapping spheres of unequal size