Jump to content
  • Advertisement

jake_Ghost

Member
  • Content Count

    442
  • Joined

  • Last visited

Community Reputation

103 Neutral

About jake_Ghost

  • Rank
    Member
  1. Hi, I am having trouble with my pixel shader and at this point I am totally lost on what to do next. Basically all I am doing is using a pixel shader to show the spots on a shield that have been hit. I have all the coords of the shield hit locations in the shader but what I don't know how to do is get the distance from a pixel to the hit location. Basically I'm looking at something like this, // ps_3_0 float4 ps_normal(in PS_INPUT In) : COLOR { float Distance; float2 Pos; float4 color= tex2D( Tex0, In.Texture ); for (int i = 0; i < CurHitSize; ++i) { Pos = PixelCoord - HitCoord; // I dont know how to get the pixel coord Distance = sqrt(Pos.x * Pos.x + Pos.y * Pos.y); if (Distance < 10) // I'm just using 10 as an example as it will obviously change depending on how large you want the impact to be { // Here I don't know how to return color of the pixel // I want all the pixels to be at 0 alpha except for the ones that are in the impact range } } } Any help would be great! Thanks, Jake
  2. jake_Ghost

    Dynamic array of std::string

    I am, maybe that is the cause of the problems.
  3. jake_Ghost

    Dynamic array of std::string

    I use optimizations for the release version. Using iterators with vectors is as fast as a normal array it just requires more code to use it. Would it be a good idea to write a wrapper class that handles all the iterators to vectors to increase performance? I did a lot of testing with vectors when I was writing my particle system and I found that they were just too slow, even when using iterators and pointers to each memory block. What would you suggest I do?
  4. jake_Ghost

    Dynamic array of std::string

    I found that vectors are not so fast when not using iterators. Using the [] operator is very slow. But maybe I am doing something wrong? I also wrote this class as a learning experience. I find that writing my own class helps me understand things better.
  5. jake_Ghost

    Dynamic array of std::string

    Thank you so much!! Why didn't I think of that... :D
  6. I have written a small array class to handle dynamic arrays of objects. I did it mostly for speed. But I am running into problems with memcpy and std::string. I use a function called adjust pointer which just allocates a new array, copies the old one into it and deletes the old one. template <class T> void cGhost :: AdjustPointer(T *&Var, int &Size, int Increment) { if (Increment < 0) { if (Size + Increment < 1) { if (Var == NULL) return; else { SAFE_DELETE_ARRAY(Var); Size = 0; return; } } } T *New = new T[Size + Increment]; memcpy(&New[0], &Var[0], sizeof(T) * Size); SAFE_DELETE_ARRAY(Var); Var = New; Size += Increment; } But I am running into problems with strings. It doesn't seem to copy properly and I ended up having to use a for loop and set each iteration directly. I'm guessing it has something to do with the how the string stores it array of chars. Maybe a copy constructor is needed with strings? I'm not sure. I've spent a long time looking up this problem and I can't seem to find any solution. Here's the array class for reference. #pragma once #include "GhostVars.h" template<class T> class cArray { public: cArray(void) { Array = NULL; Size = 0; Increment = 1; Last = 0; CurIndex = 0; AutoDelete = true; } cArray(int size, int inc = 1, bool autodelete = true) { Array = NULL; Size = 0; Increment = inc; Last = 0; CurIndex = 0; AutoDelete = autodelete; Increase(size); } cArray(const cArray &cA) { Array = cA.Array; Size = cA.Size; Increment = cA.Increment; Last = cA.Last; CurIndex = cA.CurIndex; AutoDelete = cA.AutoDelete; } ~cArray(void) { if (AutoDelete) SAFE_DELETE_ARRAY(Array); } void Insert(const T &In, const int &Index); void Delete(const int &Index); void InsertSafe(const T &In, const int &Index); void DeleteSafe(const int &Index); __inline void Clear() { if (Size > 0) { SAFE_DELETE_ARRAY(Array); Size = 0; } } __inline T& operator[](const int &Index) { return Array[Index]; } __inline T *Get(const int &Index) { return &Array[Index]; } __inline T *GetFirst() { return &Array[0]; } __inline T *GetLast() { return &Array[Last]; } __inline bool GetSafe(T &Out, const int &Index) { if (Index >= 0 && Index < Size) { Out = Array[Index]; return true; } else return false; } __inline bool GetSafeFirst(T &Out) { if (Size > 0) { Out = Array[0]; return true; } else return false; } __inline bool GetSafeLast(T &Out) { if (Size > 0) { Out = Array[Last]; return true; } else return false; } __inline const int &GetSize() { return Size; } __inline const int &GetIncrement() { return Increment; } __inline const int &GetFilledSize() { return CurIndex; } __inline void operator++() { Ghost->AdjustPointer(Array, Size, 1); Last = Size - 1; } __inline void operator--() { Ghost->AdjustPointer(Array, Size, -1); Last = Size - 1; } __inline void Increase(int inc = 0) { if (inc == 0) inc = Increment; Ghost->AdjustPointer(Array, Size, inc); Last = Size - 1;} __inline void Decrease(int inc = 0) { if (inc == 0) inc = -Increment; Ghost->AdjustPointer(Array, Size, inc); Last = Size - 1;} __inline void Push(const T &In) { Ghost->AdjustPointer(Array, Size, 1); Last = Size - 1; Array[Last] = In; } __inline void Fill(const T &In) { Array[CurIndex] = In; ++CurIndex; if (CurIndex >= Size) Increase(); } __inline bool IsValidIndex(const int &Index) { return (Index >= 0 && Index < Size); } __inline void SetAutoDelete(const bool &In) { AutoDelete = In; } __inline void SetIncrement(const int &i) { if (i != 0) Increment = i; } __inline void SetCurIndex(const int &i = 0) { if (IsValidIndex(i)) CurIndex = i; } private: T *Array; int Size; int Increment; int Last; int CurIndex; bool AutoDelete; }; template<class T> void cArray<T> :: Insert(const T &In, const int &Index) { T *NewArray = new T[Size + 1]; memcpy(&NewArray[0], &Array[0], sizeof(T) * Index); NewArray[Index] = In; memcpy(&NewArray[Index + 1], &Array[Index], sizeof(T) * Size - Index); SAFE_DELETE_ARRAY(Array); Array = NewArray; ++Size; } template<class T> void cArray<T> :: Delete(const int &Index) { if (Size == 1) { SAFE_DELETE_ARRAY(Array); Size = 0; return; } --Size; T *NewArray = new T[Size]; if (Index != 0 && Index < Size) { memcpy(&NewArray[0], &Array[0], sizeof(T) * Index); memcpy(&NewArray[Index], &Array[Index + 1], sizeof(T) * (Size - Index)); } else if (Index == 0) memcpy(&NewArray[0], &Array[1], sizeof(T) * (Size)); else if (Index == Size) memcpy(&NewArray[0], &Array[0], sizeof(T) * (Size)); SAFE_DELETE_ARRAY(Array); Array = NewArray; } template<class T> void cArray<T> :: InsertSafe(const T &In, const int &Index) { if (Index >= 0 && Index < Size) { T *NewArray = new T[Size + 1]; memcpy(&NewArray[0], &Array[0], sizeof(T) * Index); NewArray[Index] = In; memcpy(&NewArray[Index + 1], &Array[Index], sizeof(T) * Size - Index); SAFE_DELETE_ARRAY(Array); Array = NewArray; ++Size; } } template<class T> void cArray<T> :: DeleteSafe(const int &Index) { if (Index >= 0 && Index < Size) { if (Size == 1) { SAFE_DELETE_ARRAY(Array); Size = 0; return; } --Size; T *NewArray = new T[Size]; if (Index != 0 && Index < Size) { memcpy(&NewArray[0], &Array[0], sizeof(T) * Index); memcpy(&NewArray[Index], &Array[Index + 1], sizeof(T) * (Size - Index)); } else if (Index == 0) memcpy(&NewArray[0], &Array[1], sizeof(T) * (Size)); else if (Index == Size) memcpy(&NewArray[0], &Array[0], sizeof(T) * (Size)); SAFE_DELETE_ARRAY(Array); Array = NewArray; } } Any help would be great! Thanks, Jake
  7. jake_Ghost

    need help on first big project...

    I have written a simple way to read a file with c++. If you'd like I could send you the code so you can see how to use it or you can just use it yourself. It's simple to use, here's an example. cSerializer *S = new cSerializer(); std::string Input = ""; if (S->ReadFile(Filename)) { Pulse = new cParticle(); PulseE = new cParticle(); PulseInfo = new tPulse(); P = new Particle_SSE(1); S->Begin(); { if (S->GetBlockByName("Weapon")) { S->Begin(BlockVariable); S->GetVariableByName("Size", PulseInfo->pSize); S->GetVariableByName("Particle", PulseInfo->P); S->GetVariableByName("ParticleExplode", PulseInfo->pE); S->GetVariableByName("ParticlePolarity", PulseInfo->Polarity); S->End(); } else return false; if (S->GetBlockByName("Weapon_Stats")) { S->Begin(BlockVariable); S->GetVariableByName("Type", PulseInfo->Type); S->GetVariableByName("Damage", PulseInfo->Damage); S->GetVariableByName("EnergyCost", PulseInfo->EnergyCost); S->End(); } else return false; if (S->GetBlockByName("Weapon_Particle_Settings")) { S->Begin(BlockVariable); S->GetVariableByName("Circle", PulseInfo->Circle); S->GetVariableByName("InvCircle", PulseInfo->invCircle); S->GetVariableByName("Life", PulseInfo->Life); S->End(); } else return false; if (S->GetBlockByName("Weapon_Emitter")) { S->Begin(BlockVariable); S->GetVariableByName("Size", PulseInfo->pDim); S->GetVariableByName("Velocity", PulseInfo->Velocity); S->GetVariableByName("AngleRandLow", PulseInfo->angleRLow); S->GetVariableByName("AngleRandHigh", PulseInfo->angleRHigh); S->GetVariableByName("Direction", PulseInfo->Direction); S->GetVariableByName("PRandLow", PulseInfo->pRandLow); S->GetVariableByName("PRandHigh", PulseInfo->pRandHigh); S->GetVariableByName("PLife", PulseInfo->pLife); S->GetVariableByName("CRadius", PulseInfo->cRadius); S->GetVariableByName("RateOfFire", PulseInfo->rateOfFire); S->GetVariableByName("Distance", PulseInfo->Distance); S->GetVariableByName("NumFire", PulseInfo->NumFire); S->GetVariableByName("POnDeath", PulseInfo->pOnDeath); S->End(); } else return false; if (S->GetBlockByName("Weapon_Sound")) { std::string s[4]; S->Begin(BlockVariable); S->GetVariableByName("SoundFire", s[0]); S->GetVariableByName("VolumeFire", s[1]); S->GetVariableByName("SoundHit", s[2]); S->GetVariableByName("VolumeHit", s[3]); S->GetVariableByName("SoundType", PulseInfo->SoundType); S->End(); #pragma omp critical Ghost->Sound->LoadSound(s[0], atof(s[1].c_str()), PulseInfo->SoundType, FMOD_DEFAULT | FMOD_3D, PulseInfo->SoundFire); #pragma omp critical Ghost->Sound->LoadSound(s[2], atof(s[3].c_str()), PulseInfo->SoundType, FMOD_DEFAULT | FMOD_3D, PulseInfo->SoundHit); } else return false; }S->End(); } If you're interested send me a PM. jake
  8. jake_Ghost

    recommend some books

    Quote:Original post by rushikesh3030 Isnt it that site rapidshare also offers the free download for that book? Yes but that's illegal.
  9. jake_Ghost

    IDirect3DDevice9::Clear() failed

    Do you call BeginScene() and EndScene() at any point?
  10. jake_Ghost

    recommend some books

    http://www.jbpub.com/Catalog/9781556220784/student/ I found the book very helpful and you can download source code right from that site for free. But the book itself is 50 dollars. Jake
  11. It depends on how big your program is. If you're making something simple then I don't think there's anything wrong with the way you're doing it. But if you're going to be making something more complex there are different methods. Personally, I do something like this. UpdateMovements(); UpdateCollisions(); CheckCollisions(); // this method calls each objects check collision function which determines what each object will do There are a few reasons doing it like this is beneficial, of course this might not be the *most* efficient way to do it but it is good enough. I divide the area into grids and sort the objects amoungst them. This way each object isn't testing collisions with every other object. Also when doing it like this, I can take advantage of some multithreading without making it too difficult to manage. Hope this helps, Jake
  12. jake_Ghost

    Help with script

    No problem. Good programming. Jake
  13. jake_Ghost

    Help with script

    The problem is with int intlinearsearch (int*,int,int); // it should be int intLinearSearch(int p_stuNum[], int p_max, int p_searchArg); i = intlinearsearch(stuNum,max,searchArg); // this should then be i = intLinearSearch(stuNum,max,searchArg); #include <iostream> #include <string> #include <cstdlib> #include <iomanip> #include <cstdio> using namespace std; int intLinearSearch(int p_stuNum[], int p_max, int p_searchArg); int intLinearSearch(int p_stuNum[], int p_max, int p_searchArg) { int i; int hitLoc; bool found; found = false; hitLoc = -1; i = 0; while (i < p_max && !found) { if (p_stuNum == p_searchArg) { found = true; hitLoc = i; } i = i + 1; } return(hitLoc); } int stuNum[] = {201,202,203,204}; struct testData { int t1; int t2; int t3; }; int main (void) { testData testRcd[4]; int stuID; int sumscores; double meanAvg; int i = 0; int max = 4; int searchArg; testRcd[0].t1 = 16; testRcd[0].t2 = 20; testRcd[0].t3 = 18; testRcd[1].t1 = 17; testRcd[1].t2 = 19; testRcd[1].t3 = 17; testRcd[2].t1 = 18; testRcd[2].t2 = 18; testRcd[2].t3 = 19; testRcd[3].t1 = 17; testRcd[3].t2 = 18; testRcd[3].t3 = 19; cout << "Enter number range (201-204): "; cin >> stuID; while(stuID < 201 || stuID > 204) { cout << "A Valid entry between (201-204): "; cin >> stuID; } searchArg = stuID; i = intLinearSearch(stuNum,max,searchArg); sumscores = testRcd.t1 + testRcd.t2 + testRcd.t3; meanAvg = (double)sumscores/3; cout << "Score of Student Number " << stuID << "is: " << meanAvg << endl; } C++ is case sensitive. Also, you can put your code in source blocks by using ["source"] ... code ... ["/source"] Just take out the "" Jake
  14. jake_Ghost

    Help With Code::Blocks Compiler!

    You're talking about the console screen? I don't think you can make those go full screen. Just create a win32 window.
  15. jake_Ghost

    Strange persistent prompt in VS2008

    Backup the file in question. Go to your project and press delete on it and delete the file, don't just remove it. Then add it again and see if that helps. Jake
  • 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!