MattEvans 473 Veteran Poster Team Colleague Featured Poster

What kind of 2D library? Graphics, or physics? or something else?

I like this book alot, it says collision detection, but it also has a lengthly intro to many of the concepts of simulated 'space and time': http://www.amazon.com/exec/obidos/tg/detail/-/1558607323?tag=realtimecolli-20. Is 3D rather than 2D, but it's (a hell of) alot easier to convert 3D stuff to 2D than the other way around.

But, I don't have masses of books, (infact, I only really have that book, and this one, http://www.amazon.com/Calculus-Analytic-Geometry-George-Simmons/dp/0070576424, which is way to deep for what I tend to need), so perhaps there are more appropriate choices.

For basic 2D math.. A 'middle-level' education textbook should probably suffice.. In UK terms, an A-level or equivalent textbook should have enough material to understand most things you'd need to do w.r.t to 2D geometry, linear algebra, integration/differentiation, and that's a good basis for doing a whole lot of stuff.

Often, the hardest thing to work out is where & how to actually apply what you know, and what extra you'll need to know in order to do x. If you can classify exactly what x is, searching for how x is usually done, reading that material, following references / researching what you don't know, and recursing tends to work quite well, and you'll pick up useful transferable stuff along the way.

A quick question, what sort of mathematical architecture are you using? By that I mean, when you think about your code, do …

MattEvans 473 Veteran Poster Team Colleague Featured Poster

It's easy enough to arbitrarily set the rotation point, e.g. this will work:

case 'E':
case 'e':
{
	//Rotation of the red square.
	glMatrixMode(GL_MODELVIEW_MATRIX);
	glLoadMatrixd(redTransformationMatrix);
	glTranslated(200.0, 600.0, 0.0);
	glRotated(1.0,0.0, 0.0, 1.0);
	glTranslated(-200.0, -600.0, 0.0);
	glGetDoublev(GL_MODELVIEW_MATRIX, redTransformationMatrix);
	glutPostRedisplay();
	break;
}

The general rule is, translate to the origin, rotate, and then translate back again.

However, you are making your life abit more difficult by offsetting the square outside of the matrix.. that is, you are doing matrix transforms, and then offseting by 200, 600 in that space.. you'll find it easier to initialize your matrix to that 200, 600 offset, and then always draw the square at 0,0 in the space of your matrix transform.

That is, if you do this:

void init()
{
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	[b]glTranslated (200.0, 600.0, 100.0);[/b]
	glGetDoublev(GL_MODELVIEW_MATRIX, redTransformationMatrix);
}
...
void display()
{
...
	glPushMatrix();
	glLoadMatrixd(redTransformationMatrix);
	glColor3d(1.0, 0.0, 0.0);
	[b]DrawSquare(0.0, 0.0, 0.0);[/b]
	glPopMatrix();
...
}

Then, you can just do this:

case 'E':
case 'e':
{
	//Rotation of the red square.
	glMatrixMode(GL_MODELVIEW_MATRIX);
	glLoadMatrixd(redTransformationMatrix);
	glRotated(1.0,0.0, 0.0, 1.0);
	glGetDoublev(GL_MODELVIEW_MATRIX, redTransformationMatrix);
	glutPostRedisplay();
	break;
}

You will find, when you do get it rotating properly, that any subsequent translation will be in the local space of the previous transform. That is, what you consider to be moving in 'x' will actually be moving in the rotated x direction. If that's what you want, great, otherwise, you can keep transforming in global 'x' by reversing the translate multiplication order, like this:

case 'D':
case 'd':
{
	//Translation of the red …
Nick Evan commented: Your knowledge of 3d-development is somewhat frightening ;) +17
MattEvans 473 Veteran Poster Team Colleague Featured Poster
#include <vector>
#include <iostream>

int main ( void )
{
  std::vector < int > myvector;
  for ( int i = 0; i != 10; ++i ) {
    myvector.push_back ( i );
  }
  int * myarray = &( myvector [ 0 ] );
  for ( int i = 0; i != 10; ++i ) {
    std::cerr << myarray [ i ];
  }
  return 0;
}

Should always work because a vector is internally just an array. But, if they wanted you to use it as an array, there'd be a member for accessing the array (like c_str in std::string ).

sciwizeh commented: Very useful thanks +1
MattEvans 473 Veteran Poster Team Colleague Featured Poster

Of course it is possible; there is necessarily always a projection from object>screen coords and there is always a projection from screen>a subset of object coords on a plane parallel with the view plane (notice the difference). If you want a 1:1 mapping between screen and object coords, use an orthographic projection (which you are), and make sure that the args to glOrtho are the ACTUAL width and height of your viewport, and remember that opengl puts 0,0 (in screencoords) in the bottom left rather than the top left, and 0,0 (in object coords) in the center of the screen.. so, something like:

glMatrixMode ( GL_PROJECTION );
  glLoadIdentity( );
  gluOrtho2D ( 0, w, 0, h );
  glScalef ( 1, -1, 1 );
  glTranslatef ( 0, -h, 0 );
  glMatrixMode ( GL_MODELVIEW );
  glLoadIdentity( );
 /* draw stuff here */

Now, x,y in the screen will be x,y,0 in object coords.

If you use a projective view transform, you can use gluProject/gluUnproject to move between object space and screen space coords. You probably don't (although maybe you do) need to convert between screen&object coordinate systems though, the only time you'd usually need to do that is if you want to be able to 'pick' (with a mouse or similar) some point on the card.

If you want correct relative positions, just work on the assumption that object units are e.g. millimeters, the relative position/sizes of things will always be correct, and you can then pre-scale the modelview matrix to …

Nick Evan commented: Helpful as always +15
MattEvans 473 Veteran Poster Team Colleague Featured Poster

