Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 31 Oct 2011
Offline Last Active May 23 2012 03:02 AM

#4941580 Rotating camera around player origin

Posted by on 19 May 2012 - 10:48 PM

I always have yaw, pitch, and roll variables, then every frame I update them with the controller or whatever, then I create a quaternion using those variables, then I transform the "backward" vector with that quaternion. Make the camera position that vector (multiply it by whatever distance you want it to be from the player), add the player position to that vector, then set the target to the character position.

It's really not hard to do, and I would provide some sample code, but I'm a little lazy right now :P

Aww, hell, here's some pseudo-code:
float yaw, pitch, roll;//Some variables that will be in your camera class or wherever you want them
//You could also just use a quaternion rather than those variables, then just multiply the quaternions.
//I feel it's a little better to use yaw, pitch, and roll since you can keep track of your camera's rotations a little better (doesn't really matter if it's a free camera anyway)

//I really don't know which is which with yaw pitch roll, but only two are important (I think yaw and pitch, yaw being up/down, pitch being rotation?)
//Anyway, doesn't matter. Just find out which is which, add to them using input from a controller/keyboard, then create your quaternion

Quaternion rotator = Quaternion.FromYawPitchRoll(yaw,pitch,roll);

float camDistance = 5.0f;
vector3 back = Vector3.Backward;

back = Vector3.Transform(back, rotator);//Rotate our vector
rotator *= distance;//Push it out a distance from the player)
rotator += playerPosition;//Add the position

View = Matrix.CreateLookAt(back, playerPosition, upVector);

#4933615 Diffuse color?

Posted by on 21 April 2012 - 03:54 PM

Then you can just go like this in your pixel shader (in pseudocode):

outputcolor = (texColor + blendColor) * 0.5;

Or you can blend it more or less strongly like this:

outputcolor = lerp(texColor, blendColor, t);

If t = 0, the output color will just be texColor, if t = 1 then it will be blendColor. Values in between give various blend levels. t = 0.5 corresponds to the blend before.

I actually figured it out myself. I tried the code you provided, and it didn't do what I wanted. It did some weird blending.
texColor * blendColor
does exactly what I want.

#4922410 What do I need to know to make a simple physics engine?

Posted by on 15 March 2012 - 04:11 PM

I'm not asking what I need to know to make a physics engine

That may certainly prove to be confusing considering that is the very exact title of your thread.

I, much like the others, can't quite make out what you're asking for. If you want to code the algorithms yourself instead of looking them up, then go read up on basic physics concepts, crank up your math skills, grab a pen and paper and off you go. You should have enough knowledge about the physical relationships between various physical quantities and enough tricks in your math bag that you should be able to not only handle collision detection but collision response. If you do not, then you can find both physics and math tutorials in my signature. That is about as bare as it gets to reinventing the algorithms, without having to reinvent classical physics altogether.

I apologize for being very confusing. I'm not asking how to make a physics engine, I'm just asking what kinds of concepts I should look into to be able to check collisions. After going off on my own research, I've decided that I know much of what I need to know.
Cross production to get the normal of a face (already knew this)
Dot product (also knew this previously)
Projection (knew of it, but never used it)
Normalization (knew it and used it)

The kind of information I was really hoping to hear about were things like Separating Axis Theorem. Which I've looked into and managed to write my own algorithm to check collision between two convex polygons. Voronoi regions were another thing that I found that I might want to look into.

I wasn't looking for info for how to do complex collision responses (like rotation), I just needed to push the bodies apart.

What I mean by wanting to know the basics, and how to use them is something like how you can use dot production to project vertices onto an axis to check for gaps with SAT. (I figured this out myself after reading up about it).

Everything I've found on the net was really vague about how to do things, and they left parts out, and the equations were hard to understand at times.

I haven't learned anything from this post that I didn't already know about, but that is my own fault for being unable to express what kind of info I'm looking for. I apologize for wasting everyone's time. I'm just going to try to figure out what I need to know myself.

Thanks for at least trying.

#4918663 What do I need to know to make a simple physics engine?

Posted by on 02 March 2012 - 12:36 PM

