Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 12 Oct 2004
Offline Last Active Oct 19 2016 11:19 AM

#5250085 Find tile coordinates within a given radius

Posted by on 01 September 2015 - 06:07 AM

Instead of doing a distance check that requires a square root, you can check against the squared distance:

if((j - x)*(j - x) + (k - y)*(k - y) <= r * r)

Should be faster.

#5249776 Translate Planet around a circle path on X, Z axes?

Posted by on 30 August 2015 - 03:19 PM

If you just want a circular motion you can set your X and Z to:

X = sunPosition.X + orbitDistance * cos(t)
Z = sunPosition.Z + orbitDistance * sin(t)

where t should increase with time, the faster t increases, the faster your planet will move about. An increase of 2*Pi in t represents one full orbit.

#5249531 How would I be able to do this in C++?

Posted by on 29 August 2015 - 04:20 AM

If you need a fixed size array you can do:

int array[] = {1, 2, 3};

If you need a dynamic array, one that can change in size, use std::vector:

std::vector<int> vector = {1, 2, 3};

#5247843 Pointer Clarification

Posted by on 20 August 2015 - 05:57 AM

Hmm, well while I attempt what you asked, I am realizing that building an Array to represent items like HP values and Names isn't working very well... So, is it safe to say that the following is possible:

Goblin 1's Address (which is Pointed to...): 123

I could pull specific information from that address such as HP values and names? I ask because I was under the impression only a specific type of integer could be stored at the address, i.e. and INT or STRING value, for example.

I realize that I might only confuse you more at this point. I'll continue on KnonalCross's analogy as that seems to have resonated well with you.




This is an amazing analogy! Thank you! Similar to a question I asked above. Would the 'coat' hold multiple variables? (i.e. Name of the coat, color, size, etc.?)

The coat could hold all kinds of stuff in it's pockets, it could even hold another paper with 'Wardrobe 17' on it. That would mean that for the person who has their belongings(could be a coat, scarf etc.) in wardrobe 17, would first have to get the coat from 16, in order to pull out the paper and get their belongings from 17.

#5247722 Matching Parameter Names to Class Fields

Posted by on 19 August 2015 - 12:59 PM

If your declaration and definition are separated, i.e. you have a .h and .cpp file, you can use a different name in your definition like gasIn or gasArg while still having declared it as gas.

#5247363 Code Review

Posted by on 18 August 2015 - 05:23 AM

'rotated' is supposed to be treated as a bool value. I use uint8_t because I wanted it strictly typed for POD purposes so it's more portable when exporting to a file. I try to stay away from bool when working with POD due varying to compiler implementation. bool can vary between platforms/implementations, so I wanted to strictly type something to an unsigned 8-bit value. Also, it doesn't seem like I can XOR bools on some compiler. I use XOR to toggle rotation state of my BinRects. If using a bool, I could toggle simply by myBoolVar = !myBoolVar. Checking > 0 is true, but again, I should just check if(rotated == true) { }. Would a bool still be a better way to go? It'd certainly make it more readable.

If you want to go for portable serialization you should either be using a library(e.g. Boost::Serialization) or manually write the serialization code, because even for POD structures, the memory layout may differ due to alignment and padding and then there's also the issue of endianness.


Also for clarity sake simply write the following instead:

if(rotated) {}

#5246792 How can this code be refactored to be more proper OOP?

Posted by on 15 August 2015 - 05:59 PM

Why is the Enemy class responsible for loading textures?


Personally, I would just make a member public if your set method is just an assignment, if it's not, it should probably not be called set in the first place. This saves you from having to write unnecessary setter and getter methods. Now some would argue that it's good to have these methods for re-factoring, which is arguably a good point, but I personally have never felt bottlenecked by having to re-factor a public variable to a private variable. Also, I think they look hideous tongue.png.

#5246712 A little math problem

Posted by on 15 August 2015 - 09:58 AM

Shift everything so that the range becomes 0 to 2n + 1, then it's basically the same as indexing a normal array:

i = (y + n) * dimx + x + n
x = i % (2n + 1) - n
y = i / (2n + 1) - n

#5244292 Octrees with multiple-sized objects

Posted by on 03 August 2015 - 08:46 AM

It depends on your octree implementation. If you only allow for leaves to contain objects, your "planets" might cause many "asteroids" being contained in a single leaf. In this case you could create two octrees, one for very large objects and one for smaller objects.


If you allow for all your nodes to contain objects, you can place a large object into the biggest encompassing node and your smaller objects into sub-nodes of that node. This will increase the size of your octree data structure though.

#5242784 Who wants to see a C replacement?

Posted by on 26 July 2015 - 11:28 AM

Jonathan Blow is working on a new language, he has a lot of good ideas. You can check out some demos on his Youtube channel.

#5241766 Sphere - triangle intersections

Posted by on 21 July 2015 - 02:17 PM

Removing that line makes my characters unable to move.

solveCollision doesn't fully move my basePoint, it only moves it to the point of intersection and changes the velocity vector to a "slide" vector, so (basePoint + velcoity) will make the sphere slide.


Ah I see, it should be placed in an else block then:

//solve that collision
    col.basePoint += col.velocity;

As for your other problem, have you tried not positioning exactly onto the plane by moving slightly less?

#5241425 Sphere - triangle intersections

Posted by on 19 July 2015 - 04:15 PM

You're weclome, feel free to up vote any post you deem helpful :D.


1. In the collision response routine on page 47, why does the author moves the sphere slightly less than the collision detection routine suggests?


This is to avoid floating point issues, trying to move exactly on to a plane might cause it to be seen as inside the plane on your next iteration. Moving slightly less than the exact distance will prevent any bugs concerning pushing the sphere out of plane into another one.


Your second issue is caused by an illegal move in your simulate method:

col.basePoint += col.velocity;

You haven't checked collision for that, so this will cause you to go through planes. You already move in your solveCollision function, so removing that line should fix your problem.

#5241280 Sphere - triangle intersections

Posted by on 18 July 2015 - 04:19 PM

//slide plane from point and normal
Plane slidePlane(colPacket->intersectionPoint, colPacket->basePoint - colPacket->intersectionPoint);


Are you sure the normal is correct? I think you want to use something like (basePoint + t*velocity) - intersectionPoint instead of basePoint - intersectionPoint.


Also this line:

colPacket->velocity = colPacket->velocity * colPacket->nearestDistance + intersectionToNewDestination;

nearestDistance is the actual distance, i.e. multiplied with the length of velocity, but here you are multiplying it again with the velocity. I think your intersectionToNewDestination is the new velocity you want.

#5241220 Sphere - triangle intersections

Posted by on 18 July 2015 - 10:33 AM

Ah I see, well I don't see anything pop out really. How do you calculate the signed distance to a plane?


What happens if you remove the collision response and just stop once you collide?

#5238764 How to make 3D art look more like a 2d?

Posted by on 07 July 2015 - 07:41 AM

On the topic of making 3D look like 2D, you might find this talk about the art style of Guilty Gear Xrd interesting