Brute force isn't too bad.. you don't have to check every pair of pixels between the two sprites, you only have to check each pixel space to see if it's occupied twice, and that's not very costly ( it's no more costly than looping all of the pixels in the screen, and the calculation can be performed for all objects at the same time ). This is what a z-buffered application (e.g. OpenGL or DirectX) does to determine occlusion, so it's not really 'inneficient'.

There are some optimizations you can make though.. for any candidate pair of objects, calculate the 2d minimum bounding rectangles of the two sprites, and you will only possibly get a collision within the intersection of these two rectangles. Obviously, if the intersection is empty, you can return false straightaway, otherwise, check the pixels in the intersection.

Heuristically, for two 'convex' sprites, you're more likely to get a collision towards the (actual) centroid of the sprite so check the pixels in the intersection rectangle from the 'outside' in.. and finish the algorithm early if a collision is detected.

You can also group up pixel states into pre-defined groups of 8/16/32/etc pixels, and then it just takes just a bitwise 'and' to check a whole group of pixels at a time. 16 is good because it's square - effectively you can test two 4x4 squares of pixels in one cycle, rather than just testing 1 pair of pixels. Massaging your data into the correct …

Ezzaral commented: Great post. +19
MattEvans 473 Veteran Poster Team Colleague Featured Poster

Are your transforms 'full 3d' or 'half 3d'? That is, when your character rotates, can they rotate over all axes, or just around an 'up' vector? Are you using matrices as the authoritative representation of the character's transform, or some scalars ( typically x, y,z and rotation ).

MATRICES

If you're using transform matrices, the vector that points 'forward' in the character's space is one of the vectors in the upper 3x3 submatrix, the actual vector depends on the way you define 'up' and 'forward', and whether the vector is a row or column of the matrix depends on whether you treat vectors as rows or columns.. but for e.g., in OpenGL, it would usually be:

m00 m01 [b]m02[/b] m03
m10 m11 [b]m12[/b] m13
m20 m21 [b]m22[/b] m23
m30 m31 m32 m33

the usual 'forward' vector (z) is emboldened. If you extract 'forward' from the character's matrix, and add if to the character's position, it will move the character in their own 'forward'.

I know for a fact that this is different in most DX setups, but it will be quite similar, most likely the row m20->m22, assuming that z is forward, which it isn't always.

SCALARS

If you're just using x, y, z and rotation scalars.... then assuming that positive z is 'up' and positive x is 'forward'... the forward direction vector is:

x = cos ( r )
y = sin ( r )

so,

player.x += cos ( r ) * speed; …
Ezzaral commented: Another great post. +18
MattEvans 473 Veteran Poster Team Colleague Featured Poster

Lines do not have ends: although a line is often uniquely defined by two endpoints coincident with the line; a 'line' is correctly considered to be infinite in both directions.

Line segments are lines with ends... and a 'one ended line' is usually termed either a ray, or a half-line ( depending on whether or not it's considered to be directed).

An axis is generally just a direction vector - i.e. an axis has no position, only a (usually normalized) direction.

MattEpp's suggestion is roughly correct : determine the angle that object2 is relative to the reference angle of object1 ( the reference angle is at 0 degrees ), and subtract the current angle of object1 to give the angle to rotate by (which we'll call 'delta').

However, some considerations - arctan ignores the quadrant (infact, the input to arctan makes finding the quadrant impossible): so you can't differentiate between the output of arctan for certain pairs of (non-congruent-modulo-360) angles. That's basically bad, so, use arctan2 (C function is atan2). Remember output is radians, NOT degrees.

You also need to normalize the input to atan/atan2, else the result is meaningless.

So, in C:

double obj1x, obj1y, obj2x, obj2y; /* positions of objects 1 & 2 */
double obj1rot; /* rotation of object1*/

double relx = obj2x - obj1x;
double rely = obj2y - obj1y;

/* length of relative position (i.e. distance) */
double reldis = sqrt ( ( relx * relx ) + ( …
Ezzaral commented: Always good info in your posts. +16
MattEvans 473 Veteran Poster Team Colleague Featured Poster

That "the behaviour when dereferencing an invalid pointer is undefined" is fact.

Other than that, the best you'll get (in terms of an explanation for why you get this output) is speculation or some implementation-specific reason. On my implementation (GCC) reasonable evidence (see second code I posted) suggests that local variables in any function get allocated from the same starting address (assuming the calls come from the same level).

(EDIT: and that would be sufficient explanation for your output, providing std::ostream::operator<< allocates at least one local variable)

There's no requirement for "reclaimed" memory to be zeroed or otherwise restored (by reclaimed, I mean memory under deleted pointers or under auto variables that go out of scope). The most efficient implementation strategy is to just leave the contents of such memory untouched, hence, before reclaimed memory is overwritten, it will tend to contain its old value. (You shouldn't rely on this, either)

Nick Evan commented: Excellent posts in this thread! +12
MattEvans 473 Veteran Poster Team Colleague Featured Poster

Hey, sorry for the delay, been a bit busy.

No I am using it for Robot motion planing.

Cool.

DO U HAVE ANY MORE INFO ON THIS? COULD U EXPLAIN ME ME THE OPEN SPARSE GRAPH?
TUTORIAL, SITES, PUBLICATIONS E.T.C

Well, it's open space graph, but the sparseness of the environment is a factor in choosing the method used to generate the graph... There isn't a one-size-fits-all method, because you get a better result using a different method for different environments.

E.g. for an environment that's mostly open space, with a few obstacles that are roughly the same size, you can create the Voronoi tesselation ( http://mathworld.wolfram.com/VoronoiDiagram.html ) of the obstacles ( treating each obstacle as a point ), if you look at the picture on that site, treat the lines as the arcs and the junctions as the nodes of a space graph, following any path through that graph will keep the agent at a maximal distance at all times between obstacles, running standard a-star on that graph will give the shortest path that maintains such a maximal distance ( although this isn't necessarily the shortest path through the space itself, since the constraints conflict somewhat ). However, with obstacles that are different sizes, or very large, you have to do a lot of 'repair work' on the graph before it's useable...

If the environment is mostly obstacles, or narrow paths ( like a maze ), you'd get a better graph by …

William Hemsworth commented: Epic post :) +5
MattEvans 473 Veteran Poster Team Colleague Featured Poster

