Results 1 to 10 of 10

Thread: converting c code

  1. #1

    converting c code

    im trying to convert a c demo and im stuck. heres the code (just 1 line)

    Code:
    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

    [pascal]LNozzleDampForce := -{(LNozzleVelocity % LNozzleDirection) *} Hovercraft.Mass * LNozzleDampCoef;[/pascal]

    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

  2. #2

    converting c code

    it's the same like mod
    http://www.programuotojas.com

  3. #3

    converting c code

    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 :?

  4. #4

    converting c code

    I guess it's an overridden operator, post the class of nozzleDir

  5. #5

    converting c code

    its a vector, an array of 3 singles

    [edit] im so dumb heres the c file, from reading it. its just a dot product?

    Code:
    //********************************************************************
    // 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
    &#123;
    	public&#58;
    	TemplateVector &#40;&#41;;
    	TemplateVector &#40;const T *ptr&#41;;
    	TemplateVector &#40;T m_x, T m_y, T m_z, T m_w&#41;; 
    	TemplateVector Scale &#40;T s&#41; const;
    
    	T& operator&#91;&#93; &#40;int i&#41;;
    	const T& operator&#91;&#93; &#40;int i&#41; const;
    
    	TemplateVector operator+ &#40;const TemplateVector &A&#41; const; 
    	TemplateVector operator- &#40;const TemplateVector &A&#41; const; 
    	TemplateVector &operator+= &#40;const TemplateVector &A&#41;;
    	TemplateVector &operator-= &#40;const TemplateVector &A&#41;; 
    
    	// return dot product
    	T operator% &#40;const TemplateVector &A&#41; const; 
    
    	// return cross product
    	TemplateVector operator* &#40;const TemplateVector &B&#41; const; 
    
    	// component wiise multiplacation
    	TemplateVector CompProduct &#40;const TemplateVector &A&#41; const;
    
    	T m_x;
    	T m_y;
    	T m_z;
    	T m_w;
    &#125;;
    
    
    class dVector&#58; public TemplateVector<dFloat32>
    &#123;
    	public&#58;
    	dVector&#40;&#41;;
    	dVector &#40;const TemplateVector<dFloat32>& v&#41;;
    	dVector &#40;const dFloat32 *ptr&#41;;
    	dVector &#40;dFloat32 x, dFloat32 y, dFloat32 z, dFloat32 w = 1.0&#41;; 
    &#125;;
    
    
    
    
    
    template<class T>
    TemplateVector<T>&#58;&#58;TemplateVector&#40;&#41; &#123;&#125;
    
    template<class T>
    TemplateVector<T>&#58;&#58;TemplateVector&#40;const T *ptr&#41;
    &#123;
    	m_x = ptr&#91;0&#93;;
    	m_y = ptr&#91;1&#93;;
    	m_z = ptr&#91;2&#93;;
    	m_w = 1.0;
    &#125;
    
    template<class T>
    TemplateVector<T>&#58;&#58;TemplateVector&#40;T x, T y, T z, T w&#41; 
    &#123;
    	m_x = x;
    	m_y = y;
    	m_z = z;
    	m_w = w;
    &#125;
    
    
    template<class T>
    typename T& TemplateVector<T>&#58;&#58;operator&#91;&#93; &#40;int i&#41;
    &#123;
    	return &#40;&m_x&#41;&#91;i&#93;;
    &#125;	
    
    template<class T>
    typename const T& TemplateVector<T>&#58;&#58;operator&#91;&#93; &#40;int i&#41; const
    &#123;
    	return &#40;&m_x&#41;&#91;i&#93;;
    &#125;
    
    template<class T>
    typename TemplateVector<T> TemplateVector<T>&#58;&#58;Scale &#40;T scale&#41; const
    &#123;
    	return TemplateVector<T> &#40;m_x * scale, m_y * scale, m_z * scale, m_w&#41;;
    &#125;
    
    
    template<class T>
    typename TemplateVector<T> TemplateVector<T>&#58;&#58;operator+ &#40;const TemplateVector<T> &B&#41; const
    &#123;
    	return TemplateVector<T> &#40;m_x + B.m_x, m_y + B.m_y, m_z + B.m_z, m_w&#41;;
    &#125;
    
    template<class T>
    typename TemplateVector<T>& TemplateVector<T>&#58;&#58;operator+= &#40;const TemplateVector<T> &A&#41; 
    &#123;
    	m_x += A.m_x;
    	m_y += A.m_y;
    	m_z += A.m_z;
    	return *this;
    &#125;
    
    template<class T>
    typename TemplateVector<T> TemplateVector<T>&#58;&#58;operator- &#40;const TemplateVector<T> &A&#41; const
    &#123;
    	return TemplateVector<T> &#40;m_x - A.m_x, m_y - A.m_y, m_z - A.m_z, m_w&#41;;
    &#125;
    
    template<class T>
    typename TemplateVector<T>& TemplateVector<T>&#58;&#58;operator-= &#40;const TemplateVector<T> &A&#41; 
    &#123;
    	m_x -= A.m_x;
    	m_y -= A.m_y;
    	m_z -= A.m_z;
    	return *this;
    &#125;
    
    
    template<class T>
    typename T TemplateVector<T>&#58;&#58;operator% &#40;const TemplateVector<T> &A&#41; const
    &#123;
    	return m_x * A.m_x + m_y * A.m_y + m_z * A.m_z;
    &#125;
    
    
    template<class T>
    typename TemplateVector<T> TemplateVector<T>&#58;&#58;operator* &#40;const TemplateVector<T> &B&#41; const
    &#123;
    	return TemplateVector<T> &#40;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&#41;;
    &#125;
    
    
    
    template<class T>
    typename TemplateVector<T> TemplateVector<T>&#58;&#58;CompProduct &#40;const TemplateVector<T> &A&#41; const
    &#123;
    	return TemplateVector<T> &#40;m_x * A.m_x, m_y * A.m_y, m_z * A.m_z, A.m_w&#41;;
    &#125;
    
    
    
    inline dVector&#58;&#58;dVector&#40;&#41;
    	&#58;TemplateVector<dFloat32>&#40;&#41;
    &#123;
    &#125;
    
    inline dVector&#58;&#58;dVector &#40;const TemplateVector<dFloat32>& v&#41;
    	&#58;TemplateVector<dFloat32>&#40;v&#41;
    &#123;
    &#125;
    
    inline dVector&#58;&#58;dVector &#40;const dFloat32 *ptr&#41;
    	&#58;TemplateVector<dFloat32>&#40;ptr&#41;
    &#123;
    &#125;
    
    inline dVector&#58;&#58;dVector &#40;dFloat32 x, dFloat32 y, dFloat32 z, dFloat32 w&#41; 
    	&#58;TemplateVector<dFloat32>&#40;x, y, z, w&#41;
    &#123;
    &#125;
    
    #endif

  6. #6

    converting c code

    template<class T>
    typename T TemplateVector<T>:perator% (const TemplateVector<T> &A) const
    {
    return m_x * A.m_x + m_y * A.m_y + m_z * A.m_z;
    }

    dotproduct

  7. #7

    converting c code

    thanks. but its not giving the result i need

  8. #8

    converting c code

    It's not very clear what kind of result you need and what you get

  9. #9

    converting c code

    I think that "LNozzleVelocity % LNozzleDirection" would be equivalent to:

    [pascal]LNozzleVelocity[0] * LNozzleDirection[0] + LNozzleVelocity[1] * LNozzleDirection[1] + LNozzleVelocity[2] * LNozzleDirection[2][/pascal]
    [size=10px]&quot;In science one tries to tell people, in such a way as to be understood by everyone, something that no one ever knew before. But in poetry, it&#39;s the exact opposite.&quot; -- Paul Dirac[/size]

  10. #10

    converting c code

    Quote Originally Posted by Paulius
    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •