• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

QNAN

Members
  • Content count

    45
  • Joined

  • Last visited

Community Reputation

232 Neutral

About QNAN

  • Rank
    Member
  1. Thanks for the reply. It helped alot.
  2. I have an enum, which I would like to call a function on to change its value. The enum is called "Direction" (North/South/East/West), and I want to make an extension method called "TurnLeft()", which will change the value of the enum itself.   Example: Direction l_direction = Direction.N; l_direction.TurnLeft()                                      // value should become Direction.W   Unfortunately it seems that the standard way of implementing an extension method can not change the value of the enum itself. I had hoped that the "this" keyword could have done it, believing it would implicitly work like "ref", but no. And it is not possible to use both "this" and "ref" for the same argument. Is there any way to accomplish this? This is what I have: public enum Direction { N = 0, E, S, W, } public static class DirectionFunction { public static void TurnLeft(this Direction a_direction) { switch(a_direction) { case Direction.N: a_direction = Direction.W; return; case Direction.W: a_direction = Direction.S; return; case Direction.S: a_direction = Direction.E; return; case Direction.E: a_direction = Direction.N; return; } } }
  3. EDIT: Thanks, it was something like this I needed Your code makes sure, that values are included right away. Can't believe what a mess I ventured into with the other code (which I took over from a far-range fadeout of instancing with too little tthought).   Just for the record, the final shader code will look like this: float l_dissolvemap_result = tex2D(g_dissolvemap_sampler, a_texcoord0).r; if(g_alpha < l_dissolvemap_result) discard; l_final_color.a = l_original_alpha; In this way alpha-testing (or alpha-to-coverage, which is very similar, just with nicer edges and antialiasing) will still work for the original alpha of the object texture, as the g_alpha is not factored in.
  4. Im working on instancing and would like to allow the instancing area (the area holding all instances) to change LoD, if the player moves closer/further away.   Since alpha blending is a no-go with instancing as it is impossible to sort render order with them, I have experimented with alpha testing and dissolvemap.   My problem so far is, that the dissolving matches up pretty bad across the fading time. Last test I tried with this calculation on the shader: l_final_color.a = l_original_alpha * saturate(g_alpha * (0.5f + tex2D(g_dissolvemap_sampler, a_texcoord0).r))   g_alpha is the fading over time (will be 0.1 at 10% of the time etc). The dissolvemap, which is a noisemap with values distributed across the 0-1 spectrum. Alpha test will succeed when value is above 0.5. I offset it with 0.5 to get the median values to fade in at around 0.5. If I do not use this offset, the first values (those that are 1.0 on the dissolvemap) will first start trickling in at 0.5. By offsetting it, I can get them to fade in at 0.333~. Which is also quite late...   To close the 0.333~ gap, I offset the g_alpha by 0.333~ from the main program, while scaling the timing by 0.666~, effectively removing the start gap while keeping the timing intact.   Anyway, the fading kinda works, but the bulk of the fading takes place in a too short time span. I have watched it up-close and it does fade over the entire time, but the beginning kinda trickles in and is not noticable from afar, and similar with the ending, making both beginning and ending not noticable. The result is a fast fade, that looks too much like a pop.   So my questions are: - Is it possible to make a better distribution equation for the final color? (I have tried with exponentials but couldn't arrive at anything satisfactory) - Can the problem be the dissolvemap? (IMO it looks fairly evenly distributed, I attached it (original is in .bmp, I saved as .jpg to save space here)   Is there alternatives to this approach?
  5. I have dug a bit deeper, and I think I have some new information. The values for the inverse matrix is calculated in the loading. The values are in quaternion+position form. From that a matrix is built, and then the matrix is set to its inverse. The SetInverse()-method does math on all members, including _44, and this math may have skewed the value slightly.   I tested by running the D3DXMatrixInverse() method instead, just to see if it did it better, but it didn't. Although the problem was opposite: _44 was slightly higher than 1.0f, not slightly lower as with my method.   Anyway, it must be my loading thread (Im using boost::thread) that creates a slightly different result compared to the main thread. Taking Hodgman's post into consideration, is it likely that the loading thread was created with different values than the main, and that is what alters the result?   I need to guard against floating point errors in any case, so it was good to catch this one (who knows what hardware the program is going to run on anyway?). Still, I like to understand what went wrong.
  6. phil_t: I guess I was a bit imprecise in my expression. The memory is shared, so me talking about "transferring" doesn't make sense, you are right about that. So I guess the question would have to be rephrased to something like if there can be a difference how threads load.
  7. The thing is just, that the change in value was so extremely subtle. The value still showed as 1.0000 in both file output as well as in my VS-environment.   I have created my own framework for thread loading and I use that framework everywhere, loading many different kinds of assets, and never have I encountered a problem. I will look through my program again, but I don't think it is a syncronization problem, as I have been quite aggressive in protecting with mutexes. And as I said, since this is done standardized (a baseclass takes care of it across all my loaders), I believe I would have encountered the problem before.   Right now there is only one class that asks for the resource, and once asked, it will have to sit there and wait until the library gets back to it. This means, that all communication takes place between the library and the thread, where the library plays a passive role, until the thread delivers the asset. The library will run on the CPU when it delivers the asset, so no outsiders need to think about syncing.   I will have another look at my structure and see if I can find anything. Thanks for the input so far.
  8. I had one of the worst debugging sessions In my life.   I am currently working on animations, and wanting optimal performance, I shifted loading multithreaded. When I shifted my refpose to loading multithreaded, however, something wierd happened. Suddenly my animated model collapsed after a few animations cycles and was completely distorted. I tried to change back to non-multithreaded, and there was no error. Then I wrote out everything to files: Animations, boneweights, animationpose, refpose - everything. And I could see no difference between the multithreaded and the non-multithreaded.   After a long time of digging down to isolate the problem, I finally found out, that the bones of final pose, which are in matrix form, had its members _44 distorted. Since all the math takes place with quaternion+position, except an inverse-value that I have pre-calculated on each refpose-bone, the final bone-matrices would never have their members _44 overwritten through the animation, except when the inverse-matrix of the refpose would be continously multiplying with it, slowly skewing it.   I could solve this by resetting the final bones every iteration before using them, but I found it a bit unsatisfactory, that I would even have to do that, because it works fine when loading single-threaded. Another solution was to set all the _44-values in the main thread once it gets delivered from the loading-thread.    - is it a normal problem, that floats created on one thread lose accuracy when transferred to another?  - should I reset the finalbones-matrices from iteration to iteration no matter what? Is it too unsafe to rely on a 100% good float?   PS: This debugging session must have taken me some 20 hours in all, what a nightmare.
  9. I solved it. I forgot to change the indices of the triangles.
  10. The ODE demos run with the Z-axis as being up/down. I have tried to change this to work with my system, where Y-axis is up/down.   I got it to work with a heightfield. Unfortunately, there is an unfixed bug in the heightfield, so it will fail in certain areas. The solution is to use a tri-mesh.   So I took a look at the trimesh-demo to learn how to convert my heightmap data to an ODE trimesh. After failing again and again, I finally went to the root and tried to convert the ODE trimesh itself to use a gravity vector of -Y instead of -Z as it has now, while at the same time changing the trimesh to the new orientation. I believe I have translated everything correctly, but the demo still fails, and behaves quite like the test in my own program.   I will write the entire file here. Search for "Y-Conversion" to find the areas I changed from the original. The original can be seen commented out at the bottom. The easiest would probably be to substitute this one with the original while testing, if you have the ODE system installed.   Is ODE only working with Z-axis or did I miss something in conversion?   Here is the code (I couldn't attach a .cpp?) /************************************************************************* * * * Open Dynamics Engine, Copyright (C) 2001-2003 Russell L. Smith. * * All rights reserved. Email: russ@q12.org Web: www.q12.org * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of EITHER: * * (1) The GNU Lesser General Public License as published by the Free * * Software Foundation; either version 2.1 of the License, or (at * * your option) any later version. The text of the GNU Lesser * * General Public License is included with this library in the * * file LICENSE.TXT. * * (2) The BSD-style license that is included with this library in * * the file LICENSE-BSD.TXT. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files * * LICENSE.TXT and LICENSE-BSD.TXT for more details. * * * *************************************************************************/ // TriMesh test by Erwin de Vries #include <ode/ode.h> #include <drawstuff/drawstuff.h> #include "texturepath.h" #ifdef _MSC_VER #pragma warning(disable:4244 4305) // for VC++, no precision loss complaints #endif // select correct drawing functions #ifdef dDOUBLE #define dsDrawBox dsDrawBoxD #define dsDrawSphere dsDrawSphereD #define dsDrawCylinder dsDrawCylinderD #define dsDrawCapsule dsDrawCapsuleD #define dsDrawLine dsDrawLineD #define dsDrawTriangle dsDrawTriangleD #endif // some constants #define NUM 200 // max number of objects #define DENSITY (5.0) // density of all objects #define GPB 3 // maximum number of geometries per body #define MAX_CONTACTS 40 // maximum number of contact points per body // dynamics and collision objects struct MyObject { dBodyID body; // the body dGeomID geom[GPB]; // geometries representing this body }; static int num=0; // number of objects in simulation static int nextobj=0; // next object to recycle if num==NUM static dWorldID world; static dSpaceID space; static MyObject obj[NUM]; static dJointGroupID contactgroup; static int selected = -1; // selected object static int show_aabb = 0; // show geom AABBs? static int show_contacts = 0; // show contact points? static int random_pos = 1; // drop objects from random position? #define VertexCount 5 #define IndexCount 12 static dVector3 Size; static float Vertices[VertexCount][3]; static dTriIndex Indices[IndexCount]; static dGeomID TriMesh; static dGeomID Ray; // this is called by dSpaceCollide when two objects in space are // potentially colliding. static void nearCallback (void *data, dGeomID o1, dGeomID o2) { int i; // if (o1->body && o2->body) return; // exit without doing anything if the two bodies are connected by a joint dBodyID b1 = dGeomGetBody(o1); dBodyID b2 = dGeomGetBody(o2); if (b1 && b2 && dAreConnectedExcluding (b1,b2,dJointTypeContact)) return; dContact contact[MAX_CONTACTS]; // up to MAX_CONTACTS contacts per box-box for (i=0; i<MAX_CONTACTS; i++) { contact[i].surface.mode = dContactBounce | dContactSoftCFM; contact[i].surface.mu = dInfinity; contact[i].surface.mu2 = 0; contact[i].surface.bounce = 0.1; contact[i].surface.bounce_vel = 0.1; contact[i].surface.soft_cfm = 0.01; } if (int numc = dCollide (o1,o2,MAX_CONTACTS,&contact[0].geom, sizeof(dContact))) { dMatrix3 RI; dRSetIdentity (RI); const dReal ss[3] = {0.02,0.02,0.02}; for (i=0; i<numc; i++) { if (dGeomGetClass(o1) == dRayClass || dGeomGetClass(o2) == dRayClass){ dMatrix3 Rotation; dRSetIdentity(Rotation); dsDrawSphere(contact[i].geom.pos, Rotation, REAL(0.01)); dVector3 End; End[0] = contact[i].geom.pos[0] + (contact[i].geom.normal[0] * contact[i].geom.depth); End[1] = contact[i].geom.pos[1] + (contact[i].geom.normal[1] * contact[i].geom.depth); End[2] = contact[i].geom.pos[2] + (contact[i].geom.normal[2] * contact[i].geom.depth); End[3] = contact[i].geom.pos[3] + (contact[i].geom.normal[3] * contact[i].geom.depth); dsDrawLine(contact[i].geom.pos, End); continue; } dJointID c = dJointCreateContact (world,contactgroup,contact+i); dJointAttach (c,b1,b2); if (show_contacts) dsDrawBox (contact[i].geom.pos,RI,ss); } } } // start simulation - set viewpoint static void start() { dAllocateODEDataForThread(dAllocateMaskAll); static float xyz[3] = {2.1640f,-1.3079f,1.7600f}; static float hpr[3] = {125.5000f,-17.0000f,0.0000f}; dsSetViewpoint (xyz,hpr); printf ("To drop another object, press:\n"); printf (" b for box.\n"); printf (" s for sphere.\n"); printf (" c for cylinder.\n"); printf (" x for a composite object.\n"); printf ("To select an object, press space.\n"); printf ("To disable the selected object, press d.\n"); printf ("To enable the selected object, press e.\n"); printf ("To toggle showing the geom AABBs, press a.\n"); printf ("To toggle showing the contact points, press t.\n"); printf ("To toggle dropping from random position/orientation, press r.\n"); } char locase (char c) { if (c >= 'A' && c <= 'Z') return c - ('a'-'A'); else return c; } // called when a key pressed static void command (int cmd) { int i,j,k; dReal sides[3]; dMass m; cmd = locase (cmd); if (cmd == 'b' || cmd == 's' || cmd == 'c' || cmd == 'x' /* || cmd == 'l' */) { if (num < NUM) { i = num; num++; } else { i = nextobj; nextobj++; if (nextobj >= num) nextobj = 0; // destroy the body and geoms for slot i dBodyDestroy (obj[i].body); for (k=0; k < GPB; k++) { if (obj[i].geom[k]) dGeomDestroy (obj[i].geom[k]); } memset (&obj[i],0,sizeof(obj[i])); } obj[i].body = dBodyCreate (world); for (k=0; k<3; k++) sides[k] = dRandReal()*0.5+0.1; dMatrix3 R; if (random_pos) { // ************************************************************************ // Y-Conversion // ************************************************************************ dBodySetPosition (obj[i].body, 1,10,2); // ************************************************************************ /* dBodySetPosition (obj[i].body, dRandReal()*2-1,dRandReal()*2-1,dRandReal()+1); */ dRFromAxisAndAngle (R,dRandReal()*2.0-1.0,dRandReal()*2.0-1.0, dRandReal()*2.0-1.0,dRandReal()*10.0-5.0); } else { dReal maxheight = 0; for (k=0; k<num; k++) { const dReal *pos = dBodyGetPosition (obj[k].body); if (pos[2] > maxheight) maxheight = pos[2]; } dBodySetPosition (obj[i].body, 0,0,maxheight+1); dRFromAxisAndAngle (R,0,0,1,dRandReal()*10.0-5.0); } dBodySetRotation (obj[i].body,R); dBodySetData (obj[i].body,(void*)(size_t)i); if (cmd == 'b') { dMassSetBox (&m,DENSITY,sides[0],sides[1],sides[2]); obj[i].geom[0] = dCreateBox (space,sides[0],sides[1],sides[2]); } else if (cmd == 'c') { sides[0] *= 0.5; dMassSetCapsule (&m,DENSITY,3,sides[0],sides[1]); obj[i].geom[0] = dCreateCapsule (space,sides[0],sides[1]); } /* // cylinder option not yet implemented else if (cmd == 'l') { sides[1] *= 0.5; dMassSetCapsule (&m,DENSITY,3,sides[0],sides[1]); obj[i].geom[0] = dCreateCylinder (space,sides[0],sides[1]); } */ else if (cmd == 's') { sides[0] *= 0.5; dMassSetSphere (&m,DENSITY,sides[0]); obj[i].geom[0] = dCreateSphere (space,sides[0]); } else if (cmd == 'x') { dGeomID g2[GPB]; // encapsulated geometries dReal dpos[GPB][3]; // delta-positions for encapsulated geometries // start accumulating masses for the encapsulated geometries dMass m2; dMassSetZero (&m); // set random delta positions for (j=0; j<GPB; j++) { for (k=0; k<3; k++) dpos[j][k] = dRandReal()*0.3-0.15; } for (k=0; k<GPB; k++) { obj[i].geom[k] = dCreateGeomTransform (space); dGeomTransformSetCleanup (obj[i].geom[k],1); if (k==0) { dReal radius = dRandReal()*0.25+0.05; g2[k] = dCreateSphere (0,radius); dMassSetSphere (&m2,DENSITY,radius); } else if (k==1) { g2[k] = dCreateBox (0,sides[0],sides[1],sides[2]); dMassSetBox (&m2,DENSITY,sides[0],sides[1],sides[2]); } else { dReal radius = dRandReal()*0.1+0.05; dReal length = dRandReal()*1.0+0.1; g2[k] = dCreateCapsule (0,radius,length); dMassSetCapsule (&m2,DENSITY,3,radius,length); } dGeomTransformSetGeom (obj[i].geom[k],g2[k]); // set the transformation (adjust the mass too) dGeomSetPosition (g2[k],dpos[k][0],dpos[k][1],dpos[k][2]); dMassTranslate (&m2,dpos[k][0],dpos[k][1],dpos[k][2]); dMatrix3 Rtx; dRFromAxisAndAngle (Rtx,dRandReal()*2.0-1.0,dRandReal()*2.0-1.0, dRandReal()*2.0-1.0,dRandReal()*10.0-5.0); dGeomSetRotation (g2[k],Rtx); dMassRotate (&m2,Rtx); // add to the total mass dMassAdd (&m,&m2); } // move all encapsulated objects so that the center of mass is (0,0,0) for (k=0; k<2; k++) { dGeomSetPosition (g2[k], dpos[k][0]-m.c[0], dpos[k][1]-m.c[1], dpos[k][2]-m.c[2]); } dMassTranslate (&m,-m.c[0],-m.c[1],-m.c[2]); } for (k=0; k < GPB; k++) { if (obj[i].geom[k]) dGeomSetBody (obj[i].geom[k],obj[i].body); } dBodySetMass (obj[i].body,&m); } if (cmd == ' ') { selected++; if (selected >= num) selected = 0; if (selected < 0) selected = 0; } else if (cmd == 'd' && selected >= 0 && selected < num) { dBodyDisable (obj[selected].body); } else if (cmd == 'e' && selected >= 0 && selected < num) { dBodyEnable (obj[selected].body); } else if (cmd == 'a') { show_aabb ^= 1; } else if (cmd == 't') { show_contacts ^= 1; } else if (cmd == 'r') { random_pos ^= 1; } } // draw a geom void drawGeom (dGeomID g, const dReal *pos, const dReal *R, int show_aabb) { if (!g) return; if (!pos) pos = dGeomGetPosition (g); if (!R) R = dGeomGetRotation (g); int type = dGeomGetClass (g); if (type == dBoxClass) { dVector3 sides; dGeomBoxGetLengths (g,sides); dsDrawBox (pos,R,sides); } else if (type == dSphereClass) { dsDrawSphere (pos,R,dGeomSphereGetRadius (g)); } else if (type == dCapsuleClass) { dReal radius,length; dGeomCapsuleGetParams (g,&radius,&length); dsDrawCapsule (pos,R,length,radius); } /* // cylinder option not yet implemented else if (type == dCylinderClass) { dReal radius,length; dGeomCylinderGetParams (g,&radius,&length); dsDrawCylinder (pos,R,length,radius); } */ else if (type == dGeomTransformClass) { dGeomID g2 = dGeomTransformGetGeom (g); const dReal *pos2 = dGeomGetPosition (g2); const dReal *R2 = dGeomGetRotation (g2); dVector3 actual_pos; dMatrix3 actual_R; dMultiply0_331 (actual_pos,R,pos2); actual_pos[0] += pos[0]; actual_pos[1] += pos[1]; actual_pos[2] += pos[2]; dMultiply0_333 (actual_R,R,R2); drawGeom (g2,actual_pos,actual_R,0); } if (show_aabb) { // draw the bounding box for this geom dReal aabb[6]; dGeomGetAABB (g,aabb); dVector3 bbpos; for (int i=0; i<3; i++) bbpos[i] = 0.5*(aabb[i*2] + aabb[i*2+1]); dVector3 bbsides; for (int j=0; j<3; j++) bbsides[j] = aabb[j*2+1] - aabb[j*2]; dMatrix3 RI; dRSetIdentity (RI); dsSetColorAlpha (1,0,0,0.5); dsDrawBox (bbpos,RI,bbsides); } } // simulation loop static void simLoop (int pause) { for(int i = 0; i < 3000000; i++) int dd = 0; dsSetColor (0,0,2); dSpaceCollide (space,0,&nearCallback); if (!pause) dWorldStep (world,0.05); //if (!pause) dWorldStepFast (world,0.05, 1); // remove all contact joints dJointGroupEmpty (contactgroup); dsSetColor (1,1,0); dsSetTexture (DS_WOOD); for (int i=0; i<num; i++) { for (int j=0; j < GPB; j++) { if (i==selected) { dsSetColor (0,0.7,1); } else if (! dBodyIsEnabled (obj[i].body)) { dsSetColor (1,0,0); } else { dsSetColor (1,1,0); } drawGeom (obj[i].geom[j],0,0,show_aabb); } } /*{ for (int i = 1; i < IndexCount; i++) { dsDrawLine(Vertices[Indices[i - 1]], Vertices[Indices[i]]); } }*/ {const dReal* Pos = dGeomGetPosition(TriMesh); const dReal* Rot = dGeomGetRotation(TriMesh); {for (int i = 0; i < IndexCount / 3; i++){ const float *p = Vertices[Indices[i * 3 + 0]]; const dVector3 v0 = { p[0], p[1], p[2] }; p = Vertices[Indices[i * 3 + 1]]; const dVector3 v1 = { p[0], p[1], p[2] }; p = Vertices[Indices[i * 3 + 2]]; const dVector3 v2 = { p[0], p[1], p[2] }; dsDrawTriangle(Pos, Rot, v0, v1, v2, 0); }}} if (Ray){ dVector3 Origin, Direction; dGeomRayGet(Ray, Origin, Direction); dReal Length = dGeomRayGetLength(Ray); dVector3 End; End[0] = Origin[0] + (Direction[0] * Length); End[1] = Origin[1] + (Direction[1] * Length); End[2] = Origin[2] + (Direction[2] * Length); End[3] = Origin[3] + (Direction[3] * Length); dsDrawLine(Origin, End); } } int main (int argc, char **argv) { // setup pointers to drawstuff callback functions dsFunctions fn; fn.version = DS_VERSION; fn.start = &start; fn.step = &simLoop; fn.command = &command; fn.stop = 0; fn.path_to_textures = DRAWSTUFF_TEXTURE_PATH; // create world dInitODE2(0); world = dWorldCreate(); space = dSimpleSpaceCreate(0); contactgroup = dJointGroupCreate (0); // ************************************************************************ // Y-Conversion // ************************************************************************ dWorldSetGravity (world,0,-0.5,0); // ************************************************************************ dWorldSetCFM (world,1e-5); //dCreatePlane (space,0,0,1,0); memset (obj,0,sizeof(obj)); // ************************************************************************ // Y-Conversion // ************************************************************************ Size[0] = 5.0f; Size[1] = 5.0f; Size[2] = 2.5f; Vertices[0][0] = -Size[0]; Vertices[0][1] = Size[2]; Vertices[0][2] = -Size[1]; Vertices[1][0] = Size[0]; Vertices[1][1] = Size[2]; Vertices[1][2] = -Size[1]; Vertices[2][0] = Size[0]; Vertices[2][1] = Size[2]; Vertices[2][2] = Size[1]; Vertices[3][0] = -Size[0]; Vertices[3][1] = Size[2]; Vertices[3][2] = Size[1]; Vertices[4][0] = 0; Vertices[4][1] = 0; Vertices[4][2] = 0; Indices[0] = 0; Indices[1] = 1; Indices[2] = 4; Indices[3] = 1; Indices[4] = 2; Indices[5] = 4; Indices[6] = 2; Indices[7] = 3; Indices[8] = 4; Indices[9] = 3; Indices[10] = 0; Indices[11] = 4; // ************************************************************************ dTriMeshDataID Data = dGeomTriMeshDataCreate(); //dGeomTriMeshDataBuildSimple(Data, (dReal*)Vertices, VertexCount, Indices, IndexCount); dGeomTriMeshDataBuildSingle(Data, Vertices[0], 3 * sizeof(float), VertexCount, &Indices[0], IndexCount, 3 * sizeof(dTriIndex)); TriMesh = dCreateTriMesh(space, Data, 0, 0, 0); //dGeomSetPosition(TriMesh, 0, 0, 1.0); Ray = dCreateRay(space, 0.9); dVector3 Origin, Direction; Origin[0] = 0.0; Origin[1] = 0; Origin[2] = 0.5; Origin[3] = 0; Direction[0] = 0; Direction[1] = 1.1f; Direction[2] = -1; Direction[3] = 0; dNormalize3(Direction); dGeomRaySet(Ray, Origin[0], Origin[1], Origin[2], Direction[0], Direction[1], Direction[2]); // run simulation dsSimulationLoop (argc,argv,352,288,&fn); dJointGroupDestroy (contactgroup); dSpaceDestroy (space); dWorldDestroy (world); dCloseODE(); return 0; } /* // TriMesh test by Erwin de Vries #include <ode/ode.h> #include <drawstuff/drawstuff.h> #include "texturepath.h" #ifdef _MSC_VER #pragma warning(disable:4244 4305) // for VC++, no precision loss complaints #endif // select correct drawing functions #ifdef dDOUBLE #define dsDrawBox dsDrawBoxD #define dsDrawSphere dsDrawSphereD #define dsDrawCylinder dsDrawCylinderD #define dsDrawCapsule dsDrawCapsuleD #define dsDrawLine dsDrawLineD #define dsDrawTriangle dsDrawTriangleD #endif // some constants #define NUM 200 // max number of objects #define DENSITY (5.0) // density of all objects #define GPB 3 // maximum number of geometries per body #define MAX_CONTACTS 40 // maximum number of contact points per body // dynamics and collision objects struct MyObject { dBodyID body; // the body dGeomID geom[GPB]; // geometries representing this body }; static int num=0; // number of objects in simulation static int nextobj=0; // next object to recycle if num==NUM static dWorldID world; static dSpaceID space; static MyObject obj[NUM]; static dJointGroupID contactgroup; static int selected = -1; // selected object static int show_aabb = 0; // show geom AABBs? static int show_contacts = 0; // show contact points? static int random_pos = 1; // drop objects from random position? #define VertexCount 5 #define IndexCount 12 static dVector3 Size; static float Vertices[VertexCount][3]; static dTriIndex Indices[IndexCount]; static dGeomID TriMesh; static dGeomID Ray; // this is called by dSpaceCollide when two objects in space are // potentially colliding. static void nearCallback (void *data, dGeomID o1, dGeomID o2) { int i; // if (o1->body && o2->body) return; // exit without doing anything if the two bodies are connected by a joint dBodyID b1 = dGeomGetBody(o1); dBodyID b2 = dGeomGetBody(o2); if (b1 && b2 && dAreConnectedExcluding (b1,b2,dJointTypeContact)) return; dContact contact[MAX_CONTACTS]; // up to MAX_CONTACTS contacts per box-box for (i=0; i<MAX_CONTACTS; i++) { contact[i].surface.mode = dContactBounce | dContactSoftCFM; contact[i].surface.mu = dInfinity; contact[i].surface.mu2 = 0; contact[i].surface.bounce = 0.1; contact[i].surface.bounce_vel = 0.1; contact[i].surface.soft_cfm = 0.01; } if (int numc = dCollide (o1,o2,MAX_CONTACTS,&contact[0].geom, sizeof(dContact))) { dMatrix3 RI; dRSetIdentity (RI); const dReal ss[3] = {0.02,0.02,0.02}; for (i=0; i<numc; i++) { if (dGeomGetClass(o1) == dRayClass || dGeomGetClass(o2) == dRayClass){ dMatrix3 Rotation; dRSetIdentity(Rotation); dsDrawSphere(contact[i].geom.pos, Rotation, REAL(0.01)); dVector3 End; End[0] = contact[i].geom.pos[0] + (contact[i].geom.normal[0] * contact[i].geom.depth); End[1] = contact[i].geom.pos[1] + (contact[i].geom.normal[1] * contact[i].geom.depth); End[2] = contact[i].geom.pos[2] + (contact[i].geom.normal[2] * contact[i].geom.depth); End[3] = contact[i].geom.pos[3] + (contact[i].geom.normal[3] * contact[i].geom.depth); dsDrawLine(contact[i].geom.pos, End); continue; } dJointID c = dJointCreateContact (world,contactgroup,contact+i); dJointAttach (c,b1,b2); if (show_contacts) dsDrawBox (contact[i].geom.pos,RI,ss); } } } // start simulation - set viewpoint static void start() { dAllocateODEDataForThread(dAllocateMaskAll); static float xyz[3] = {2.1640f,-1.3079f,1.7600f}; static float hpr[3] = {125.5000f,-17.0000f,0.0000f}; dsSetViewpoint (xyz,hpr); printf ("To drop another object, press:\n"); printf (" b for box.\n"); printf (" s for sphere.\n"); printf (" c for cylinder.\n"); printf (" x for a composite object.\n"); printf ("To select an object, press space.\n"); printf ("To disable the selected object, press d.\n"); printf ("To enable the selected object, press e.\n"); printf ("To toggle showing the geom AABBs, press a.\n"); printf ("To toggle showing the contact points, press t.\n"); printf ("To toggle dropping from random position/orientation, press r.\n"); } char locase (char c) { if (c >= 'A' && c <= 'Z') return c - ('a'-'A'); else return c; } // called when a key pressed static void command (int cmd) { int i,j,k; dReal sides[3]; dMass m; cmd = locase (cmd); if (cmd == 'b' || cmd == 's' || cmd == 'c' || cmd == 'x' if (num < NUM) { i = num; num++; } else { i = nextobj; nextobj++; if (nextobj >= num) nextobj = 0; // destroy the body and geoms for slot i dBodyDestroy (obj[i].body); for (k=0; k < GPB; k++) { if (obj[i].geom[k]) dGeomDestroy (obj[i].geom[k]); } memset (&obj[i],0,sizeof(obj[i])); } obj[i].body = dBodyCreate (world); for (k=0; k<3; k++) sides[k] = dRandReal()*0.5+0.1; dMatrix3 R; if (random_pos) { dBodySetPosition (obj[i].body, dRandReal()*2-1,dRandReal()*2-1,dRandReal()+1); dRFromAxisAndAngle (R,dRandReal()*2.0-1.0,dRandReal()*2.0-1.0, dRandReal()*2.0-1.0,dRandReal()*10.0-5.0); } else { dReal maxheight = 0; for (k=0; k<num; k++) { const dReal *pos = dBodyGetPosition (obj[k].body); if (pos[2] > maxheight) maxheight = pos[2]; } dBodySetPosition (obj[i].body, 0,0,maxheight+1); dRFromAxisAndAngle (R,0,0,1,dRandReal()*10.0-5.0); } dBodySetRotation (obj[i].body,R); dBodySetData (obj[i].body,(void*)(size_t)i); if (cmd == 'b') { dMassSetBox (&m,DENSITY,sides[0],sides[1],sides[2]); obj[i].geom[0] = dCreateBox (space,sides[0],sides[1],sides[2]); } else if (cmd == 'c') { sides[0] *= 0.5; dMassSetCapsule (&m,DENSITY,3,sides[0],sides[1]); obj[i].geom[0] = dCreateCapsule (space,sides[0],sides[1]); } else if (cmd == 's') { sides[0] *= 0.5; dMassSetSphere (&m,DENSITY,sides[0]); obj[i].geom[0] = dCreateSphere (space,sides[0]); } else if (cmd == 'x') { dGeomID g2[GPB]; // encapsulated geometries dReal dpos[GPB][3]; // delta-positions for encapsulated geometries // start accumulating masses for the encapsulated geometries dMass m2; dMassSetZero (&m); // set random delta positions for (j=0; j<GPB; j++) { for (k=0; k<3; k++) dpos[j][k] = dRandReal()*0.3-0.15; } for (k=0; k<GPB; k++) { obj[i].geom[k] = dCreateGeomTransform (space); dGeomTransformSetCleanup (obj[i].geom[k],1); if (k==0) { dReal radius = dRandReal()*0.25+0.05; g2[k] = dCreateSphere (0,radius); dMassSetSphere (&m2,DENSITY,radius); } else if (k==1) { g2[k] = dCreateBox (0,sides[0],sides[1],sides[2]); dMassSetBox (&m2,DENSITY,sides[0],sides[1],sides[2]); } else { dReal radius = dRandReal()*0.1+0.05; dReal length = dRandReal()*1.0+0.1; g2[k] = dCreateCapsule (0,radius,length); dMassSetCapsule (&m2,DENSITY,3,radius,length); } dGeomTransformSetGeom (obj[i].geom[k],g2[k]); // set the transformation (adjust the mass too) dGeomSetPosition (g2[k],dpos[k][0],dpos[k][1],dpos[k][2]); dMassTranslate (&m2,dpos[k][0],dpos[k][1],dpos[k][2]); dMatrix3 Rtx; dRFromAxisAndAngle (Rtx,dRandReal()*2.0-1.0,dRandReal()*2.0-1.0, dRandReal()*2.0-1.0,dRandReal()*10.0-5.0); dGeomSetRotation (g2[k],Rtx); dMassRotate (&m2,Rtx); // add to the total mass dMassAdd (&m,&m2); } // move all encapsulated objects so that the center of mass is (0,0,0) for (k=0; k<2; k++) { dGeomSetPosition (g2[k], dpos[k][0]-m.c[0], dpos[k][1]-m.c[1], dpos[k][2]-m.c[2]); } dMassTranslate (&m,-m.c[0],-m.c[1],-m.c[2]); } for (k=0; k < GPB; k++) { if (obj[i].geom[k]) dGeomSetBody (obj[i].geom[k],obj[i].body); } dBodySetMass (obj[i].body,&m); } if (cmd == ' ') { selected++; if (selected >= num) selected = 0; if (selected < 0) selected = 0; } else if (cmd == 'd' && selected >= 0 && selected < num) { dBodyDisable (obj[selected].body); } else if (cmd == 'e' && selected >= 0 && selected < num) { dBodyEnable (obj[selected].body); } else if (cmd == 'a') { show_aabb ^= 1; } else if (cmd == 't') { show_contacts ^= 1; } else if (cmd == 'r') { random_pos ^= 1; } } // draw a geom void drawGeom (dGeomID g, const dReal *pos, const dReal *R, int show_aabb) { if (!g) return; if (!pos) pos = dGeomGetPosition (g); if (!R) R = dGeomGetRotation (g); int type = dGeomGetClass (g); if (type == dBoxClass) { dVector3 sides; dGeomBoxGetLengths (g,sides); dsDrawBox (pos,R,sides); } else if (type == dSphereClass) { dsDrawSphere (pos,R,dGeomSphereGetRadius (g)); } else if (type == dCapsuleClass) { dReal radius,length; dGeomCapsuleGetParams (g,&radius,&length); dsDrawCapsule (pos,R,length,radius); } else if (type == dGeomTransformClass) { dGeomID g2 = dGeomTransformGetGeom (g); const dReal *pos2 = dGeomGetPosition (g2); const dReal *R2 = dGeomGetRotation (g2); dVector3 actual_pos; dMatrix3 actual_R; dMultiply0_331 (actual_pos,R,pos2); actual_pos[0] += pos[0]; actual_pos[1] += pos[1]; actual_pos[2] += pos[2]; dMultiply0_333 (actual_R,R,R2); drawGeom (g2,actual_pos,actual_R,0); } if (show_aabb) { // draw the bounding box for this geom dReal aabb[6]; dGeomGetAABB (g,aabb); dVector3 bbpos; for (int i=0; i<3; i++) bbpos[i] = 0.5*(aabb[i*2] + aabb[i*2+1]); dVector3 bbsides; for (int j=0; j<3; j++) bbsides[j] = aabb[j*2+1] - aabb[j*2]; dMatrix3 RI; dRSetIdentity (RI); dsSetColorAlpha (1,0,0,0.5); dsDrawBox (bbpos,RI,bbsides); } } // simulation loop static void simLoop (int pause) { for(int i = 0; i < 3000000; i++) int dd = 0; dsSetColor (0,0,2); dSpaceCollide (space,0,&nearCallback); if (!pause) dWorldStep (world,0.05); //if (!pause) dWorldStepFast (world,0.05, 1); // remove all contact joints dJointGroupEmpty (contactgroup); dsSetColor (1,1,0); dsSetTexture (DS_WOOD); for (int i=0; i<num; i++) { for (int j=0; j < GPB; j++) { if (i==selected) { dsSetColor (0,0.7,1); } else if (! dBodyIsEnabled (obj[i].body)) { dsSetColor (1,0,0); } else { dsSetColor (1,1,0); } drawGeom (obj[i].geom[j],0,0,show_aabb); } } {const dReal* Pos = dGeomGetPosition(TriMesh); const dReal* Rot = dGeomGetRotation(TriMesh); {for (int i = 0; i < IndexCount / 3; i++){ const float *p = Vertices[Indices[i * 3 + 0]]; const dVector3 v0 = { p[0], p[1], p[2] }; p = Vertices[Indices[i * 3 + 1]]; const dVector3 v1 = { p[0], p[1], p[2] }; p = Vertices[Indices[i * 3 + 2]]; const dVector3 v2 = { p[0], p[1], p[2] }; dsDrawTriangle(Pos, Rot, v0, v1, v2, 0); }}} if (Ray){ dVector3 Origin, Direction; dGeomRayGet(Ray, Origin, Direction); dReal Length = dGeomRayGetLength(Ray); dVector3 End; End[0] = Origin[0] + (Direction[0] * Length); End[1] = Origin[1] + (Direction[1] * Length); End[2] = Origin[2] + (Direction[2] * Length); End[3] = Origin[3] + (Direction[3] * Length); dsDrawLine(Origin, End); } } int main (int argc, char **argv) { // setup pointers to drawstuff callback functions dsFunctions fn; fn.version = DS_VERSION; fn.start = &start; fn.step = &simLoop; fn.command = &command; fn.stop = 0; fn.path_to_textures = DRAWSTUFF_TEXTURE_PATH; // create world dInitODE2(0); world = dWorldCreate(); space = dSimpleSpaceCreate(0); contactgroup = dJointGroupCreate (0); dWorldSetGravity (world,0,0,-0.5); dWorldSetCFM (world,1e-5); //dCreatePlane (space,0,0,1,0); memset (obj,0,sizeof(obj)); Size[0] = 5.0f; Size[1] = 5.0f; Size[2] = 2.5f; Vertices[0][0] = -Size[0]; Vertices[0][1] = -Size[1]; Vertices[0][2] = Size[2]; Vertices[1][0] = Size[0]; Vertices[1][1] = -Size[1]; Vertices[1][2] = Size[2]; Vertices[2][0] = Size[0]; Vertices[2][1] = Size[1]; Vertices[2][2] = Size[2]; Vertices[3][0] = -Size[0]; Vertices[3][1] = Size[1]; Vertices[3][2] = Size[2]; Vertices[4][0] = 0; Vertices[4][1] = 0; Vertices[4][2] = 0; Indices[0] = 0; Indices[1] = 1; Indices[2] = 4; Indices[3] = 1; Indices[4] = 2; Indices[5] = 4; Indices[6] = 2; Indices[7] = 3; Indices[8] = 4; Indices[9] = 3; Indices[10] = 0; Indices[11] = 4; dTriMeshDataID Data = dGeomTriMeshDataCreate(); //dGeomTriMeshDataBuildSimple(Data, (dReal*)Vertices, VertexCount, Indices, IndexCount); dGeomTriMeshDataBuildSingle(Data, Vertices[0], 3 * sizeof(float), VertexCount, &Indices[0], IndexCount, 3 * sizeof(dTriIndex)); TriMesh = dCreateTriMesh(space, Data, 0, 0, 0); //dGeomSetPosition(TriMesh, 0, 0, 1.0); Ray = dCreateRay(space, 0.9); dVector3 Origin, Direction; Origin[0] = 0.0; Origin[1] = 0; Origin[2] = 0.5; Origin[3] = 0; Direction[0] = 0; Direction[1] = 1.1f; Direction[2] = -1; Direction[3] = 0; dNormalize3(Direction); dGeomRaySet(Ray, Origin[0], Origin[1], Origin[2], Direction[0], Direction[1], Direction[2]); // run simulation dsSimulationLoop (argc,argv,352,288,&fn); dJointGroupDestroy (contactgroup); dSpaceDestroy (space); dWorldDestroy (world); dCloseODE(); return 0; } */  
  11. I figured it out, and it was not an easy one: My rendertarget was in the format of ARGB and cleared to black. The alpha values of the plants then changed the alpha value of the rendertarget. This rendertarget was then rendered onto another rendertarget (in order to support multiple viewports), also cleared black, but with XRGB format. And then the black hits through the alpha values.   I changed the rendertarget to XRGB and the problem was solved. I was experimenting once with antialias and at some point set the rendertarget to ARGB and never changed it back, and then it hit me now like a landmine   I thank you all for your patience and incredible will to help. Even when we did not get close to the actual problem here, I learned alot:  - Not taking anything for granted, not even a D3DX-file-loader  - Both editors and loaders can play funny tricks to save space, like storing RGB-layer of pixels with alpha 0 as black (0).  - I learned that good alpha textures needs similar RGB color across the border, or filtering will create an unwanted result (since I have only used other ppl's textures, this was new  to me)  - When I go into details on mipmaps, I have to be careful with the same borders on these as well  - I learned to use PIX!   Thank you all for your help. I wouldn't know what to do without the incredible amount of expertise on this forum.     EDIT: phil_t: It was actually the same scenario as before, I had just disabled rendering skybox, terrain and non-alphatested objects, so I wouldn't get an ungodly amount of textures and surfaces in the test.
  12. I stole code for loading .tga from the ATI demo I used ealier. But it still took quite a while to implement, so I really regret that I didn't try PIX earlier. I didn't know PIX and I guess I shied away because of that. Too bad.   Once I got it up and running, I must say that Im impressed. I can easily see myself getting addicted to it   It does not look like there is anything wrong with the D3DX-loading of the .tga. My ATI-imported code didn't solve the problem either, so I expected that. But what can it be then? I made a collage of the PIX session I ran. If you are interested in something not shown, let me know. I am also uploading my .PixRun file, if anyone is interested. It is created by the latest DX-SDK (june 2010 - had to download it especially for this, as the DX I run on had an ancient version (DX SDK June 2005).     Here is the PIXRun-file (zipped): http://www.samtalebasen.dk/Run7.PIXRun.zip   Here is the PIX-collage (BIG!):
  13. I am hard at work testing different approaches. I got drowned in suggestions here My first attempt will be to write my own loader, so I can be sure D3DX is not messing with me.   I will get back with a full report when I come out of the pixel mines again     EDIT: Actually Im gonna install PIX first, it looks like it can save me the trouble, if D3DX is actually doing its job properly.
  14. I tried to alter the texture filtering in the shader to Point, with this result:   As can be seen, this does not solve my problem. The result is just pixelated.   This is how the sampler looks in the shader: sampler2D g_texturemap_sampler = sampler_state { Texture = <g_texturemap>; MinFilter = Point; MagFilter = Point; MipFilter = Point; };   I also tried to plug my texture into an ATI-demo called "Alpha to Coverage", replacing it with one of the other textures. The demo also draws AlphaTesting, which I set it to in the screenshot. This is how it looks in the ATI demo:   There is no flaws, so I believe that this is not a texture problem - at least not at the file level.   Maybe in my creation? D3DXCreateTextureFromFileExW( m_device,                                 "../database/texture/foliage/gniff.tga", // gniff.tga is just a testname - it is the right one                                 D3DX_FROM_FILE, // width                                 D3DX_FROM_FILE, // height                                 D3DX_DEFAULT, // miplevels                                 0, // usage                                 D3DFMT_A8R8G8B8, // format                                 D3DPOOL_MANAGED, // pool                                 D3DX_DEFAULT, // filter                                 D3DX_DEFAULT, // mipfilter                                 0, // colorkey                                 NULL, // srcinfo                                 NULL, // palette                                 a_textureDX)) // texture   If it is not any of these, could it then be a renderstate, that Im unaware of? Is there any renderstate, that can cause this?   Thank you for your help guys.
  15. Btw, I whited out the entire rgb layer - completely, meaning across borders - of the texture in the opening post. That should ensure, that the colors around the borders were the same.