Some questions to you:

- are you using the A* for AI character path planning? ( usual case ), is the 3D space unbounded? if so, are you ok with the fact that 3D A* search in infinite space will nearly always find a path, but that the path might well just go over ( or under ) all of the obstacles?
- are the obstacles dynamic ( moving )? if not, it's nearly always better to calculate an open space graph ( i.e. find waypoints between the obstacles, connect waypoints that are visible from each other together ) and then run A* on that graph, than it is to run A* on dense uniform grids.. if the obstacles are moving, you need to incorporate the movement in the A* search, else you'll hit a timestep problem ( e.g. a path that existed at the beginning of the search stops existing after the search has finished ). the timestep problem can be dealt with in simple A*... but.. it will obv. become more difficult to deal with as you add layers to the algorithm..
- A* becomes evil when it can't find a path quickly, i.e. if no path exists, A* will expand every reachable node. you have to either limit the input node-set, or limit the number of iterations of A*. limiting the number of iterations of A* means a search might terminate with fail even when a valid ( but long, winding, complicated ) path …

Ezzaral commented: Good information here. +13
MattEvans 473 Veteran Poster Team Colleague Featured Poster

alpha = [A-Za-z]
numeric = [0-9]
special characters = could be [^A-Za-z0-9], but it depends on your definition of 'special'. usually it's prefered to treat _ ( underscore ) as non-special at minimum, thus: [^A-Za-z0-9_]

when a character group ( enclosed in square brackets ) starts with ^, it means 'not': [^a-z] means "anything but the characters a-z". when ^ is in a character group but not at the start, it means the literal ^ ( caret ) character.. e.g. [^^] means "anything but ^".

when a regex pattern starts with ^; it means "bind to the start of the string*", and it will only be able to match if the regex matches from the very beggining of the string, similarly $ at the end of a regex means it will only be able to match if the regex matches up to the very end of the string, so ^ at the beggining AND $ at the end means only match if the entire regex matches the entire string. ( otherwise, a regex will match if any part of the string matches the rules. )

( * or to any given line, but thats complicated so don't worry about it for now ).


/^[0-9]*$/ means match a complete string that contains 0 or more numbers, this is what * means ( i.e. an empty string, or a string containing only numbers )

/^[0-9]+$/ means match a complete string that contains 1 …

OmniX commented: Great informative reply. Thankyou! +1
MattEvans 473 Veteran Poster Team Colleague Featured Poster

DirectX doesn't necessarily have better performance : it really depends how the graphics card manufacturers build their cards, and write their drivers. Without hardware acceleration, DirectX is probably faster, but only on Windows ( and only because the software implementation of OpenGL from Microsoft isn't great ). With hardware acceleration, the limiting factor is the card itself, not the API.

However, DirectX only works on Windows/XBox anyway - OpenGL works on a larger number of platforms.

Read: http://www.gamedev.net/reference/articles/article1775.asp, it's pretty unbiased and ( importantly ) it's up-to-date. Much discussion you'll find on the net about OGL vs. DX is way out of date.

Nick Evan commented: Thanks for the correction/follow up +9
MattEvans 473 Veteran Poster Team Colleague Featured Poster

For 2D point-in-convex or point-in-non-convex, see the crossing test on this page: http://www.erichaines.com/ptinpoly/. As its given there, that test will work in 2D only, for a 2D shape embedded in 3D, you have to project the point onto the plane of the shape first, if the projection is impossible, obviously the shapes don't intersect. The same theory should apply for polyhedra, the number of face/edge crossings determines the 'side' ( inside or outside ) that the point is on,

Of course, it becomes more difficult when you start incorporating different shapes to collide with ( i.e. not just polygon-against-point ).

Most shapes can be decomposed into more simple shapes. In your example, the shape could be decomposed into a pair of triangles, and to detect if triangles and other shapes intersect there are a number of popular methods.. If you can decompose into cuboids, spheres, tetrahedra, etc, ( rects, circles and triangles in 2D ) you'll be able to find existing optimized methods.

For generalized convex shapes, see below, but for generalized concave shapes, there aren't any efficient methods ( it's one of those 'difficult problems' in geometry ).

There also aren't effective generalized methods for converting any shape into the simplest decomposition of non-convex shapes, although there are certainly generalized triangulation routines. If you know the shapes involved before hand, you can either preprocess, or manually specify the bounding poly[gons|hedra].

My favorite method, at the moment, is to perform GJK on the …

Ezzaral commented: Excellent post. +11
MattEvans 473 Veteran Poster Team Colleague Featured Poster

assuming that look at and 'up' are at roughly at right angles; take the cross product of the look-at and up direction. this will give you a vector that points from the characters left to right ( or right to left ). if the look at and up aren't at right angles... this still should work, but you must normalize the result.

now, calculate the normalized vector between the listeners position and the source position.

finally take the dot product of the normalized vector between listener and source and the normalized vector that points left to right.

the dot product between two vectors gives the scalar projection of one vector onto another, when both vectors are normalized, this projection is a number between -1 and 1. If the value comes out backwards ( negative when it should be positive ) reverse the order of operands to the cross product, or of course, just multiply by -1. Test with something visual first, to see the magnitude of difference between different positions, then scale/offset the result according.

S = source position
L = listeners positon
A = look at direction
B = up direction

dot( normalize( cross( A, B ) ), normalize( S - L ) )
MattEvans 473 Veteran Poster Team Colleague Featured Poster

You can't disable the close button in a popup. It's part of the browser; a webpage rightfully can't assume control over all aspects of the browser.

Reorganize your logic so that it isn't an issue, or use a "popup div" instead ( i.e. http://javascript.internet.com/miscellaneous/popup-div.html ).

peter_budo commented: Nice link, didn't know this can be done so easily +9
MattEvans 473 Veteran Poster Team Colleague Featured Poster

You need to represent a game company with development + release experience, and pay sums for a licence to get your hands on the official Wii SDK.

