Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

354 Neutral

About Misery

  • Rank

Personal Information

  • Interests
  1. I am programming boolean operations on 3D meshes which are described by sphere trees. They do not deform, nor change in time anyhow. However to generate the environments I need to perform boolean operations on them as fast as possible. I need to find all the collisions between polygons (triangles). What is the best approach / algorithm for that purpose? I haven't found anything particularly useful via Google. In detail: I am in need for an algorithm that will take two sphere trees and return the buffer of all collisions. I do not have much experience in using sphere trees so my idea is to check every polygon from the first mesh with the second mesh sphere tree and vice versa. Somehow I feel that is a waste of CPU power. Could anyone give me a description of better approach or some useful links?
  2. Misery

    Vulkan 101 Tutorial

    It does the same in my case. Win 10 VS2015 using TDM-GCC causes crash as well.
  3. It is supposed to be an image filter for smartphone. I am not worry about overflow or underflow as I am able to control it.
  4. Hello,   I would like to store four c++ chars in one int (or other int data types compatibile with each other in such way) and perform basic operations on them in such way that the operation would be done for all of the elements at once (to speed up computations). Like in the example below: union{  uint8_t i8[4];  uint32_t i64; } A,B,C;     A.i8[0]=10;     A.i8[1]=14;     A.i8[2]=2;     A.i8[3]=5;     B.i8[0]=8;     B.i8[1]=4;     B.i8[2]=2;     B.i8[3]=2;     cout<<"A = "<<short(A.i8[0])<<" "<<short(A.i8[1])<<" "<<short(A.i8[2])<<" "<<short(A.i8[3])<<endl;     cout<<"B = "<<short(B.i8[0])<<" "<<short(B.i8[1])<<" "<<short(B.i8[2])<<" "<<short(B.i8[3])<<endl;     C.i64=A.i64+B.i64;     cout<<"A+B="<<short(C.i8[0])<<" "<<short(C.i8[1])<<" "<<short(C.i8[2])<<" "<<short(C.i8[3])<<endl;     C.i64=A.i64-B.i64;     cout<<"A-B="<<short(C.i8[0])<<" "<<short(C.i8[1])<<" "<<short(C.i8[2])<<" "<<short(C.i8[3])<<endl;     C.i64=A.i64*B.i64;     cout<<"A*B="<<short(C.i8[0])<<" "<<short(C.i8[1])<<" "<<short(C.i8[2])<<" "<<short(C.i8[3])<<endl;     C.i64=A.i64/B.i64;     cout<<"A/B="<<short(C.i8[0])<<" "<<short(C.i8[1])<<" "<<short(C.i8[2])<<" "<<short(C.i8[3])<<endl; The addition and subtraction works just fine, however I don't really have any idea to how to perform multiplication and division in such way. I was planning to use SSE, however it turned out that the target platform might not have ability to use SSE functionality. How to force C++ to multiply and divide properly four chars one by one like it happens in SSE?
  5. Hi there,   I am working on an adventure TPP game in which the game character is a hacker. It is the minor feature of the game, however the player from time to time will have to break some codes, hacks some computers etc. I would very much like to deliver a bit of reality in that aspect like using command line, searching patterns in memory dumps, installing keyloggers and so on (Just to make player feel like me when I was a kid at school shutting down all PCs via net to my class-mates during IT classes). However I cannot assume that person playing this game will have any experience in hacking, bash, programming, scripting or any OS administration. So I would like to ask for any tips that would help me to make this enough easy for player but still interesting and giving the sense of really hacking into a computer.   For now I have designed it in such way that the game character is a hacker and he has the knowledge on how to do hacking stuff. So the player only does quite simple tasks like installing keylogger and watches the rest being done by the character. For example: you are supposed to break into some wi-fi spot. You get the menu with options which are explained by the game character. When choosing one, then you have update in your notepad what you need to do to achieve the goal. Any suggestions on how to improve that part?    
  6.   Thanks for your advise. I agree with you absolutely. However my approach allows to conversions only if such converions are explicitly defined by user or by the language standard. Therefore I find it nice approach. And in the case of lack of conversion function it prompts pretty error message instead of huge message. Therefore I care much about implementing it that way.
  7. I am implementing expression templates for Vector3<> template class in C++. Actually I have it working very well, but only when arguments of the same type are involved. Lets say Vector3<double> and Vector3<double> or double scalar and Vector3<double>, etc. In the case of for example multiplying Vector3<double> and Vector3<float> compiler prompts error, as it these are two different objects and it is unable to perform float to double conversion by itself.  To solve this issue I had two ideas: 1. Define all necessary classes and operators in terms of possible interactions float and double, float and int etc. Which is very very wrong approach 2. Create templates using auto and decltype   I managed to achieve somewhat a success. I can create a Vector3<anything1> and perform operations on it with other Vector3<anything2>. So it is a clean and nice solution, as it does not require to define all possible conversions. However when I try to perform an operation between any scalar and Vector3<anything> I get errors.   Different operators (in the code below it would be Vector3<DATA_TYPE_L>*Vector3<DATA_TYPE_R> and scalar DATA_TYPE_L*Vector3<DATA_TYPE_R>) interfere. Separately both operators work fine. However when both are present compiler always chooses scalar*Vector3<> operator, and of course fails to deduce arguments when Vector3<>*Vector3 operator should be used. I managed to solve this situation only by providing additional class Scalar<DATA_TYPE> which embraces the scalar value. However then I have to call some function creating Scalar class explicitly out of let's say double. This is something I would like to avoid.   So I thought of two solutions: 1. Make the operator create Scalar class transparently out of float or double etc. so no explicit usage of function creating Scalar would be needed 2. Redesign the code so operators wouldn't interfere However I did not manage to achieve any of those. Any help would be very appreciated. The Code below works fine in VS2015. Remove comments to get mentioned error. typedef  int SIZE_INT; template <class DATA_TYPE, class Expression> class Vector3Expression { public:     auto operator[](SIZE_INT i) const { return static_cast<Expression const &>(*this)[i]; }     operator Expression&() { return static_cast<      Expression&>(*this); }     operator Expression const&() const { return static_cast<const Expression&>(*this); } }; template <class DATA_TYPE> class Vector3 :public Vector3Expression<DATA_TYPE, Vector3<DATA_TYPE> > { public:     DATA_TYPE Data[3];     Vector3() {}     Vector3(const Vector3& that)     {         Data[0] = that.Data[0];         Data[1] = that.Data[1];         Data[2] = that.Data[2];     }     Vector3(Vector3&& that)     {         std::move(that.Data, 3, Data);     }     template <class OTHER_DATA_TYPE, class Expression>     Vector3(Vector3Expression<OTHER_DATA_TYPE, Expression> const& VE)     {         Expression const& ve = VE;         Data[0] = ve[0];         Data[1] = ve[1];         Data[2] = ve[2];     }     //access operators     DATA_TYPE&  operator[](SIZE_INT i) { return Data[i]; }     DATA_TYPE  operator[](SIZE_INT i) const { return Data[i]; }     DATA_TYPE&  operator()(SIZE_INT i) { return Data[i]; }     DATA_TYPE  operator()(SIZE_INT i) const { return Data[i]; }     //operators     Vector3<DATA_TYPE>& operator=(Vector3<DATA_TYPE> &&that)     {         if (&that != this)         {             std::swap(Data[0], that.Data[0]);             std::swap(Data[1], that.Data[1]);             std::swap(Data[2], that.Data[2]);         }         return *this;     }     Vector3<DATA_TYPE>& operator=(const Vector3<DATA_TYPE> &that)     {         if (&that != this)         {             Data[0] = that.Data[0];             Data[1] = that.Data[1];             Data[2] = that.Data[2];         }         return *this;     }     SIZE_INT  Length() const {         return SIZE_INT(3);     }     };     template <class DATA_TYPE_LHS, class DATA_TYPE_RHS, class Lhs, class Operator, class Rhs>     class Vector3Vector3Operation : public Vector3Expression<decltype(Operator::Apply(DATA_TYPE_LHS(), DATA_TYPE_RHS())), Vector3Vector3Operation<DATA_TYPE_LHS, DATA_TYPE_RHS, Lhs, Operator, Rhs> >     {     private:         Lhs const& vL;         Rhs const& vR;     public:         Vector3Vector3Operation(Vector3Expression<DATA_TYPE_LHS, Lhs> const & lhs, Vector3Expression<DATA_TYPE_RHS, Rhs> const & rhs) : vL(lhs), vR(rhs) {}         auto operator[](SIZE_INT i) const { return Operator::Apply(vL[i], vR[i]); }     };     template <class DATA_TYPE_LHS, class DATA_TYPE_RHS, class Operator, class Vec>     class ScalarVector3Operation : public Vector3Expression<decltype(Operator::Apply(DATA_TYPE_LHS(), DATA_TYPE_RHS())), ScalarVector3Operation<DATA_TYPE_LHS, DATA_TYPE_RHS, Operator, Vec> >     {     private:         const DATA_TYPE_LHS S;         Vec const& V;     public:         ScalarVector3Operation(const DATA_TYPE_LHS s, Vector3Expression<DATA_TYPE_RHS, Vec> const& v) : V(v), S(s) {}         auto operator[](SIZE_INT i) const { return Operator::Apply(S, V[i]); }     };     namespace meta {         template<class DATA_TYPEL, class DATA_TYPER = DATA_TYPEL>         struct Multiply         {             inline static auto Apply(DATA_TYPEL a, DATA_TYPER b)->decltype(a*b) { return a*b; }         };     }     template <class DATA_TYPEL, class DATA_TYPER, class LExpression, class RExpression>     Vector3Vector3Operation<DATA_TYPEL, DATA_TYPER, LExpression, meta::Multiply<DATA_TYPEL, DATA_TYPER>, RExpression> const         operator*(Vector3Expression<DATA_TYPEL, LExpression> const& u, Vector3Expression<DATA_TYPER, RExpression> const& v)     {         return Vector3Vector3Operation<DATA_TYPEL, DATA_TYPER, LExpression, meta::Multiply<DATA_TYPEL, DATA_TYPER>, RExpression>(u, v);     }     /* //operator causing trouble     template <class DATA_TYPE_LHS, class DATA_TYPE_RHS, class RExpression>     ScalarVector3Operation<DATA_TYPE_LHS, DATA_TYPE_RHS, meta::Multiply<DATA_TYPE_LHS, DATA_TYPE_RHS>, RExpression> const     operator*(const DATA_TYPE_LHS s, Vector3Expression<DATA_TYPE_RHS, RExpression> const& v)     {     return ScalarVector3Operation<DATA_TYPE_LHS, DATA_TYPE_RHS, meta::Multiply<DATA_TYPE_LHS, DATA_TYPE_RHS>, RExpression>(s.value, v);     }     */     int main()     {         Vector3<double> d, x, u;         Vector3<float> f;         double s = 0.25;         d[0] = 1; d[1] = 2; d[2] = 3;         x = d;         f[0] = 3; f[1] = 2; f[2] = 1;         u = d*f;         std::cout << u[0] << " " << u[1] << " " << u[2] << std::endl;         u = d*x;         std::cout << u[0] << " " << u[1] << " " << u[2] << std::endl;         //u = s*d*x; //does not work         std::cout << u[0] << " " << u[1] << " " << u[2] << std::endl;         getchar();         return 0;     }
  8. Is it worth to implement expression templates for classes representing two or three dimensional vector? Expression templates improve performance, however I'm not sure if it is reasonable to implement such functionality when dealing with such simple class.
  9. @Aardvajk you are using a method instead of the class field. My question is just a spin-off of this question.
  10. @Madhed I forgot to add that it shouldn't add any memory overhead like it is with using references. I am just curious - no special need for it. I am still learning C++.
  11. Let's say there is a class foo that has a variable of another class, call it C. Is is possible to access C members by a field of foo? EDIT: I forgot to mention that it should be without any additional memory or significant performance loss (like with using references - mem loss). class C {   public:   float t; }; class foo {   public:    C c;    float x; //this should access c.t } f; float T=f.x; //returns foo.c.t  f.x=5f; The similar example was given by Alvaro, however it regards an access between two fields of one class: struct vector3 {     float x, y, z;     float& operator[](int index) {         assert(index >= 0 && index < 3);         return this->*members[index];     }     float operator[](int index) const {         assert(index >= 0 && index < 3);         return this->*members[index];     }     static float vector3::* const members[3]; }; float vector3::* const vector3::members[3] = { &vector3::x, &vector3::y, &vector3::z};
  12. Recently I started to use unity3d for my hobby game project and I really liked a Vector3 (and similar) classes (in C#). At the moment at work I am implementing a simple (but for large simulations) SPH solver. What I would like to achieve is a similar Vector3 class in C++ in the means of access to elements both by v.x, v.y, v.z and v[0], v[1], v[2]. In general to obtain this is very simple, but none of the solutions that came to my mind is free of flaws.   Solution 1: using references &x, &y, &z, problem: such class has three additional variables which occupy the memory. In the case of large simulation it is problematic: template <class T>   class Vector3   {     public:         T &x,&y,&z;         T v[3];         Vector3(): x(v[0]), y(v[1]), z(v[2])         {           v[0]=0; v[1]=1;  v[2]=2;         }         T& operator[](int i)         {             return v[i];         }   }; The access is very elegant: v[i] as well as v.x, v.y and v.z And this is what I woluld like to obtain - this elegant access. However the additional memory overhead is unacceptable.   Solution 2: using class fileds x,y,z and access operator with if statement: problem performance of [] operator template <class T>   class Vector3   {     public:         T x,y,z;         Vector3(): x(0), y(1), z(2)         { }         T& operator[](int i)         {             if (i==0) return x; else if (i==1) return y; else if (i==2) reurn z; else { //throw access error }         }   }; This solution is elegant as well, but the operator [] will be very slow.   Solution 3: Using the class functions x(), y(), z() template <class T>   class Vector3   {     public:         T v[3];         Vector3()         {           v[0]=0; v[1]=1; v[2]=2;         }         T& operator[](int i)         {             return v[i];         } T& x() { return v[0]; } T& y() { return v[1]; } T& z() { return v[2]; }   }; This solution is ideal in means of efficiency and memory overhead, but, does not allow elegant access to members, requires for example v.x() instead of v.x.   The question is: is there a way to obtain this elegant access with no efficiency and memory loss?    
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!