Why is my ball using acceleration as velocity? - c++

I got an object of type ball which is a subclass of the class Particle. This class has three members position, velocity and acceleration of type Vector.
On each frame, when myball.update is called, its velocity is summed to the position and the acceleration is summed to the velocity. Then the ball is drawn on the screen. Anyway for some unclear motive whatever value I give as a velocity the ball doesn't move, but it moves in non - accelerated uniform movement if I give a value as the acceleration.
Here are my classes Vector:
class Vector {
private:
void updateC() {
x = cos(a) * l;
y = sin(a) * l;
}
void updateT() {
a = atan2(y, x);
l = sqrt(x * x + y * y);
}
public:
float x = 0, y = 0;
float a = 0, l = 0;
Vector() {
}
Vector(float nx, float ny): x(nx), y(ny) {
updateT();
}
void X(float nx) {
x = nx;
updateT();
}
void Y(float ny) {
y = ny;
updateT();
}
void A(float na) {
a = na;
updateC();
}
void L(float nl) {
l = nl;
updateC();
}
Vector operator +(Vector other) {
return Vector(x + other.x, y + other.y);
}
Vector operator -(Vector other) {
return Vector(x - other.x, y - other.y);
}
Vector operator *(float m) {
Vector result(x, y);
result.L(l * m);
return result;
}
void operator +=(Vector other) {
x += other.x;
y += other.y;
updateT();
}
void operator -=(Vector other) {
x -= other.x;
y -= other.y;
updateT();
}
void operator *=(float m) {
l *= m;
updateC();
}
};
Particle:
class Particle {
public:
Vector position;
Vector velocity;
Vector gravity;
Particle() {}
Particle(Vector np, Vector nv = Vector(0, 0), Vector na = Vector(0, 0)): position(np), velocity(na), gravity(na) {}
void accelerate(Vector a) {
velocity += a;
}
void update() {
position += velocity;
velocity += gravity;
}
};
And ball:
class ball: public Particle {
public:
ball(Vector p, Vector v, Vector a): Particle(p, v, a) {}
void update() {
Particle::update();
graphics.circle("fill", position.x, position.y, 10);
}
};
So, as I said before, if I initialize myball with a velocity different than 0, the ball still won't move, but it will move if I inititialize it with an acceleration different than 0 using acceleration as velocity.
What did I do wrong?

You have a typo in the Particle constructor:
Particle(Vector np, Vector nv = Vector(0, 0), Vector na = Vector(0, 0)): position(np), velocity(na), gravity(na) {}
It must be:
Particle(Vector np, Vector nv = Vector(0, 0), Vector na = Vector(0, 0)): position(np), velocity(nv), gravity(na) {}

Related

How to use Class? (with poor English ability)

Code that implements Vectors as Class and inputs and outputs them as txt files.
I was temporarily implementing a function of Class, but I have a question because there is an error.
I tried to add vectorA and vectorB as Add functions in the main function and replace them with vectorO to printf.
However, in the Vector output part of the Add function, the error No default creator of the Vector class continues to appear. How should we solve this problem?
#include<stdio.h>
class Vector
{
public: // private?
double x, y, z;
public:
Vector(int x, int y, int z) {
x = x;
y = y;
z = z;
}
double Magnitude(void);
Vector Add(Vector v) {
Vector output;
output.x = x + v.x;
output.y = y + v.y;
output.z = z + v.z;
return output;
}
Vector Subract(Vector v);
double DotProduct(Vector v);
Vector CrossProduct(Vector v);
};
int main()
{
Vector vectorA(1, 2, 3);
Vector vectorB(4, 5, 6);
Vector vectorO = vectorA.Add(vectorB);
printf("(%d, %d, %d)\n", vectorO.x, vectorO.y, vectorO.z); // (5, 7, 9)
return 0;
}
Even if I put this code in the Vector class, I get a strange value.
Vector() {
x = x;
y = y;
z = z;
}
This should fix your errors. have a basic and an overrided contructors, also be careful of the variable names they shouldn't be the same
#include<stdio.h>
class Vector
{
public: // private?
double x, y, z;
public:
Vector() {
x = 0;
y = 0;
z = 0;
}
Vector(int _x, int _y, int _z) {
x = _x;
y = _y;
z = _z;
}
double Magnitude(void);
Vector Add(Vector v) {
Vector output;
output.x = x + v.x;
output.y = y + v.y;
output.z = z + v.z;
return output;
}
Vector Subract(Vector v);
double DotProduct(Vector v);
Vector CrossProduct(Vector v);
};
int main()
{
Vector vectorA(1, 2, 3);
Vector vectorB(4, 5, 6);
Vector vectorO = vectorA.Add(vectorB);
printf("(%d, %d, %d)\n", vectorO.x, vectorO.y, vectorO.z); // (5, 7, 9)
return 0;
}
Read More Here

