Jump to content

  • Log In with Google      Sign In   
  • Create Account

Lauris Kaplinski

Member Since 02 Aug 2006
Offline Last Active Feb 18 2013 02:33 AM

#4985683 How can I put 2d sprites in a 3d world?

Posted by on 01 October 2012 - 02:37 AM

The correct term to use/search for help is "billboard". I.e. you create a rectangle, apply texture and keep it always faced to camera. Normally this is used for things like UI elements (think about health bar above character's head), particles (sparks, smoke, fire) etc. but you can use it for sprites as well. More advanced billboarding uses vertex shader, but for simpler cases you can just modify the transformation of your rectangle object every frame.

Unity Wiki page about billboard: http://wiki.unity3d.com/index.php?title=CameraFacingBillboard

#4982844 Guide to bad game design

Posted by on 23 September 2012 - 01:57 AM

Make difficulty levels that only affect enemies, weapons and ammo. All jumping and stealth still requires near-perfect timing, whatever the difficulty is.

#4980677 Reference& question

Posted by on 16 September 2012 - 12:14 PM

At end of code here, "10MbClass* Pobj" is 8bit in memory storage?
and "10MbClass& Robj" is how big? is reference taking same amount of space as pointer or?

You probably meant 8 bytes.
And yes, internally references take the same amount of memory as pointers. Except of course in cases where compiler is able to optimize these out.

#4979404 View matrix forming

Posted by on 12 September 2012 - 12:32 PM

Think of all matrices as a transformation from one coordinate system to another one. In case of view matrix you have always keep in mind, which transformation you are talking about - world to camera or camera to world.

Your view matrix above transforms from world coordinate system to camera coordinate system.

Now u,v and w are camera axes represented in world coordinate system. Thus in your view matrix they form rows, not columns.
On the other hand the world axes represented in camera coordinate system do form the rows of view matrix.

#4978115 Perspective to Ortho Collision fails.

Posted by on 08 September 2012 - 04:37 PM

No, you have to start from two points in screen space:
One at mouse position (x,y) and near plane (1) - this will be ray starting point if transformed to world space
Another at mouse position (x,y) and far plane (-1) - this will be ray endpoint if transformed to world space
Now after transforming these points to world space use these to construct your view ray.

#4977753 Trouble combining two projection spaces?

Posted by on 07 September 2012 - 11:53 AM

Is your brush border strip correct? I.e. if you render it as "normal" object in deferred pass, does it appear as ellipse (as it should) or line (as it does now)?
Try hardcoding linestrip coordinates (so it lies on the ground plane) - what happens?

#4977619 Effective way to detect whether my 3D cubes are outside the 2D screen boundar...

Posted by on 07 September 2012 - 07:37 AM

What's wrong with the following method?

1. Extract the frstum sides (4 planes) - one-time operation
2. Find the distance of cube center from all planes (4 x cheap operation)
3. If any distance is > diagonal/2 discard that cube

It may have few extra operations compared to your method and it slightly overestimates cube size but I doubt any of these are serious problems.

If you want the absolute least amount of tests and your cubes have linear trajectories then precalculate the time when they go offscreen (using either the above method or the exact method), store the value for each generated cube and discard these as soon as the system time will become greater than their lifetime.

#4977614 blender cutscenes

Posted by on 07 September 2012 - 07:21 AM

If you want to use the whole Blender material/lighting/environment options then you should render it to some common video format, then implement loader for that video format in your code and show frames as sequence of images. While in theory it is possible to parse Blender file and reimplement it's rendering system, it is too much work to do.

If you only need object placements, basic textures, lights and camera movement you may try using some common export format, like FBX. But you still have to find/implement the loader of that specific file format, implement animation system and so on.

#4977544 Stuck in late development

Posted by on 07 September 2012 - 03:14 AM

Writing good code from start is always easier than "debugging things to existence". But what to do if you already have a bug-ridden code base?

1. Admit, that it is not hopeless
2. If you wrote the code yourself, take some time off. Work on something else. Rest.
3. Take a fresh look at your codebase.
4. Write down the structure of your code.
5. Start writing down bugs. Assign priorities to them.
6. Work becomes manageable.

#4977108 Coding gradiant transitions

Posted by on 06 September 2012 - 01:34 AM

As I understand your banding is caused by the mapping of smooth gradient (either HDR image or calulated floating-point color values) to 8-bit color channels. You cannot get rid of these bands unless you introduce some dithering.
As a test you may try to add some low-intensity high-frequency (pixel) noise to you color values before sending these to framebuffer. Or even better - add the noise before smapling gradient values so the bands will be smeared aout a bit.

#4976589 being realistic

Posted by on 04 September 2012 - 04:23 PM

I wanted to know if it is possible for a single person to make a game in sdl and or opengl and with this i mean a big game not just a pong or something like that. Should i use a game engine instead?? I want to make a nice looking game, i prefer 2d but i dont dislike 3d. I also like to code so I wouldn't like to use one of those engines where you don't code at all.
I feel that even though engines help a lot they also limit what you can do and also even though I like the flexibility that using sdl and opengl gives you but it seems to hard Posted Image and maybe I just can't find any good one but everytime I try to look for projectsmade in sdl, sfml, opengl and directx they all look horrible and boring.

First - yes, it is possible. But it is hard work - a bit easier if you use engine, but still huge amount of work.
I think that if you want to make big game then creating art will become bigger task than code. Of course it depends on the kind of game you are building - if you are clever, you can create very rich environments from simple elements - like Minecraft. But in any case you need high-quality art for nice looking game. If you are not modeler/pixel artist/background artist then learning to create it will take very long time.

#4929285 Height on triangles using 4 points

Posted by on 08 April 2012 - 05:25 AM

If Y is my up vector, shouldn't i be using x and z to find the distance between the points?

Oh, yes of course ;-)

