View Full Version : converting c code
im trying to convert a c demo and im stuck. heres the code (just 1 line)
nozzleDampForce = - (nozzleVeloc % nozzleDir) * mass * nozzleDampCoef;
ive never seen a % in code before so i dont know what to do with it.
this is how the delphi code is looking so far
LNozzleDampForce := -{(LNozzleVelocity % LNozzleDirection) *} Hovercraft.Mass * LNozzleDampCoef;
LNozzleVelocity, LNozzleDirection are Vectors (array[0..2] of Single) and Hovercraft.Mass, LNozzleDampForce and LNozzleDampCoef are singles.
any help is great as im pulling my hair out over this :D
it's the same like mod :)
hmm, mod a vector? sure i can do that but then what to do with the vector? use the vector length?
[edit]
LTempVector[0] := LNozzleVelocity[0] mod LNozzleDirection[0];
LTempVector[1] := LNozzleVelocity[1] mod LNozzleDirection[1];
LTempVector[2] := LNozzleVelocity[2] mod LNozzleDirection[2];
doesnt work anyway :?
Paulius
24-05-2005, 04:37 PM
I guess it's an overridden operator, post the class of nozzleDir
its a vector, an array of 3 singles
[edit] im so dumb :D heres the c file, from reading it. its just a dot product?
//************************************************** ******************
// Newton Game dynamics
// copyright 2000-2004
// By Julio Jerez
// VC: 6.0
// simple 4d vector class
//************************************************** ******************
#include <stdafx.h>
#ifndef __dVector__
#define __dVector__
#include <math.h>
// small but very effective 4 dimetional template vector class
template<class T>
class TemplateVector
{
public:
TemplateVector ();
TemplateVector (const T *ptr);
TemplateVector (T m_x, T m_y, T m_z, T m_w);
TemplateVector Scale (T s) const;
T& operator[] (int i);
const T& operator[] (int i) const;
TemplateVector operator+ (const TemplateVector &A) const;
TemplateVector operator- (const TemplateVector &A) const;
TemplateVector &operator+= (const TemplateVector &A);
TemplateVector &operator-= (const TemplateVector &A);
// return dot product
T operator% (const TemplateVector &A) const;
// return cross product
TemplateVector operator* (const TemplateVector &B) const;
// component wiise multiplacation
TemplateVector CompProduct (const TemplateVector &A) const;
T m_x;
T m_y;
T m_z;
T m_w;
};
class dVector: public TemplateVector<dFloat32>
{
public:
dVector();
dVector (const TemplateVector<dFloat32>& v);
dVector (const dFloat32 *ptr);
dVector (dFloat32 x, dFloat32 y, dFloat32 z, dFloat32 w = 1.0);
};
template<class T>
TemplateVector<T>::TemplateVector() {}
template<class T>
TemplateVector<T>::TemplateVector(const T *ptr)
{
m_x = ptr[0];
m_y = ptr[1];
m_z = ptr[2];
m_w = 1.0;
}
template<class T>
TemplateVector<T>::TemplateVector(T x, T y, T z, T w)
{
m_x = x;
m_y = y;
m_z = z;
m_w = w;
}
template<class T>
typename T& TemplateVector<T>::operator[] (int i)
{
return (&m_x)[i];
}
template<class T>
typename const T& TemplateVector<T>::operator[] (int i) const
{
return (&m_x)[i];
}
template<class T>
typename TemplateVector<T> TemplateVector<T>::Scale (T scale) const
{
return TemplateVector<T> (m_x * scale, m_y * scale, m_z * scale, m_w);
}
template<class T>
typename TemplateVector<T> TemplateVector<T>::operator+ (const TemplateVector<T> &B) const
{
return TemplateVector<T> (m_x + B.m_x, m_y + B.m_y, m_z + B.m_z, m_w);
}
template<class T>
typename TemplateVector<T>& TemplateVector<T>::operator+= (const TemplateVector<T> &A)
{
m_x += A.m_x;
m_y += A.m_y;
m_z += A.m_z;
return *this;
}
template<class T>
typename TemplateVector<T> TemplateVector<T>::operator- (const TemplateVector<T> &A) const
{
return TemplateVector<T> (m_x - A.m_x, m_y - A.m_y, m_z - A.m_z, m_w);
}
template<class T>
typename TemplateVector<T>& TemplateVector<T>::operator-= (const TemplateVector<T> &A)
{
m_x -= A.m_x;
m_y -= A.m_y;
m_z -= A.m_z;
return *this;
}
template<class T>
typename T TemplateVector<T>::operator% (const TemplateVector<T> &A) const
{
return m_x * A.m_x + m_y * A.m_y + m_z * A.m_z;
}
template<class T>
typename TemplateVector<T> TemplateVector<T>::operator* (const TemplateVector<T> &B) const
{
return TemplateVector<T> (m_y * B.m_z - m_z * B.m_y,
m_z * B.m_x - m_x * B.m_z,
m_x * B.m_y - m_y * B.m_x, m_w);
}
template<class T>
typename TemplateVector<T> TemplateVector<T>::CompProduct (const TemplateVector<T> &A) const
{
return TemplateVector<T> (m_x * A.m_x, m_y * A.m_y, m_z * A.m_z, A.m_w);
}
inline dVector::dVector()
:TemplateVector<dFloat32>()
{
}
inline dVector::dVector (const TemplateVector<dFloat32>& v)
:TemplateVector<dFloat32>(v)
{
}
inline dVector::dVector (const dFloat32 *ptr)
:TemplateVector<dFloat32>(ptr)
{
}
inline dVector::dVector (dFloat32 x, dFloat32 y, dFloat32 z, dFloat32 w)
:TemplateVector<dFloat32>(x, y, z, w)
{
}
#endif
Paulius
24-05-2005, 04:52 PM
template<class T>
typename T TemplateVector<T>::operator% (const TemplateVector<T> &A) const
{
return m_x * A.m_x + m_y * A.m_y + m_z * A.m_z;
}
dotproduct
thanks. but its not giving the result i need :(
Paulius
24-05-2005, 06:17 PM
It's not very clear what kind of result you need and what you get
cragwolf
24-05-2005, 06:32 PM
I think that "LNozzleVelocity % LNozzleDirection" would be equivalent to:
LNozzleVelocity[0] * LNozzleDirection[0] + LNozzleVelocity[1] * LNozzleDirection[1] + LNozzleVelocity[2] * LNozzleDirection[2]
It's not very clear what kind of result you need and what you get
well its for a hovercraft, it sits on springs, i just cant get it to damp properly. ill figure it out
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.