How to make inherited class different from parent only by one value in C++?

I'm trying to write a class for the UnitVector, having already written the one for a generic Vector. The UnitVector class diverges from the Vector class only by the fact that the abs variable is set to 1.0f. I'd like to know what the best approach to the problem would be, whether it's better to make another class, UnitVector, that inherits the Vector class (my current idea, that's giving me problems) or to just write a method in the Vector class
Here's my code for the class Vector:
Vector.h
class Vector
{
public:
Vector();
Vector(float x, float y);
void set_by_angle(float abs, float angle);
void set(float x, float y);
void rotate(float angle);
void scale(float scale_factor);
void translate(float x, float y);
void translate(Vector v);
float get_abs();
float get_angle();
static Vector create_by_angle(float abs, float angle);
static Vector create(float x, float y);
static Vector create_from_vectors(Vector v1, Vector v2, float abs);
static float get_distance(Vector v1, Vector v2);
static float get_angle(float x, float y);
static float get_angle(Vector v);
void to_string();
Vector operator=(const Vector &v);
bool operator==(const Vector &v);
bool operator!=(const Vector &v);
Vector operator+=(const Vector &v);
friend Vector operator+(const Vector &v1, const Vector &v2);
friend Vector operator-(const Vector &v1, const Vector &v2);
float x;
float y;
private:
float abs;
float angle;
};
Vector.cpp
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <string>
#include "vector.h"
using namespace std;
Vector::Vector() : Vector(0, 0) {}
Vector::Vector(float x, float y)
{
set(x, y);
}
void Vector::set_by_angle(float abs, float angle)
{
this->abs = abs;
this->angle = angle;
x = abs * cos(angle);
y = abs * sin(angle);
}
void Vector::set(float x, float y)
{
this->x = x;
this->y = y;
abs = get_abs();
angle = get_angle();
}
void Vector::rotate(float angle)
{
set_by_angle(this->abs, this->angle + angle);
}
void Vector::scale(float scale_factor)
{
set(x * scale_factor, y * scale_factor);
}
void Vector::translate(float x, float y)
{
set(this->x + x, this->y + y);
}
void Vector::translate(Vector v)
{
translate(v.x, v.y);
}
float Vector::get_abs()
{
return sqrt(pow(x, 2) + pow(y, 2));
}
float Vector::get_angle()
{
return get_angle(x, y);
}
Vector Vector::create_by_angle(float abs, float angle)
{
Vector v;
v.set_by_angle(abs, angle);
return v;
}
Vector Vector::create(float x, float y)
{
Vector v;
v.set(x, y);
return v;
}
float Vector::get_distance(Vector v1, Vector v2)
{
return sqrt(pow(v1.x - v2.x, 2) + pow(v1.y - v2.y, 2));
}
Vector Vector::create_from_vectors(Vector v1, Vector v2, float abs)
{
float x = v2.x - v1.x;
float y = v2.y - v1.y;
Vector v;
v.set_by_angle(abs, Vector(x, y).get_angle());
return v;
}
float Vector::get_angle(float x, float y)
{
float tan = 0.0f;
float angle = 0.0f;
if (x != 0)
{
tan = y / x;
angle = atan(tan);
// this setting applies to the graphic reference system
if (x > 0 && y < 0) angle = 2 * M_PI + angle;
if (x < 0 && y > 0) angle += M_PI;
if (x < 0 && y < 0) angle += M_PI;
}
if (x == 0)
{
if (y > 0) angle = M_PI_2;
if (y < 0) angle = 3 * M_PI_2;
}
if (y == 0)
{
if (x > 0) angle = 0.0f;
if (x < 0) angle = M_PI;
}
return angle;
}
float Vector::get_angle(Vector v)
{
return get_angle(v.x, v.y);
}
void Vector::to_string()
{
cout << "x: " + std::to_string(x) + " y: " + std::to_string(y) << endl;
}
Vector operator+(const Vector &v1, const Vector &v2)
{
Vector tmp;
tmp.set(v1.x + v2.x, v1.y + v2.y);
return tmp;
}
Vector operator-(const Vector &v1, const Vector &v2)
{
return v1 + Vector(-v2.x, -v2.y);
}
Vector Vector::operator+=(const Vector &v)
{
set(x + v.x, y + v.y);
return *this;
}
Vector Vector::operator=(const Vector &v)
{
set(v.x, v.y);
return *this;
}
bool Vector::operator==(const Vector &v)
{
return
(
(x == v.x)
&&
(y == v.y)
);
}
bool Vector::operator!=(const Vector &v)
{
return !(*this == v);
}
Thanks in advance!
Just add the following two methods:
void normalize()
{
float scalar = 1.0 / this->get_abs();
this->x *= scalar;
this->y *= scalar;
}
And:
static Vector get_unit(const Vector &v)
{
float scalar = 1.0 / v.get_abs();
return Vector(v.x * scalar, v.y * scalar);
}

