Jump to content
  • Advertisement

FrozenSnake

Member
  • Content Count

    34
  • Joined

  • Last visited

Everything posted by FrozenSnake

  1. I read on the MSDN that overloading += doesn't work so I should use + instead. But my problem is I already have it overloaded. I am trying to convert some of my c++ code to c# to make the same program in C#.   Here is my C++ code MyVector operator+(const MyVector& vec) { return MyVector(mX + vec.mX, mY + vec.mY, mZ + vec.mZ); }   void operator += (const MyVector& vec) { mX += vec.mX; mY += vec.mY; mZ += vec.mZ; }   MyVector operator-(const MyVector& vec) { return MyVector(mX - vec.mX, mY - vec.mY, mZ - vec.mZ); }   MyVector operator-() {   return MyVector(-mX, -mY, -mY); }   void operator -=(const MyVector& vec) { mX -= vec.mX; mY -= vec.mY; mZ -= vec.mZ; }   float operator*(const MyVector& vec) { return (mX * vec.mX + mY * vec.mY + mZ * vec.mZ); }   MyVector operator*(const float& f) { return MyVector(mX * f, mY * f, mZ * f); }   void operator*=(const float& f) { mX *= f; mY *= f; mZ *= f; } As you can see I do different stuff on the + and += for example. Is there any good way to get this to work in C#?  
  2. FrozenSnake

    Operator overloading +=, -=, *=

    I have made these two, guess I need a MyVector version of the second one public static MyVector operator*(MyVector a, MyVector b) { return (new MyVector(a.mX * b.mX, a.mY * b.mY, a.mZ * b.mZ)); } public static float operator*(MyVector a, float b) { return (a.mX * b + a.mY * b + a.mZ * b); } // Edit public static MyVector operator *(MyVector a, float b)        { return (new MyVector(a.mX * b, a.mY * b, a.mZ * b)); } // Edit     *Edit* now that Calc works too. Hopefully all the operators will work from now on If you see anything I do that should be done a different way feel free to point it out.
  3. FrozenSnake

    Operator overloading +=, -=, *=

    I do stuff like this in the C++ version: void Body::AddForce(const MyVector& x) { mForce += x; } void Body::SetVelocity(const sf::Vector2f& vec) { mPrevPos = mPos - vec * mFrames; } void Body::Update() { if (mID == 0) mForce.SetZ(0); if (mCanMove) { mForce.SetZ(0); mBodyShape.setPosition(mPos); MyVector tempPos1(mPos); MyVector tempPos2(mPrevPos); MyVector calc = (tempPos1 * 2.0f - tempPos2 + mForce * mInvertedMass * (mFrames * mFrames)); mPrevPos = mPos; mPos.x = calc.GetX(); mPos.y = calc.GetY(); } mWindow.draw(mBodyShape); DrawTrace(); ClearForce(); } At the moment I can't get this code MyVector calc = (tempPos1 * 2.0f - tempPos2 + mForce * mInvertedMass * (mFrames * mFrames)); To work in the C# version the "tempPos1 * 2.0f - tempPos2" part gives me This will probably complain about something else in this line if I fix the first problem. But this is quite confusing.   The operator overloading code looks like this: public static MyVector operator-(MyVector a, MyVector b) { a.mX -= b.mX; a.mY -= b.mY; a.mZ -= b.mZ; return a; } public static float operator -(MyVector a, float b) { return (a.mX - b + a.mY - b + a.mZ - b); } I am doing a solar system simulation and it works like a charm in C++ and I am trying to translate it to C# and mainly the operators are acting up :/   *EDIT* Currently rewriting the operators to this format: public static MyVector operator x(MyVector a, MyVector b) { return (new MyVector(a.mX x b.mX, a.mY x b.mY, a.mZ x b.mZ)); }
  4. FrozenSnake

    Operator overloading +=, -=, *=

    No, your example will: - Create a new vector (likely with mX=0,mY=0,mZ=0). - Add vec to the new vector. - Won't return a value, so all the work it's doing will be lost. In C#, all overloaded operators have to be static and have to return a value (they never modify a "this" object like you might do in C++).   I have done this now         public static MyVector operator+(MyVector a, MyVector b)         {             a.mX += b.mX;             a.mY += b.mY;             a.mZ += b.mZ;             return a;         } Hopefully that works better :)
  5. FrozenSnake

    Operator overloading +=, -=, *=

    This makes me a bit confused:  public static void operator+(MyVector vec)         {             MyVector mv = new MyVector();             mv.mX += vec.mX;             mv.mY += vec.mY;             mv.mZ += vec.mZ;         } Will it keep the value from mForce in this example. So I actually add 'x' to w/e value mForce already have or will the "new MyVector()" mess things up? mForce = mForce + x; *EDIT BELOW* Thanks for clarifying! Will my example above work as it should or should I alter that as well?
  6. FrozenSnake

    Operator overloading +=, -=, *=

    I'll take a look and see if I can figure it out.   That is because C# silently converts the code: x += y; into the code: x = x + y; Part of that is to help avoid the beginner's c++ bug of forgetting to implement all the corresponding operators, or the more nuanced bug of having slightly different behavior between the two operators. You just implement your addition operator, subtraction operator, and the rest. The +=, -=, *=, /=, %=, &=, |=, ^=, and other "op plus assign" operators will use your overloaded operation.   So I should do something like the code below to get the same behavior? I haven't been poking around in C# before so a lot of this is new to me. public static MyVector operator +(MyVector vec) { MyVector mv = new MyVector(); return (new MyVector(mv.mX + vec.mX, mv.mY + vec.mY, mv.mZ + vec.mZ)); } // This doesn't work, Type 'SFMLapp.MyVector' already defines a member called 'op_UnaryPlus' with the same parameter types public static void operator+(MyVector vec) // += in the c++ code { MyVector mv = new MyVector(); mv.mX += vec.mX; mv.mY += vec.mY; mv.mZ += vec.mZ; }
  7. FrozenSnake

    Hierarchical finite state machine

      You are doing this as an assignment, right? Your class has no text about it?   The text we have about the hierarchical is:   After this he talks about a global state, which according to him didn't meet the criteria because all states are substates to the global one. So I decided to place Two other states inside AgentIsTierd but I do not know is I did the thing he asks for or something else entirely.   So we have 4 lines of text, but it doesn't really show anything that is helpful for me to understand how to implement this. This is why I looked elsewhere to find some more information but I am still unsure about if it meet the criteria, and I would prefer to get some more information about HFSM and how it can be implemented.
  8. Hello! I am currently working on a FSM for a project at my university. But I have problem with figuring out if I meet the criteria for this program. I need to have a state that have sub-states (Hierarchical states). This code is about an AI I know, but the topic itself I feel is more related to general programming.   For example Combat leads to Shooting OR TakingCover. And no other state except for Combat should be able to reach these two states directly they need to go through Combat. This is how I have interpreted Hierarchical Finite State Machine anyway, so I would really like to have some feedback on this. It is not the most pretty piece of code out there so I apologize in advance. I also made a bitbucket repository if someone feel they need to dig deeper to help me, I do not wanna bloat this post with all the code. This is the code I think is the most important one and I only included the rest for people that feel they wanna study the code more.   TLDR; Is the code below hierarchical or have I misinterpreted something?   Here is my PonyStates.h file #include "State.h" class Pony; class AgentIsHungry : public State { public: static AgentIsHungry* Instance (); virtual void EnterState (Pony* p); virtual void ExitState (Pony* p); virtual void ExecuteState (Pony* p); private: // Copy construtor and assignment. AgentIsHungry() {} AgentIsHungry (const AgentIsHungry&); AgentIsHungry& operator= (const AgentIsHungry&); }; class AgentIsWorking : public State { public: static AgentIsWorking* Instance(); virtual void EnterState(Pony* p); virtual void ExitState(Pony* p); virtual void ExecuteState(Pony* p); private: AgentIsWorking() { } // Copy construtor and assignment. AgentIsWorking(const AgentIsWorking&); AgentIsWorking& operator= (const AgentIsWorking&); }; class AgentIsTierd : public State { public: static AgentIsTierd* Instance (); virtual void EnterState (Pony* p); virtual void ExitState (Pony* p); virtual void ExecuteState(Pony* p); AgentIsTierd() { } private: // Copy construtor and assignment. AgentIsTierd(const AgentIsTierd&); AgentIsTierd& operator= (const AgentIsTierd&); }; ////////////////////////////////////////////////////////////////////////////////////////////////////////// class AgentIsHavingANightmare : public AgentIsTierd { public: static AgentIsHavingANightmare* Instance(); virtual void EnterState(Pony* p); virtual void ExitState(Pony* p); virtual void ExecuteState(Pony* p); private: // Copy construtor and assignment. AgentIsHavingANightmare() {} AgentIsHavingANightmare(const AgentIsHavingANightmare&); AgentIsHavingANightmare& operator= (const AgentIsHavingANightmare&); }; class AgentIsHavingADream : public AgentIsTierd { public: static AgentIsHavingADream* Instance(); virtual void EnterState(Pony* p); virtual void ExitState(Pony* p); virtual void ExecuteState(Pony* p); private: // Copy construtor and assignment. AgentIsHavingADream() {} AgentIsHavingADream(const AgentIsHavingADream&); AgentIsHavingADream& operator= (const AgentIsHavingADream&); }; ////////////////////////////////////////////////////////////////////////////////////////////////////////// Here is my PonyStates.cpp file //////////////////////////////// ///////// AgentIsTierd ///////// //////////////////////////////// AgentIsTierd* AgentIsTierd::Instance() { static AgentIsTierd instance; return &instance; } void AgentIsTierd::EnterState(Pony* p) { if (p->WhereAmI() != Bedroom) { std::cout << GetName(p->GetID()) << " is walking to the bedroom; it is time to sleep.\n"; p->ChangeRoom(Bedroom); } } void AgentIsTierd::ExitState(Pony* p) { std::cout << GetName(p->GetID()) << " is now leaving the bedroom.\n"; } void AgentIsTierd::ExecuteState(Pony *p) { if (p->IsTierd()) { std::cout << GetName(p->GetID()) << " wishes to sleep. " << GetName(p->GetID()) << " lay down in bed to sleep! Zzz...\n"; if ((rand() % 100) % 2) p->ChangeState(AgentIsHavingADream::Instance()); else p->ChangeState(AgentIsHavingANightmare::Instance()); } else { std::cout << GetName(p->GetID()) << " wakes up refreshed! Time to go to work!\n"; p->ChangeState(AgentIsWorking::Instance()); } } ////////////////////////////////////////////////////////////////////////////////////////////////////////// // Good dream AgentIsHavingADream* AgentIsHavingADream::Instance() { static AgentIsHavingADream instance; return &instance; } void AgentIsHavingADream::EnterState(Pony* p) { // Already in bedrom. } void AgentIsHavingADream::ExitState(Pony* p) { std::cout << "\t" << GetName(p->GetID()) << " had a nice dream and is feeling refreshed.\n"; //p->ChangeState(AgentIsHungry::Instance()); } void AgentIsHavingADream::ExecuteState(Pony* p) { p->Sleep(); p->ChangeState(AgentIsHungry::Instance()); } // Nightmare AgentIsHavingANightmare* AgentIsHavingANightmare::Instance() { static AgentIsHavingANightmare instance; return &instance; } void AgentIsHavingANightmare::EnterState(Pony* p) { // Already in bedrom. } void AgentIsHavingANightmare::ExitState(Pony* p) { std::cout << "\t" << GetName(p->GetID()) << " had a nightmare and didn't sleep very well.\n"; } void AgentIsHavingANightmare::ExecuteState(Pony* p) { p->BadSleep(); p->ChangeState(AgentIsHungry::Instance()); }
  9. FrozenSnake

    Hierarchical finite state machine

    Thanks for the reply ApochPiQ, do you know any good articles I can read to some more understanding? The article I checked out was this. I had a hard time finding any text about this topic.
  10. First, I hope I post in the right forum for this question!   I am working on a shader in RenderMonkey and the shader is complete, so now I am writing a small report on the shader. My problem here is that I can't find any sources to read about pros and cons about "Specular light" and "Diffuse light". I have googled but I mainly find sources that is about what specular/diffuse light is, and these sources do not talk about the pros of each light model.   I have also checked in my course books to for some clues but I cannot find any. Do anyone here have any suggestion about where I can read about the pros and cons of these to light models?    Best regards!
  11. Thanks for the really nice reply!    The report is for a course called "Advanced Computer Graphics" at my university. The teacher is very "flummig" (it translate to dopey), he doesn't give a straight answer when someone asks a question about the report, but the text say: "Talk about the pros and cons with specular lighting Talk about the pros and cons with diffuse lighting".
  12. Thanks for the reply! One of the requirement on the report is to write pros/cons about specular and diffuse separate, I find it really hard :/ I'll try and write something and hope it works!
  13. I hope this is in the correct forum, since I am programming the shader I decided to put the topic in here.    I have been working on a shader in RenderMonkey on my desktop computer, and when I transferred the rfx-file to my laptop to continue the work in school I get two error messages that I do not get at home.     This is the Fragment program // Ljus 1 uniform vec3 uLight1Position; uniform float uLight1DiffIntent, Light1SpecIntent; float uLight1RimIntent; // Ljus 2 uniform vec3 uLight2Position; uniform float uLight2DiffIntent, uLight2SpecIntent, uLight2RimIntent; varying vec3 uLight1Color, uDiffuseColor, vColor, vNormal, vLightDir, vEyeVec; varying float uLight1Intent, luminosity1, luminosity2, uLight1RimLight, uOpacity; varying vec2 vTexCoord; uniform sampler2D baseMap; void main(void) { vec3 N = normalize(vNormal); vec3 L = normalize(vLightDir); vec3 E = normalize(vEyeVec); vec3 H = normalize(-L + E); // Lambert Diffuse Lighting. float diffuse = clamp(dot(N, -L), 0.0, 1.0); // Blinn Specular float specular = pow(max(dot(N, H), 0.0), 120.0); //float diffuse = dot(N, -L); // Rim Lighting. float rimLight = smoothstep(0.5, 0.05, dot(N,E));// * (uLight1RimIntent + uLight2RimIntent); specular += rimLight; // Diffuse Attenuation specular *= diffuse; vec3 base = texture2D( baseMap, vTexCoord ).xyz; // Lägg till kantljus till den diffusa komponenten. //vec4 finalColor = vec4(diffuse + rimLight, rimLight, rimLight, uLight1Intent) / (length(uLight1Position) * 0.02); vec3 vColor = mix(uDiffuseColor.xyz, base, uOpacity);// diffuse + finalColor; vec4 finalColor = vec4(base * diffuse, 2.0); gl_FragColor = vec4(vColor * finalColor + rimLight, 0.5); //gl_FragColor = finalColor; } The Vertex Program uniform vec3 uLight1Position; uniform vec3 uLight2Position; uniform vec3 uEyePosition; varying vec3 vColor; varying vec3 vLightDir; varying vec3 vNormal; varying vec3 vEyeVec, uOpacity, uDiffuseColor; varying float uLight1Intent, luminosity1, luminosity2; varying vec2 vTexCoord; void main( void ) { vec3 N = normalize(vNormal); vec3 L = normalize(vLightDir); vec4 vertex = gl_ModelViewProjectionMatrix * gl_Vertex; gl_Position = vertex; uLight1Intent = distance(gl_Position.xyz, uLight1Position.xyz); //uLight1RimIntent = distance(gl_Position.xyz, uLight1Position.xyz); luminosity1 = smoothstep(120, 0, uLight1Intent); vLightDir = -vec3(gl_ModelViewMatrix * vec4(uLight1Position, 0.0)); vNormal = gl_NormalMatrix * gl_Normal; vEyeVec = -vec3(gl_ModelViewMatrix * gl_Vertex); vTexCoord = vec2(gl_MultiTexCoord0); //float diffuse = dot(N, -L) * luminosity1; //vColor=vec3(diffuse,0.5,0.3); } I use the exact same rfx file (the exact same code) on the two different computers, I tried it in school as well and the same problem is there as well. We just started to work with hardware shaders so I dont know how rendermonkey work and why this is happening. It only work at home, all the files are the same on the different systems. Anyone that has any idea what I can try to get this to work?
  14. FrozenSnake

    Who to follow on Twitter?

    I do not know where this post should be posted to be under the correct category so I decided to place it here and hope for the best! I am a student at the university of Skövde in Sweden and I wish to follow some people on twitter that is relevant to my future line of work (game development). The type of people I want to follow are well known programmers, designers, artists, etc, so if anyone can help me find some of these people it would be great! I hope you guys understand what I am asking for, my English is not the best one out here! Best regards, Kim
  15. FrozenSnake

    Who to follow on Twitter?

    Thanks for all the suggestions!
  16. FrozenSnake

    Easy programming language

    People I spoken to say "Python" is a good language to learn first. If you ever played "EVE Online" it has been developed in "Stackless Python". So why not take a look on Python and Stackless Python? I can't say what platforms that uses Python. But if you are looking for PC. Python might work. But creating game is hard work in any language!
  17. FrozenSnake

    [Beginner] DX11 Book example problem

    Thanks! I will give it a try!
  18. Hi first of all, sorry for the "newb" thread! I have problem with one of the examples from the book "Introduction to 3D Game Programming With DirectX 11". I just received the book and decided to test one of the examples so I can get follow the book without to many problems! So I picked one of the examples the book have. After I compile it and tries to run it this comes up: "Direct3D Feature Level 11 unsupported." and I do not know why this is coming up. If anyone own the book it is the Chapter 19, Terrain demo I have tried. I checked in dxdiag and it say I have DirectX 11. So is there any way to find out why this error is coming up? Included the dxDiag.txt in case someone need the information to help me! Best regards, Kim
  19. A short thread, but I really wanna know, I am going to start (again) to learn game development and wonder if it's a good idea to make a class for handling the window I create. I am only going to use it to display and it will be in fullscreen mode, or should I stick with what the book I am reading at the moment is using (a non-class version of pretty much the same thing)?
  20. FrozenSnake

    Window question (C++ & Windows)

    Thanks for the replies
  21. FrozenSnake

    Ethics in game development

    I am working on a assignment in "Ethics and life issues" at my school and we got the assignment to do some research about ethics in a field of interest. My interest is game development so I decided to ask people that work with this for a living. So I have some questions and think that there are some people here that actually work in the industry, so I would appreciate if you could respond in the thread. I want you all to respect that I am only looking for answers from people who have worked more than 1-2 years in the industry. That is, it requires that you have been working on this for you to respond. If you meet this requirement but do not have a employment at the moment you can also reply. Here are the questions: Question 1 What do you think about games that depict violence? Question 2 In many (the majority) games woman are made beautiful or sexy. What is your perception of women? Question 3 What do you think about games where it's possible to rape woman/men in various ages unhindered? Ex. RapeLay. Question 4 In some games violence are over-exaggerated to a degree that they might get banned from some countries. What do you think about that type of games? Ex. Postal. Question 5This question I ask because my teacher will probably flunk me if I doesn't ask it Do you think violence in games make kids, teens or adults more violent? I would like to have detailed answers on each question, so put some thought behind each reply to each question. The work may quote portions or the whole response from a user, if you DO NOT want your username used to say to the first or else I will assume that it is OK to write "<name> wrote [---]"
  22. FrozenSnake

    Ethics in game development

    Quote:Original post by TyrianFin Yes, you can reference to my alter ego. You have smart teacher, questions target to latest issues in industry. /Tyrian Hehe, she just said I can ask I had to make the questions myself. I made them in Swedish first asking some developers in Sweden. And to get a related answer I had to translate them. Which was a bit hard, was pretty hard to find good words that made the sentence sound "OK" in English. Quote:Original post by Hodgman Re "What is your perception of women?", it's a pretty weird question. How do you think the average person on the street would respond to it? There's plenty of women in our office, and plenty of the men have wives and kids. We're normal people. What's the average perception of women in society as a whole? I'd like to think it's a meaningless question as we decided a long time ago that genders are equal... My teacher is a woman with a issue about how people (mostly men) look at womans. She would flunk me if I didn't ask it. But it can be a real discussion maker as well (I have noticed) Oh well time for school! Have a nice morning/day/evening/night!
  23. FrozenSnake

    Ethics in game development

    Quote:Original post by LockePick Did your teacher ask you to ask random questions to random people on the internet or was that your idea of "research"? Hint: Research Feel free to tell me a title of a book in the subject (Ethics in game-development). You should learn the meaning of the word research. Research can be defined as the search for knowledge or any systematic investigation to establish facts., Reading a factual book of any sort is a kind of research. Surfing the internet or watching the news is also a type of research. and asking questions is what researchers do, please don't waste my time by posting here again. Oh I forgot... Yes, my teacher said I should ask people about this as there is probably no book available on the subject. Quote:Original post by Hodgman 1) What about them? They should be classified appropriately. 2) What about them? They're people? That's a really badly worded question... "What is your perception of trees?" Uhh... 3) I wouldn't play them or sell them. 4) Postal is comedic so I can stomach it. My country did ban it, and I think it's a stupid, immature decision. There are other games with realistic brutal violence, and I can choose not to play them. 5) Kids shouldn't be playing those kinds of games in the first place, just like they shouldn't be watching "adults only" films. Unfortunately I cannot use your answers to get a picture of how the people in the industry thinks, like I said in the topic "I would like to have detailed answers on each question, so put some thought behind each reply to each question." Thanks to the two (Nypyren, TyrianFin) that took the time to give me good replies. Is it OK if I mention your nicks in the text?
  24. Anyone know if the site is abandoned by Frank? I can browser it and it's forum, but when I try to join the forum I get a error "CGI Error The specified CGI application misbehaved by not returning a complete set of HTTP headers." This isn't anything I can fix myself, and I tried to e-mail Frank but didn't get any reply (maybe 1 month ago). So anyone know if Frank has dropped it to live on it's own until it's total decay or is he still active in the site? PS. Didn't find a fitting category to post this so I posted it here.
  25. FrozenSnake

    Problem with some DirectX things

    Quote:Original post by Erik Rufelt Quote:Original post by FrozenSnake First error say cannot convert from 'IDirect3DSurface9 *' to 'LPDIRECT3DTEXTURE9' but all the variables on that line are either LPDIRECT3DTEXTURE9 or int. LPDIRECT3DTEXTURE9 pSurface; std::vector<LPDIRECT3DSURFACE9> textures; int index = groundMap[y][x]; pSurface = textures[index]; You use LPDIRECT3DTEXTURE9 for pSurface, but the vector contains LPDIRECT3DSURFACE9. Textures and surfaces are not the same thing. A texture consists of surface(s). Use GetSurfaceLevel to get a surface from a texture. Thanks for the fast reply! If I switch to what it asks for, it asks for IDirect3DSurface9 *, and when I try that it asks for LPDIRECT3DTEXTURE9 this is very confusing. I will take a look on that function and see if I can figure this out.
  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!