If you're talking about C# + XNA as being 'the Xbox360 SDK', you're a bit out, XNA is not the complete XBox360 SDK.

You can usually get dev-kits for last-gen consoles easier than you can current-gen i.e., today I can aquire a PS2 dev-kit easily, but not a PS3 dev-kit. ( Even this is probably legally 'shady' though; it's something of a back-of-the-shop affair ).

MattEvans 473 Veteran Poster Team Colleague Featured Poster

Psh.. it's not so serious.. a bot isn't necessarily bad. IMNSHO, there's no such thing as 'cheating' in a computer game.. It's like 'cheating' in reading a book by looking at the last page first. It only really hurts yourself. Oh yeah.. w/ regard to online tournaments, ok, ok. Don't cheat in a tournament, you'll get found out and blacklisted anyway, or just lose respect in w/e gamerz community you're a part of. For MMORPGS? Hey, the real world has gangs and murderers and fraudsters, so I guess, if there are people who play that way in an MMO world, they're a feature!

But anyway, on topic: No, no idea where to find a bot maker. It likely depends what game, since there's rarely such a thing as 'generic'.

MattEvans 473 Veteran Poster Team Colleague Featured Poster

That image is an 8-bit per pixel PNG, and 8bpp PNGs can only contain 1 bit transparency ( a pixel is either fully opaque, or fully transparent ). With higher bpp PNGs, you're allowed to use alpha translucency ( a pixel can be 25%, 50%, 68%, etc transparent ). Microsoft IE versions have been OK with the transparency in 8bpp PNGs for some time, but not with the translucency in 32 bpp PNGs.

To solve... make sure you dont use translucency ( only transparency ), and save as 8bpp PNG to force 1-bit transparency.

See two attached images. They both work nicely on my browser ( Opera ), but I would imagine that only the 8bpp has a transparent background in IE ( especially IE6 or earlier ).

shmay commented: Awesome, thank you. My picture is now transparent in IE. Unfortunately it looks like complete ass now. stupid IE. +3
MattEvans 473 Veteran Poster Team Colleague Featured Poster

It sounds like the `students' template isn't being matched atall ( that would cause the output to end up only as text nodes ). Silly question - did you change the capitalization of the match="students" in the 2nd template to match the capitalization of the `Students' node in your document?

The only other thing I can think of is changing the <apply-templates> in the first template to explicitly select only the Students ( root ) node, i.e:

<xsl:template match="/">
  <xsl:apply-templates [b]select="Students"[/b]>
    <xsl:with-param name="first" select="1"/>
    <xsl:with-param name="last" select="8"/>
  </xsl:apply-templates>
</xsl:template>

If the root node is `Students', that should be the same as <apply-templates> without an explicit select, but, I guess all xslt processors are a bit different..

tgreer commented: Thanks for your help. +7
MattEvans 473 Veteran Poster Team Colleague Featured Poster

>> I've just seen a lot of, and herd of, talk about pure CSS layouts

I have also heard a lot of this talk. I can't imagine a CSS-only layout, since these layouts do use a few (X)HTML elements ( div, p, span, ul, strong, em, etc.. )*. So, I will use 'no tables' for what might be called 'CSS-only', and I don't need a special word for normal coding practice, because it's normal coding practice.

* don't get me wrong, these are all great elements.

For certain layouts, it is perfectly feasible, even elegant, to use minimilistic markup and it is most certainly the case that not every layout needs a table.

Many of the 'no tables' pages are fixed-width -- as is Daniweb -- the entire content is set at some defined width ( suitable for the majority of users, but smaller than the available visible width on an average display ), this makes it easier to use positioning and strictly-defined sizes for elements. 'No tables' design also favours sites without complex non-flowing layout ( text and pictures, newspaper/magazine-esque pages ); sites where alot of the layout is made of vertically stacked blocks ( like Daniweb again, although, there used to be tables here in places [ yep, there still are ] ); and sites that are sent to small devices, since reduced layout works well there. Some of these sites are indeed really pretty, and examining source code is a good way to …

MattEvans 473 Veteran Poster Team Colleague Featured Poster

Only one rule from me.. Don't set out to "work with divs to create a pure CSS layout", unless you're entering some wannabe-elitist competition. Use whatever's appropriate and whatever works best: tables, frames, etc.

Nothing but a table does what a table does, and nothing but a frame does what a frame does. Those elements would have been W3C-deprecated in the last recommendation if they were redundant, and they are certainly not redundant. There is no suggestion by anyone worth listening to that the table or the frame tag are, or will soon be, deprecated*, and there is no reason to punish yourself by ignoring these valid, useful, elements. Just don't use tables for anything you can do easily in CSS ( note 'easily' ), and avoid frames like the plague unless you're making a certain kind of site: frames are great for offline API documentation minisites, and sites that are supposed to be read like books, but they are, of course, quite awful for most sites.

The font tag was deprecated, because it's redundant and difficult; don't use the font tag.

In a way, it makes me laugh that certain people took this WAI guideline so far: http://www.w3.org/TR/WAI-WEBCONTENT/#gl-table-markup, yet will blissfully ignore the rest of the WAIs recommendation, to the detriment of many. One can create a usability atrocity without using a single table, frame or font tag; and equally, one can create a blissful user experience with a frame and some layout tables. …

Venom Rush commented: Your response was brilliant ;) Thanks +1
MattEvans 473 Veteran Poster Team Colleague Featured Poster

browsers,wont,usually,break,a,string,unless,it,has,some,breaking,characters,in,it,such,as,spaces,so,either,this,text,will,extend,forever,or,it,will,get,cut,off,depending,on,the,browser,mostly.

this isnt a daniweb issue,it's more of an issue with a convention in the way text is processed/rendered at the client.

that said, it is relatively easy to fix, just run through the uploaded post data and insert extra breaking chracters as required.

~s.o.s~ commented: Clever! +20
MattEvans 473 Veteran Poster Team Colleague Featured Poster

If I'm honest, I only dishwash once a week when every piece of kitchenware is unusable for any purpose. So, the cutlery is usually jammed in anyway and everywhere it can fit.

I guess I save loads on dishwasher tabs ^_-

Lardmeister commented: thanks for being honest +2
MattEvans 473 Veteran Poster Team Colleague Featured Poster

This is good reference, http://www.gamasutra.com/features/19991018/Gomez_1.htm there are collision tests for different pairs of 3D objects ( see contents box on the right ). The tests would work in 2D, but, there are even simpler versions of these tests for 2D.

'Separating objects' that have collided is theoretically simple - calculate the magnitude of the velocities of the two objects before the collision, make them proportional ( i.e. turn the velocities into positive normalized weights ) hold on to those for a second =P. Now, calculate the intersection vector of one of the objects into the other object, that's simple, since most static collision tests for convex hull types give you this information for free. Translate both objects by their normalized velocity weight multiplied by the intersection vector, or by the normalized velocity weight times the intersection vector times minus 1; depending on which of the two objects it is, and depending which way you measured the intersection vector.. that works well for immediate separation of illegally intersecting objects. Alternatively, never put objects into intersection - keep them separate by checking that they can move into space before you move them, or use both methods.

Do you have grid/tile based space or not? If you dont, I suggest using some kind of pairwise pruning before checking objects - i.e. not checking objects that can't collide.

All in all, it's quite a complex subject, but there are many simplificiations. In 2D tile based space, it's alot easier …

Ezzaral commented: Very good info. +6
MattEvans 473 Veteran Poster Team Colleague Featured Poster

3D math and physics, artificial intelligence ( as it relates to games ), 3D graphics [ stay on top of all of the updates ], general programming skills, data formats, optimizing, and more... of course, pick/change/add the parts that are relevant to what you're trying to do. A good way to learn alot is to try and make something ( a game ) that you don't know how to make. You'll be forced to find out and learn alot of things. There's no real substitute for that.. reading all the theory is mighty boring unless you have ( or can see ) a use for it.

scru commented: thanks this helps +1
MattEvans 473 Veteran Poster Team Colleague Featured Poster

Basically whatever url I passed in xmlHttp.open("GET",urlstr,true) had to match the actual url in the address bar.

Yes, this is the case. www.domain.com is a different subdomain from domain.com in terms of the address.. it might not infact be a different subdomain but the address indicates that it is. FF is security conscious, it'll think your trying to issue ajax requests to a foreign domain.

If you're ajax-ing to the same server that the page is hosted on ( which is all you should be allowed to do ), then try using a '/' rather than a http:// and domain.. i.e, instead of ajax-ing 'http://www.yourdomain.tld/thescript.cgi', ajax '/thescript.cgi'.. this will only work if your page is on 'yourdomain.tld', and not in a subdomain (other than www).

agrothe commented: thanks, very informative. +2
MattEvans 473 Veteran Poster Team Colleague Featured Poster

It isn't accessible for users who use such things as screenreaders

Screenreaders work better, ( i.e. more intuitively and standardized ), with tables than they do with some div layouts that force table-like display using floating/positioning, or with div layouts that want to order markup weirdly for the purpose of upping search engine rankings. It's an old myth that screenreaders fail with tables; more modern readers are very capable of reading tables, whether they be used for layout or pure tabular data.
Order of markup and correct use of 'special tags' is more important than the block tags used in markup. Search engines and screenreaders alike care little for table/div/span... all are at best semantically meaningless. 'h1', 'h2', 'title' should be important, as is 'a' and others.

It isn't just about tables: it is about using ANY html for layout purposes. xHTML should be used just for content and CSS for layout. It's that simple.

Great in theory. Not so great in practice. XHTML defines a series of tags, the purpose of most of them is layout and presentation. If you really only care about 'semantics', use plain XML and style that with CSS; you might have compatibility problems for the moment since only the latest browsers support XML pages.. and you need the latest CSS standard to be well implemented for it to be useful for anything non-trivial.. but I guess, any 'web developer worth their salt' isn't as bothered about compatilibity and what they can actually …

GreenDay2001 commented: very well said buddy! :) +4
MattEvans 473 Veteran Poster Team Colleague Featured Poster

Ah... it's not doing it on Firefox, only Opera.. strange :|

Hm.. the code for this page looks wierd here though:

<div class="de1">[B]<span class="st0"</span>[/B]</div></li></ol></pre>

and here:

&lt;a</span> <span class="kw3">href</span>=<span class="st0">&quot;</span></div></li><li class="li1"><div class="de1"><span class="st0">[B]</span</span>[/B]</div

Assuming that's autogenerated by the syntax highlighter; I would assert that that's where it goes wrong, and that Opera and FF have different ways of dealing with the glitch.

MattEvans 473 Veteran Poster Team Colleague Featured Poster

Erm.. not using javascript. It's not a good way to adequately password protect pages. The best you can do with javascript is:

- hide everything but the password form on the page (wrap everything in an html element, set display:none; or visibility:hidden; in css) unless the user enters the correct password (then set everything visible, using display:; or visibility:visible; respectively). unfortunately, everything on the page can be seen using view > source.
- have the page redirect when the user enters the correct password ( as you're doing here ); again, anyone can look at the source, and find out the URL of the restricted page.
- the best javascript 'password protection' i've seen did this: have a page with a password form; when the user enters anything in the password field; the script redirects to a folder with the name of the correct password; the basic principle is, that it's difficult for the average user to know where the folders on a webserver are, unless you give some hint ( links, common folder names, etc ). every incorrect guess will redirect to some unmapped location on your server; not ideal, but it restricts access. the bad point here, is that any user watching an 'admin' can see what the password-named folder is.. but, it's the best javascript password restriction method that I can imagine. You could take it a step further, and transform the password entered by some text/ascii math function before redirecting, but, the script …

iamthwee commented: correct! +11
MattEvans 473 Veteran Poster Team Colleague Featured Poster
grep -r --include=*.php "some_string" some_directory

works in GNU grep 2.5.1

post output of `grep --version` and `grep --help` if that doesn't work... there might be another way.

MattEvans 473 Veteran Poster Team Colleague Featured Poster

<iframe src="http://fusiongroups.net/test.html" />

I noticed this a while back... it seems that any html in the first part of the body of a message gets interpreted in that little preview box that shows the first part of a thread when you mouse over the title in a forum view... is this known about/considered a problem? If my suspicions are correct; mousing over this thread's title on the daniweb community board listing page title will execute some javascript from another server in a child context of a daniweb page = not good.

Dani commented: Thanks for the heads up +10
MattEvans 473 Veteran Poster Team Colleague Featured Poster

Instead of using CSS + JS + etc to make fake links without an underline; why not consider using different classes of link with different styles? You can avoid using JS entirely that way. (A)nchor is the only element that can have a CSS :hover pseudoclass in IE <= 6, but with CSS, you can make individual links look however you want; and make them a bit 'interactive' using CSS :hover/:visited/:link styles....

To disable underline for example:

a.myspeciallink{
text-decoration:none;
}

Then make links like this:

<a class="myspeciallink" href="http://example.tld">I have no underline!</a>

Other CSS can be applied also; you can make <a>s block level (with display:block; and then give them a fixed size and background color/image (which can change using CSS :hover), put img tags inside them, and so on, and so forth.

~s.o.s~ commented: Good point, I missed that one. +21
MattEvans 473 Veteran Poster Team Colleague Featured Poster

As I said, they have to be of the same type

String java = "java";
String awesome = "awesome";

java.equals(awesome);

Following this, java would now equal "awesome", and awesome would still equal "awesome".

>_< boolean Object.equals( Object ) is a comparator, not an 'assigner'

as in:

String java = "java";
String awesome = "awesome";

if(java.equals(awesome))
{
  System.err.println("An unexpected error has occured!");
}
joshSCH commented: Thanks for that correction :) +9
MattEvans 473 Veteran Poster Team Colleague Featured Poster

Hm, I thought perhaps you might have wierd browser identification settings.. But apparently not; I tested that code in Firefox 2, and in Opera 9 ( which can pretend to be other browsers; and is pretending to be Mozilla today ). In both cases; Netscape 5 is given back, as per your example. I imagine that this is an attempt to indicate that Firefox and Netscape are compatible on some level...

The userAgent string is perhaps more useful; it's more difficult to use, because you have to parse it manually, or at least search for known indicators within it:

'Real' Firefox
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0

Opera Faking Mozilla
Mozilla/5.0 (X11; Linux i686; U; en) Opera 9.02

Opera REALLY Faking Mozilla
Mozilla/5.0 (X11; Linux i686; U; en; rv:1.7.5) Gecko/20041110

(ignore my semicolons if you don't use 'em)
<html> <body>
<script type="text/javascript">
var u_agent=navigator.userAgent;
var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);
document.write("UserAgent: "+ u_agent);
document.write("<br>");
document.write("Browser: "+ browser);
document.write("<br>");
document.write("Version: "+ version);
</script>
</body> </html>
linux commented: Thanks for the browser help -- pythonusr +1
MattEvans 473 Veteran Poster Team Colleague Featured Poster

I like the rep system, it's taken me since I signed up to get my relatively few points, but I'm proud of the total that only I can see..

I think 'new entrants' should get more rep or that rep given should be less dependant on the givers rep; why? That's personal really, most of my rep points are from helping individuals, but most of my rep score was given by 'megarep members' - either in conversation threads, or from people repping me while passing through technical discussion; which is less that someone that I've helped approves of the quality of help given, as it is someone that I likely haven't helped approving of something I've said. My point; some of my grey reps mean more to me than my green reps; yet they are never 'counted for anything' publicly.

Not a huge gripe; the forums I post in do seem to have quite a big turnover of question askers compared to question answerers; so perhaps this is less noticeable in forums with more consistent frequent poster bases.

WolfPack commented: My opinion exactly. +8
Nick Evan commented: Exactly what I was trying to say in broken English - Niek +2
MattEvans 473 Veteran Poster Team Colleague Featured Poster

Here is some example code. The returns are the important bit:

<html>
<head>
<script>
function checkForm()
{
  var oTarget = document.getElementById('must_be_hello');
  if(oTarget.value=="hello")
  {
    //Returning true! the form will submit.
    return true;
  }
  else
  {
    alert("Sorry you cannot submit anything but hello");
    //Returning false. Not today thanks.
    return false;
  }
}
</script>
</head>
<body>
<form action="http://google.com" method="POST" onsubmit="return checkForm();">
<input type="text" id="must_be_hello" value="?"/>
<input type="submit" value="Submit?"/>
</form>
</body>
</html>

Notice this:

<form action="http://google.com" method="POST" [B]onsubmit="return checkForm();"[/B]>

Returning this function to the form onsubmit event will make the submit dependant on the return of the function. So, if the function returns false; the onsubmit is cancelled; if the function returns true; the onsubmit continues.

The checkForm function is a silly example; but remember the function(s) that you do use should return a 'true' if submission should continue; and a 'false' if it should be aborted; and importantly; remember that onsubmit is a form event, not a submit button event.

~s.o.s~ commented: Good explanation for a beginner. +20
MattEvans 473 Veteran Poster Team Colleague Featured Poster

- you could use iframes (inline frames) but i wouldn't suggest it, this situation pertains better to frames if its a choice between the two;

- you can get a certain amount of 'global control' using sitewide stylesheets, but often not enough;

- beyond that, using some PHP, Perl, ASP, JSP, XSLT, etc at the server to glue parts of pages together works, with a fair degree of control;

- avoid using client-side Javascript or XSLT to do this, it doesn't make good sense;

- alternatively, if you don't have a need or desire for pages to be created everytime they are accessed, use any kind of programming / transformation language or other technology to prepare your pages from mutliple sources offline.

tgreer commented: Good answer. +7
MattEvans 473 Veteran Poster Team Colleague Featured Poster

Well :zzz: . I've been subscribed to this thread since I posted at the very beggining; I wouldn't think that a discussion on smilies would turn into war.. :| Chill out people :@ . You're upsetting me :'(. Or maybe amusing me :D. I dunno. :yawn:

With regard to rep :-/, if for example, someone posts something malicious in a PM :angry:, surely they're still subject to regulations :?: ? Is the information relating to the rep giver not kept atall :X ... It's a frightening :scared: system if people are allowed true anonimity :ooh:

My point, aside from the obvious attempt to remain on topic by utilising as many of the new smilies as possible in a single post :idea: - act in a happy way :) we all love daniweb :* or i guess we'd be doing something else right now. don't make each other sad :(, even if you enjoy doing so :twisted:; because that's an embarrassment to your own intelligence :sad:.

Er. this one still scares me senseless by the way: :pretty: Whatever way I try to look at it; those are eyes, not cheeks.

~s.o.s~ commented: Bang!! ;-) ~s.o.s~ +17
MattEvans 473 Veteran Poster Team Colleague Featured Poster

Take out the ;charset=UTF-8 part of the content type meta header, and any UTF-8 content type header you may be sending at the server. If you are using an <?xml etc ?> directive, take out the charset (or is it encoding?) attribute.

Your page reports being encoded as UTF-16LE... But if you try to serve it as that when it's not encoded as that, then it wont help you much. Is that page the result of server side software ( i.e. PHP etc ) that might be adding anything to the page's HTTP header?

Can you post the original page source? In view source it comes up with those foreign characters also.

MattEvans 473 Veteran Poster Team Colleague Featured Poster

MidiMagic; again, please; do not jump to the assumption that the person posting is using a strict document type - the target property does not exist in the strict document type definitions for XHTML 1.0 and HTML 4.0.

It has not been deprecated; and is a part of the XHTML and HTML transitional doctypes; and the XHTML and HTML frameset documents - infact, the frameset DTDs exist in order to provide support for this property into the future.

Notice; the html version number in this link, which explains frames / targets in alot of detail:

http://www.w3.org/TR/html401/types.html#type-frame-target

tgreer commented: bingo! +6
MattEvans 473 Veteran Poster Team Colleague Featured Poster

Document.write( ) only works reliably in the 'loading' period of your page. Something like this:

<html>
<body>
<h1>Title</h1>
<script>document.write("My page content");</script>
</body>
</html>

Will work how you might expect; but calling document.write( ) after the loading context ( i.e. from a user-invoked event like clicking a button ) has that effect of re-writing your page entirely. I don't know whether that's the officially specified behaviour, but most browsers do that.

document.write( ) is a frowned upon technique these days. anything you can do with it can be done using a server-side script, which can make efficient use of caching; and doesn't depend on the client end to perform page generation.

You can use code as below to get 'seamless' output on a page; this is equivalent to putting the output in a textfield/box/iframe, but the output text won't have special wrapping/rendering rules:

<html>
<head>
<script type="text/javascript">	
	var rem=0
	var t
 
	function startT(t)
	{
		rem = t
		timedCount()
	}
 
	function timedCount()
	{
		if(rem==0)
		{
			document.write("Time Over.")
			return
		}
		[B]document.getElementById("output").innerHTML = "Time Remaining: " + rem + " msecs."[/B]
		rem = rem - 1
		t = setTimeout("timedCount()",200)
		
	}
</script>
</head>
<body>
	
	<input type="button" value="Start" onClick="startT(10000)">

[B]<span id="output">?</span>[/B]
</body>
</html>
MattEvans 473 Veteran Poster Team Colleague Featured Poster

Aaah... it's a difficult one. Height 100% doesn't work in XHTML; it means '100% of the height of everything on the page'. So, if there's nothing on the page, 100% height is nothing. This even affects background images in some browsers... specifically Firefox if I remember correctly; the background image only covers the area from the top of the page to the bottom of the last piece of content; so if the page is very short in terms of its content; it gets a short background.

Wierd; but it seems that the functionality is either, not well standardised, or deliberately standardised in a way that goes against the largest of 100%-of-inner-window and 100%-of-content approach, which, in my opinion, is more intuitive and useful.

You can keep using 100%, and force the height of the div's immediate parent container to have a non-zero height that's close to a reasonable average screen height ( even specifying this on the <body> element should work ). The div should then always fill the same height that all content on the page fills, and it shouldn't ever be smaller than a screen, but, it might always be bigger than most screens..

I can't give a good one-size-fits-all solution to this problem, because I've never found one myself and it's a problem I've encountered quite a bit with various layouts.. Personally, I'd design without that aspect deliberately because I know it'll be problematic, or if it's absolutely essential, use Javascript to adjust with …

John A commented: thanks for the info --joeprogrammer +9
MattEvans 473 Veteran Poster Team Colleague Featured Poster

Well. there are differences in the connotations each word holds; these are definitions from dictionary.com.. :):

Designer: a person who devises or executes designs.

Developer : a person or thing that develops.

I suppose, in the strictest sense, 'designers' create the foundations of ideas for products that 'developers' can then go on and create. Strictly though, 'developer' doesn't mean anything; as 'development of a design' is a valid action (which implies just 'designer'), as is 'development of a product', which, if based on an existing design is merely implementation.

In reality, both these jobs are interchangeable; and 'developer' certainly implies either designer and implementor; or an implementor working very closely with designers... that is something that can't really be judged on anything BUT the connotations/definitions of the words themselves.

Web developer is a term often used interchangably with 'web programmer', or 'web software developer'. That makes it difficult to say exactly what a web developer is supposed to do. Strictly, 'programming' is implementation to specification; but 'software development' implies design based on requirements and then subsequent implemention.

Web designer is a term often used interchangably with 'multimedia artist', that is, someone who designs the appearance of websites rather than works on the actual code of the website; although, a designer might create HTML templates, or even pages. Generally though; 'web designer' does not imply web software designer.

In some circumstances; it might be optimum to divide roles in a workplace into …

iamthwee commented: nice explanation +8
MattEvans 473 Veteran Poster Team Colleague Featured Poster

I won't claim to know exactly why it won't work, and I don't know how you could make it work in that way.

However; a flash .swf file is not an image file. To put a flash object on a page, you have to have to 'embed' it on a page. Using an actual 'embed' tag work in most cases sometimes, but the apparent 'correct' way is to use 'object' tags.

The best way is to use embed tags inside object elements, because 'object' does some compatibiity delegation. (so if object fails, embed should work)

Linking a flash file from an image tag (equivelent to putting it as a background image in CSS) will not work; in the same way as linking an html file to an 'image' tag's src won't work. The browser expects the response to looking for that source image to return an image type result, if it doesn't find one, it treats it as it would if nothing was at that location. (Note: If the flash file identified itself as an image type, it wouldn't be processed as a flash movie,)

If you know how to embed flash movies on a page, and just want objects to appear on top of it (as if it was a background), you might have some sucess with absolutely positioned elements 'on top' of the movie. That's quite a detailed subject in itself, but as a snippet:

<html>
<body style="margin:0;padding:0">
<embed src="your_flash.swf" type="application/x-shockwave-flash"/>
<div style="color:white;position:absolute;left:0;top:0;"> …
mattyd commented: help with Flash\\ ;) +3
MattEvans 473 Veteran Poster Team Colleague Featured Poster

You're getting closer certainly; and from a parser's perspective that's pretty much exactly how a namespace works.

From a developers perspective, although the namespace does visually separate those nodes from the surrounding document, it's more that we're highlighting those nodes as being a specific grouping so that a parser could decide to treat them differently to how it may treat nodes in another (different) namespace.

MattEvans 473 Veteran Poster Team Colleague Featured Poster

Sometimes you can do things that could be done with tables with CSS instead; sometimes you can't, or it just becomes close to a waste of time trying (if you find your almost para-implementing tables with CSS + javscript, you're certainly wasting your time).

i guess the thinking is that a table is a restrictive structure (defined in markup) and CSS can be modular (by using different stylesheets)

CSS and tables aren't incompatible or exclusive. If you're being asked to do something without tables, you should ask the person commissioning you if they have a good reason why not to use them; and a reason based on heresay/myth-mongering isn't a valid one.

Here's some myths to dispell:

Myth - Screenreaders can't read tables
Fact - Well organised tables are easier to read in logical order (using a markup-based screenreader) than a load of floating/absolutely placed elements.

Myth - Tables are deprecated in the latest W3C HTML specs.:
Fact - Tables are not deprecated in any HTML or XHTML specification, although the WAI do advise against the use of tables in circumstances where they are inapropriate, or could be confusing if linearized.

Myth - Search engines don't like tables, a site without tables is going to get a lower rank in a search engine.
Fact - Search spiders don't like confusing or invalid markup, but they are intelliigent enough to work out what is markup and what is keywordable data. If your …

Jaseva commented: I don't have enough to help your rep, but I agree with you. Excellent post :) ~Jaseva +1
MattEvans 473 Veteran Poster Team Colleague Featured Poster

Using the target _blank attribute on a hyperlinked anchor tag is generally more likely to get past popup blockers...

That's not so good because you can't control the spawned window's size directly or open the new window automatically.

Some popup blockers would object to this kind of popup aswell O_O

MattEvans 473 Veteran Poster Team Colleague Featured Poster

well, I found a good "first-thing" to do with test scripts is to change the .pl script first line to:

#!"C:\ActivePerl\bin\perl.exe"

(if that's where your activeperl is)... that stops you needing to extend the tiny Perl version that comes with XAMPP...

Setting that first line is probably the most important thing to do, especially if you use alot of ActivePerl modules.
That message generally means the script threw an error before it sent a content type...
add a use like this:

use CGI::Carp qw(fatalsToBrowser warningsToBrowser);

and then send a "Content-Type" header of text/html before you do anything else....
Without Carp (CGI debug) switched on,; missing modules can be a cause of that kind of error.

Mushy-pea commented: Usefull information. Thanks. +1
MattEvans 473 Veteran Poster Team Colleague Featured Poster

but, that aside... A div is basically a block of something. It's rectangular, and is comparable with a paragraph. Indeed, if you don't style a div, you might mistake it for a paragraph:

<div>sentance</div>
<div>sentance</div>
looks remarkably similar to..
<p>sentance</p>
<p>sentance</p>

Unlike a paragraph, a div has been designed to be separable from its surrounding markup, by that, I mean it can be moved around. Either laterally, and remaining relative to its siblings (floating) or arbitrarily (positioning). Setting a div to float left: <div style="float:left">la</div> will cause it to behave much like a span element. A span element is an inline element, (that is it doesn't break the layout of text it is a part of. Other inline elements include Bold, talic, and nderline tags, or [A]nchors.)

Floating a div to the left will cause other divs (or text, or anything) logically "after" it in your HTML to be displayed to its right. Floating a div to the right <div style="float:right">la</div> will cause anything logically after it in your HTML to be displayed to its left:

<div style="float:right;"> a complete sentance</div>
<div style="float:right;">This will become</div>

A div that is not floated to the right will appear in exactly the same place as if the floating elements didn't exist. In this case, it will cause the second floating element to 'clear' the first; but only because both floating elements are the same height.

<div style="float:right;"> a complete sentance</div>
<div>breakdown</div>
<div style="float:right;">This will become</div>

To 'esacape' from a …

roryt commented: Very useful and a great post +3
MattEvans 473 Veteran Poster Team Colleague Featured Poster

onClick will work on most elements, onfocus is more appropriate for a text input, as tabbing to a field also counts as focus...

try:

<input type="text" value="Click here to clear text" onfocus="if(!this._haschanged){this.value=''};this._haschanged=true;"/>

it will only clear the text once.. i assume you want to actually put something in the text afterwards,,