Removing an object from a vector by index

I have a for loop that looks like this:
for (int i = Particles.size() - 1; i >= 0; i--) {
if (Particles[i].Dead) {
Particles.erase(Particles.begin() + i);
}
}
When I compile, I get this error:
Error C2280 'Particle &Particle::operator =(const Particle &)': attempting to reference a deleted function
Gravity C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xutility 2518
Anyone know what I'm doing wrong? Here's the particle code.
Header file
class Particle
{
public:
const float G = 6.674 * pow(10, -11);
float Mass, Radius;
Vector2 Position, Velocity, Force;
bool Dead = false;
void Gravity(Particle Particle2);
void Move();
void Draw(SDL_Surface *Surface, Uint32 Color);
Particle(float MassBounds[2], Vector2 PositionBounds[2], float Density);
Particle::Particle(float Mass, Vector2 Position, float Density, bool NonRandom);
Particle();
};
Source file
void Particle::Gravity(Particle Particle2)
{
float GravityMagnitude = (Particle::G*Mass*Particle2.Mass) / Vector2::DistanceSquared(Position, Particle2.Position);
Force += (Particle2.Position - Position).Normalised()*GravityMagnitude;
}
void Particle::Move()
{
Velocity += Force/Mass;
Position += Velocity;
}
void Particle::Draw(SDL_Surface *Surface, Uint32 Color)
{
if (int(Radius) > 0) { SDLDrawFilledCircle(Surface, int(Position.x), int(Position.y), Radius<1?1:int(Radius), Color); }
}
Particle::Particle(float MassBounds[2], Vector2 PositionBounds[2], float Density)
{
Mass = RandRange(MassBounds);
Position = Vector2(RandRange(PositionBounds[0].x, PositionBounds[1].x), RandRange(PositionBounds[0].y, PositionBounds[1].y));
Radius = pow((3.0 * Mass) / (4 * M_PI*Density), 1.0 / 3.0);
Velocity = Vector2();
Force = Vector2();
}
Particle::Particle(float Mass, Vector2 Position, float Density, bool NonRandom)
{
this->Mass = Mass;
this->Position = Position;
Radius = pow((3.0 * Mass) / (4 * M_PI*Density), 1.0 / 3.0);
Velocity = Vector2();
Force = Vector2();
}
Particle::Particle()
{
Mass = 1;
Position = Vector2();
Radius = 1;
Velocity = Vector2();
Force = Vector2();
}
inline bool operator==(const Particle& a, const Particle& b) { return a == b; }
You may have better luck using remove_if and erase:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
struct Vector {
int x;
int y;
};
bool is_negative (Vector a) {
return a.x < 0 && a.y < 0;
}
int main() {
vector<Vector> vectors;
vectors.push_back({-1, -2});
vectors.push_back({-1, 2});
vectors.push_back({1, 2});
vectors.push_back({-1, -2});
vectors.erase(
std::remove_if(vectors.begin(), vectors.end(), is_negative),
vectors.end());
for (auto v : vectors) {
cout << v.x << " " << v.y << endl;
}
}
I could not help notice this in your for loop:
Particles.erase(Particles.begin() + i-1)
More importantly
i - 1
You start with
i = Particles.size() - 1
and do not stop until
i < 0
This
Particles.begin()
gives you the head of the list.
When
i == 0
Particles.begin() + (i - 1)
will try to get invalid node.
Which translates to
Particles.begin() - 1
I do not know when your code breaks, I am going based on your loop
Here is link w/doc http://www.cplusplus.com/reference/vector/vector/erase/
Hope this helps