To be honest, your question is really vague. There isn't really one answer. You know you need to know vector and matrix math and geometric principles. Everything else pretty much expands on those things. The theorems for collision detection and resolution, the algorithms for broad-phase and narrow-phase collision detection, etc. just build on these basic concepts and ideas, and then use clever understandings of the math and the problem to accomplish the desired goal. There really isn't one answer about knowing how to detect collisions between various types. It's an open field of active research, and there are many correct answers. Some of the theorems and ideas popularly used to accomplish the things you're desiring are the Separating Axis Theorem, GJK collision detection, Voronoi regions, Minkowski addition, broad-phase collision detection (with things like BSPs, spatial hashing, etc.), etc. These things are just a small sample of things used in various physics engines, and I wouldn't be surprised if you are already aware of this. If you want to know how to detect and handle a collision, I suggest you look up another physics engine, see the algorithm they use, and then research that algorithm. Being able to look at a problem and decompose it into a mathematical formula is also important. Simply googling the type of objects that can collide is also important, and you'll find various answers for various shapes. And I don't think there's one answer that'll solve every problem. Usually, you have to use multiple answers to solve all the problems, as well as decomposing your problems into other problems which can be solved by your chosen method (like with collision detection and concave shapes using SAT or GJK). And then there's the cases you have to deal with where you really can't accurately solve the problem and just have to hack it with an estimation. If you have a more specific question about one of these aspects, then it's a much easier question to answer. But there isn't really an answer to asking what you need to know in order to write a physics engine, because there's a million ways to do it, each way having it's own million things to know. But really, I'd suggest using the Separating Axis Theorem. This site is gold for a starting point. Whether you use SAT, GJK, etc. is up to you. With each of these algorithms, there are things you need to know. But first you need to decide on an algorithm before I think anyone can really say what you'll need to know, specifically.

Sorry about being vague, I'm just unsure of how to ask the question properly. I've looked at the tutorials on metanetsoftware.com, but I'm just not sure how to use the information on there. From what I've seen, they don't really provide much more information beyond diagrams and descriptions. I feel like I already know everything I need, but I just need a "refresher" so to speak.

I guess to get a better answer, what is likely to be the best book to find information about vector math used in games?

#4916890 What do I need to know to make a simple physics engine?

Posted by on 26 February 2012 - 10:27 PM

Hey! That thing is really interesting! I think I'll play with it after I finish my homework. Thanks!

I would give you the source code, but I'd rather not give out any othe source code of my unfinished game (even though it's only test code). If you want more information about how to implement a quadtree, send me a message and I'll explain it to you.

#4916805 What do I need to know to make a simple physics engine?

Posted by on 26 February 2012 - 03:33 PM

Well, if you really don't want to use a free physics engine (there are lots there, and chances are yours won't be as good as they are), some things that you need to learn are: Kinematics, Forces, Kinetics, Collisions (detection and response), Vector math.

I know I need to know all these things. I'm not asking what I need to know to make a physics engine, I'm asking what I need to know to be able to write collision detection tests between different collision types. Specifically, what concepts of vector math should I know, and how do I use it? I know there's dot product, cross production and such, but how do I use those together to say, test where a ray collides with a plane? I'm sure I could do something similar to slope, and just project the ray to plane, and get that position, but I'd likely just brute force it. I'm sorry if I'm being confusing, but I'm just not entirely sure of how to ask this question without seeming really inexperienced.

When you know many words, what they mean, and how they can be used in sentences, you are able to create your own, proper, sentences. I'm basically asking what these "words" are, how I can learn what they mean and how to use them in "sentences". I hope that analogy made sense.

#4916783 What do I need to know to make a simple physics engine?

Posted by on 26 February 2012 - 02:36 PM

I'm working on a 3D game right now, and my engine is going to need to test collision for a few different collision types. Rays, Spheres, oriented boxes, non-oriented boxes, and cylinders. I'm not asking to be told what code to write for my engine, I just want to know a good starting point for learning to write the code myself. All I'm asking is what key concepts for testing collisions between different shapes, and how to push objects out of each other. I'm familiar with gravity, and force and all that, so that's really not what I need to know. I could easily push two spheres out of each other, and I could probably do the same with non-oriented boxes, but I'm not sure of where to start (as far as mathematics goes) for rays, oriented-boxes, and cylinders.


#4906456 Line drawing? (C#)

Posted by on 26 January 2012 - 10:14 AM

That's a great method, but I noticed that your x and y variables are unused.