#4929008 Height on triangles using 4 points

Posted by on 07 April 2012 - 04:15 AM

Thanks for the reply, i'm understanding most of it. Just what do u mean by

Just use squared distance of 2D vectors (ignore Z)

I should have said "squared distance between two 2D points :-)

To determine where your point lies, you have to project it to XY plane. I.e. if you have player position P=(Px,Py,Pz), make it 2D vector P'=(Pz,Py) and test, int which triangle it lies by finding the its distance from 2D vectors P1'=(P1x,P1y) and P2'=(P2x,P2y)

And instead of calculating and comparing actual distances between P and P1 or P2, you can compare squared distances. I.e. instead of

L = sqrt ((Px - P1x)*(Px - P1x) + (Py-P1y)*(Py-P1y))

You can leave out square root and use

Lsquared = (Px - P1x)*(Px - P1x) + (Py-P1y)*(Py-P1y)

Now this is pointless optmization - but it does not hurt.

#4928902 Height on triangles using 4 points

Posted by on 06 April 2012 - 03:13 PM

What you need, is:
  • Test, whether point is inside triangle
  • Construct plane from three points
  • Find line-plane intersection point

1. As you already know in which grid square your point lies, you can test whether it is closer to p1 or p2. Just use squared distance of 2D vectors (ignore Z)

2. Construct plane from three points (plane is given as normal vector Pn and scalar value Pd). I use P0, P1 and P3 as example triangle.

n = (P1 - P0) cross (P3 - P0)
Pn = normalize (n)
Pd = -Pn dot P0

3. Find line-plane intersection point (line is given as point Lp and direction Ld, intersection point is P)

den = Pn dot Ld
If den is 0 then line is parallel to plane
t = -(Pn dot Lp + Pd) / den
P = Lp + t * Ld

In your case you can use line, that starts from same realistic place - say 10m above the head of character and goes directly downwards - i.e. Lp = (playerX, playerY, playerLastZ + 10), Ld = (0,0,-1).

#4928762 Collinear 3d Points

Posted by on 06 April 2012 - 06:43 AM

EDIT: Another method is checking if the dot product of (P2-P1) and (P3-P1) is either -1 or 1.

You probably meant normalize(P2 - P1) . normalize(P3 - P1)