Line defined as start and lenght + orientation differs from start and end point definition - wrong orientation calculation?

I am trying to write some position/orientation methods for my small & simple 3d-space calculation library. But I'm stuck on the following problem.
I store 3d line as start and end points. However it should be possible to store it as start point and line's length + orientation as well (it's just a good example to test if orientation calculations works).
By orientation I mean rotation from the initial "0" orientation (which places the end at start + [0,legth,0]). So I first rotate the [0,length,0] by orientation and then add start to it to get end point.
The problem is, my orientation calculations fails somewhere. After calculating the orientation I get different ending point.
I use left-handed coordinate system with Y-axis pointing up, but I don't think it's important here.
Here's the code (I've tried to name the methods in the way you can check if the steps are ok; here's the full source code if you want to compile it yourself):
Point3D start = { 5.0f, 4.0f, 7.0f };
Point3D end = { 15.0f, 6.0f, 14.0f };
Point3D direction = (end - start);
std::wcout << L"Direction: "; direction.output();
float angle = Point3D(0.0f, 1.0f, 0.0f).getAngleToAnotherVectorInRadians(direction);
Point3D axis = direction.getCrossProduct(Point3D(0.0f, 1.0f, 0.0f)).getNormalized();
Quaternion o = Quaternion(AxisAngle(axis, angle));
std::wcout << L"\nAxisAngle: "; AxisAngle(axis, angle).output();
std::wcout << L"\nOrientation: "; o.output();
//test - end2 should be equal to end
Point3D offset(0.0f, (end - start).getLengthAsVector(), 0.0f);
offset = o.rotatePoint(offset);
std::wcout << L"\nOffset: "; offset.output();
Point3D end2 = start + offset;
std::wcout << L"\nEnd2: "; end2.output();
The code produces such output (without a comments, of course):
Direction: {10, 2, 7} //looks ok
AxisAngle: {{-0.573462, 0, 0.819232}, 1.40839}
Orientation: {-0.371272, 0, 0.530388, 0.762132}
Offset: {-10, 2, -7} //Almost! It should be {10, 2, 7}
End2: {-5, 6, -9.53674e-07} //Wrong! It should be { 15, 6, 14 }
In case that all steps are ok but there are some mistakes in methods' implementations I post here the important code for classes (so you can reproduce the problem): Point3D, AxisAngle, Quaternion.
I highly believe that problem(s) lay(s) in my main steps or in AxisAngle calculations. I think that AxisAngle to Quaternion transformation is ok (but I pass the wrong AxisAngle to Quaternion constructor).
The Point3D:
struct Point3D {
protected:
float x, y, z;
public:
Point3D() : x(0.0f), y(0.0f), z(0.0f) {}
Point3D(float x, float y, float z) : x(x), y(y), z(z) {}
void output() { std::wcout << L"{" << x << L", " << y << L", " << z << L"}"; }
Point3D operator-(const Point3D &point) const {
Point3D temp;
temp.setX(getX() - point.getX());
temp.setY(getY() - point.getY());
temp.setZ(getZ() - point.getZ());
return temp;
}
Point3D operator+ (const Point3D &value) const {
Point3D temp;
temp.setX(getX() + value.getX());
temp.setY(getY() + value.getY());
temp.setZ(getZ() + value.getZ());
return temp;
}
inline float getX() const { return x; } inline float getY() const { return y; } inline float getZ() const { return z; }
inline void setX(float x) { this->x = x; } inline void setY(float y) { this->y = y; } inline void setZ(float z) { this->z = z; }
inline float getLengthAsVector() const {
return sqrt(x*x + y*y + z*z);
}
inline Point3D getCrossProduct(const Point3D &anotherVector) const {
//based on: http://www.sciencehq.com/physics/vector-product-multiplying-vectors.html
return Point3D(
y * anotherVector.z - anotherVector.y * z,
z * anotherVector.x - anotherVector.z * x,
x * anotherVector.y - anotherVector.x * y
);
}
inline float getDotProduct(const Point3D &anotherVector) const {
//based on: https://www.ltcconline.net/greenl/courses/107/Vectors/DOTCROS.HTM
return x * anotherVector.x + y * anotherVector.y + z * anotherVector.z;
}
inline float getAngleToAnotherVectorInRadians(const Point3D &anotherVector) const {
//based on: http://math.stackexchange.com/questions/974178/how-to-calculate-the-angle-between-2-vectors-in-3d-space-given-a-preset-function
return acos(getDotProduct(anotherVector) / (getLengthAsVector() * anotherVector.getLengthAsVector()));
}
Point3D getNormalized() const {
float length = std::abs(sqrt(x*x + y*y + z*z));
Point3D result(x / length, y / length, z / length);
return result;
}
};
The AxisAngle:
class AxisAngle {
protected:
Point3D axis;
float angleInRadians;
public:
AxisAngle(const AxisAngle &other) { axis = other.axis; angleInRadians = other.angleInRadians; }
AxisAngle::AxisAngle(float x, float y, float z, float angleInRadians) {
this->axis = Point3D(x, y, z);
this->angleInRadians = angleInRadians;
}
AxisAngle::AxisAngle(const Point3D &axis, float angleInRadians) {
this->axis = axis;
this->angleInRadians = angleInRadians;
}
Point3D getAxis() const { return axis; }
float getAngleInRadians() const { return angleInRadians; }
void output() { std::wcout << L"{"; axis.output(); std::wcout << L", " << angleInRadians << L"}"; }
};
And last but not least, Quaternion:
class Quaternion {
protected:
float x; float y; float z; float w;
public:
Quaternion() { x = 0.0f; y = 0.0f; z = 0.0f; w = 1.0f; }
Quaternion(const Quaternion &other) { x = other.x; y = other.y; z = other.z; w = other.w; }
Quaternion(float x, float y, float z, float w) { this->x = x; this->y = y; this->z = z; this->w = w; }
Quaternion(const AxisAngle &axisAngle) {
Point3D axis = axisAngle.getAxis();
float angleInRadians = axisAngle.getAngleInRadians();
x = sin(angleInRadians / 2) * axis.getX();
y = sin(angleInRadians / 2) * axis.getY();
z = sin(angleInRadians / 2) * axis.getZ();
w = cos(angleInRadians / 2);
normalizeIt();
}
float getLength() const {
return sqrt(x*x + y*y + z*z + w*w);
}
void normalizeIt() {
float length = getLength();
x = x / length;
y = y / length;
z = z / length;
w = w / length;
}
Quaternion getConjugated() const {
return Quaternion(-x, -y, -z, w);
}
Quaternion multiply(Quaternion by) {
//"R" for result
float wR = w * by.getW() - x * by.getX() - y * by.getY() - z * by.getZ();
float xR = x * by.getW() + w * by.getX() + y * by.getZ() - z * by.getY();
float yR = y * by.getW() + w * by.getY() + z * by.getX() - x * by.getZ();
float zR = z * by.getW() + w * by.getZ() + x * by.getY() - y * by.getX();
return Quaternion(xR, yR, zR, wR);
}
//rotate Point3D p around [0,0,0] with this Quaternion
Point3D rotatePoint(Point3D p) const {
Quaternion temp = multiply(p).multiply(getConjugated());
return Point3D(temp.getX(), temp.getY(), temp.getZ());
//G: P' = Q(P-G)Q' + G <- to rotate P around G with Quaternion
}
Quaternion multiply(Point3D r) const {
float wR = -x * r.getX() - y * r.getY() - z * r.getZ();
float xR = w * r.getX() + y * r.getZ() - z * r.getY();
float yR = w * r.getY() + z * r.getX() - x * r.getZ();
float zR = w * r.getZ() + x * r.getY() - y * r.getX();
return Quaternion(xR, yR, zR, wR);
}
inline float getX() const { return x; } inline void setX(float x) { this->x = x; }
inline float getY() const { return y; } inline void setY(float y) { this->y = y; }
inline float getZ() const { return z; } inline void setZ(float z) { this->z = z; }
inline float getW() const { return w; } inline void setW(float w) { this->w = w; }
void output() { std::wcout << L"{" << x << L", " << y << L", " << z << L", " << w << L"}"; }
};
In case somebody would ask: I do want to use quaternions. They may not look 100% needed here, but storing 3d object's orientation as quaternion has many benefits in more complex computations (and most game engines / 3d software use it as well "under the mask").
Your axis has the wrong orientation. It should be:
Point3D axis = Point3D(0.0f, 1.0f, 0.0f).getCrossProduct(direction).getNormalized();
Use the two left-hand rules to figure out the correct order.

Error: object of abstract class "Sphere" not allowed. and Error: no operator "=" matches these operands

I've been trying to resolve a error for the last day or so and can't seem to work it through.
It's the kind of error that the fix is probably very easy :S
I tried to search for similar questions but the fixes don't apply.
main.c
int main(int argc, char *argv[]){
int width, height;
std::vector<Obj*> world;
world.push_back(new Sphere(Vec(0, 0, -22), 2, Vec(0.2, 0.2, 0.2), true));
(...)
return 0;
}
The error is found when I try to create a Sphere.
Relevant classes
Obj.h
class Obj
{
public:
Vec color;
bool culling;
virtual bool intersect(const Vec &ray_orig, Vec &ray_dir, float *t0 = NULL, float *t1 = NULL) = 0;
};
Sphere.h
class Sphere: public Obj
{
public:
Vec center;
float radius, radius2;
Sphere(Vec center, float radius, Vec color, bool culling);
bool intersect(const Vec &ray_orig, Vec &ray_dir, float *t0 = NULL, float *t1 = NULL);
};
Sphere.c
Sphere::Sphere(Vec center, float radius, Vec color, bool culling){
this->center = center;
this->radius = radius;
this->color = color;
this->culling = culling;
}
bool Sphere::intersect(const Vec &ray_orig, Vec &ray_dir, float *t0 = NULL, float *t1 = NULL) {...}
These second error appears when I do this->color = color;. Not sure if they are related.
Vec is a simple struct with 3 variables.
If you need more information I'll add as soon as possible.
Thank you in advance.
Jose
EDIT
Sorry for the delay.
intersect(...) is the only function in the obj class. Is there anyway to maintain the abstraction since there are several objects(sphere,box,...).
As requested here goes the definition of vec.h
vec.h
struct Vec {
float x, y, z;
Vec() {x = 0, y = 0, z = 0;}
Vec(float val) {x = val, y = val, z = val;}
Vec(float x_val,float y_val,float z_val) {x = x_val, y = y_val, z = z_val;}
Vec(const Vec& copy) : x(copy.x), y(copy.y), z(copy.z) { }
Vec operator+ (const Vec& p) const {
return Vec(x + p.x, y + p.y, z + p.z);
}
Vec operator- (const Vec& p) const {
return Vec(x - p.x, y - p.y, z - p.z);
}
Vec& operator += (const Vec& p) {
x += p.x; y += p.y; z += p.z;
return *this;
}
Vec& operator -= (const Vec& p) {
x -= p.x; y -= p.y; z -= p.z;
return *this;
}
Vec operator* (const float f) const {
return Vec(f * x, f * y, f * z);
}
Vec& operator*= (const float f) {
x *= f; y *= f; z *= f;
return *this;
}
Vec operator/ (const float f) const {
float inv = 1.f / f;
return Vec(inv * x, inv * y, inv * z);
}
Vec& operator/= (const float f) {
float inv = 1.f / f;
x *= inv; y *= inv; z *= inv;
return *this;
}
Vec& operator= (const Vec& p) {
x = p.x; y = p.y; z = p.z;
return *this;
}
bool operator== (const Vec& p) {
if(x == p.x && y == p.y && z == p.z)
return true;
return false;
}
float length_squared() const {
return x*x + y*y + z*z;
}
float length() const {
return sqrt(length_squared());
}
Vec norm() const {
float nor = x * x + y * y + z * z;
if (nor > 0) {
float invNor = 1 / sqrt(nor);
(float)x *= invNor, (float)y *= invNor, (float)z *= invNor;
}
return *this;
}
Vec cross(const Vec&b) {
return Vec(y*b.z-z*b.y,z*b.x-x*b.z,x*b.y-y*b.x);
}
float dot(const Vec& v) {
return x * v.x + y * v.y + z * v.z;
}
};
It seems the problem was indeed in the vec file.
Can't find a reasoning about the fix, but changing the Vec struct to a class fixed all the problems.
Thanks for the help.