WiredCat

Members
  • Content count

    850
  • Joined

  • Last visited

Community Reputation

1451 Excellent

About WiredCat

  • Rank
    >^_^<

Personal Information

  1. int i = 208; float f = (float)i; Despite i know you will rant about that code please tell me if i will be 208 or i may get something close to 208? Cheers
  2. Quadtree/terrain frustum culling help

    Heres quadtree pvs system #ifndef ocean_pvs_systemH #define ocean_pvs_systemH #include "DxcMath.h" #include "DxcMatrix.h" #include "frustum.h" #include "glwrapper.h" #include "shaderclass.h" struct TOceanPVSCell { Pushort * indices; //each row corresponds to each row in the ocean int len; //both dimensions of an array int ilen; unsigned int * elementbuff; bool add2; int x; int z; //points of grid (adding translation will give correct worldspace pos) vec3 A; vec3 B; vec3 C; vec3 D; TOceanPVSCell() { add2 = false; indices = NULL; elementbuff = NULL; len = 0; } ~TOceanPVSCell() { if (indices != NULL) { delete [] indices; for (int i=0; i < len; i++) glDeleteBuffers(1, &elementbuff[i]); delete [] elementbuff; } } }; struct TOceanPVS { float pvs_cell_size; TFrustum EYE; TOceanPVSCell * cells; int sectors; int sim_grid_size; int * vis[9]; //each direction, that stores visible pvs cells, because i first determine which i see then i draw them int vislen[9]; bool visvis[9]; float ocean_grid_size; int cells_in_sector; vec3 A; vec3 B; vec3 C; vec3 D; TOceanPVS() { cells = NULL; } ~TOceanPVS() { if (cells != NULL) { delete [] cells; for (int i=0; i < 9; i++) delete [] vis[i]; } } bool TGridVisible(int translation_index, int X, int Z) { float DirX[9] = {0.0, -1.0, 1.0, 0.0, 0.0, -1.0, 1.0, -1.0, 1.0}; float DirY[9] = {0.0, 0.0, 0.0, -1.0, 1.0, 1.0, 1.0, -1.0, -1.0}; vec3 t = vec3(ocean_grid_size*float(X), 0.0, ocean_grid_size*float(Z)); vec3 v[4]; v[0] = A + vec3(ocean_grid_size*DirX[translation_index], 0.0, ocean_grid_size*DirY[translation_index]) + t; v[1] = B + vec3(ocean_grid_size*DirX[translation_index], 0.0, ocean_grid_size*DirY[translation_index]) + t; v[2] = C + vec3(ocean_grid_size*DirX[translation_index], 0.0, ocean_grid_size*DirY[translation_index]) + t; v[3] = D + vec3(ocean_grid_size*DirX[translation_index], 0.0, ocean_grid_size*DirY[translation_index]) + t; return EYE.BoxIsVisible(v, 4); } bool PVSCellVisible(int index, int translation_index, int X, int Z) { float DirX[9] = {0.0, -1.0, 1.0, 0.0, 0.0, -1.0, 1.0, -1.0, 1.0}; float DirY[9] = {0.0, 0.0, 0.0, -1.0, 1.0, 1.0, 1.0, -1.0, -1.0}; vec3 t = vec3(ocean_grid_size*float(X), 0.0, ocean_grid_size*float(Z)); vec3 v[4]; v[0] = cells[index].A + vec3(ocean_grid_size*DirX[translation_index], 0.0, ocean_grid_size*DirY[translation_index]) + t; v[1] = cells[index].B + vec3(ocean_grid_size*DirX[translation_index], 0.0, ocean_grid_size*DirY[translation_index]) + t; v[2] = cells[index].C + vec3(ocean_grid_size*DirX[translation_index], 0.0, ocean_grid_size*DirY[translation_index]) + t; v[3] = cells[index].D + vec3(ocean_grid_size*DirX[translation_index], 0.0, ocean_grid_size*DirY[translation_index]) + t; return EYE.BoxIsVisible(v, 4); } void CalculatePVS(int X, int Z, TSpecCamera * FPP_CAM, mat4 CAM_VIEW, int sw, int sh, float fovy, float z_near, float z_far, float aspect) { EYE.CalcFrustum(FPP_CAM,CAM_VIEW, sw, sh, fovy, z_near, z_far, aspect); vec3 v[4]; v[0] = vec3(0.0, 0.0, 0.0); v[1] = vec3(400.0, 0.0, 0.0); v[2] = vec3(400.0, 0.0, 400.0); v[3] = vec3(0.0, 0.0, 400.0); int h = 0; //ALOG("NEW PVS FRAME"); for (int i=0; i < 9; i++) { visvis[i] = TGridVisible(i, X, Z); // if (visvis[i]) h = h + 1; vislen[i] = -1; } for (int i=0; i < 9; i++) if (visvis[i]) { for (int n=0; n < sectors*sectors; n++) if (PVSCellVisible(n, i, X, Z)) { vislen[i] = vislen[i] + 1; vis[i][vislen[i]] = n; } } for (int i=0; i < 9; i++) vislen[i] = vislen[i] + 1; //for (int i=0; i < 9; i++) //ALOG("VIS: "+IntToStr(i) + " "+IntToStr(vislen[i])+ " pvs cells visible"); } void DrawOceanPVS(TShaderObject * shader, int X, int Z) { float DirX[9] = {0.0, -1.0, 1.0, 0.0, 0.0, -1.0, 1.0, -1.0, 1.0}; float DirY[9] = {0.0, 0.0, 0.0, -1.0, 1.0, 1.0, 1.0, -1.0, -1.0}; for (int i=0; i < 9; i++) if (visvis[i]) { vec3 t = vec3(DirX[i]*float(ocean_grid_size), 0.0, DirY[i]*float(ocean_grid_size)) + vec3(float(X)*ocean_grid_size, 0.0, float(Z)*ocean_grid_size); mat4 wrld; wrld.LoadIdentity(); wrld.TranslateP(t); shader->SendWorldMatrixtoShader(wrld); mat4 MVP = (wrld * ACTUAL_VIEW) * ACTUAL_PROJECTION; shader->SendMVPtoShader(MVP); for (int n=0; n < vislen[i]; n++) { int celli = vis[i][n]; int len = cells[celli].len * 2; if (cells[celli].add2) len = len + 2; for (int k=0; k < cells[celli].len; k++) { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, cells[celli].elementbuff[k]); glDrawElements(GL_TRIANGLE_STRIP, GLsizei(len), GL_UNSIGNED_SHORT, (void*)( 0 ) ); } } } glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } int ArrI(int x, int y) { return y*sim_grid_size + x; } int pvsI(int x, int y) { return y*sectors + x; } void Initialize(int sections, float oc_grid_size, int sim_grd_size) { CAN_LOG = false; sim_grid_size = sim_grd_size; ocean_grid_size = oc_grid_size; // OCEAN_TEX_GRID_SIZE for (int i=0; i < 9; i++) { vislen[i] = 0; visvis[i] = false; vis[i] = new int[sections*sections]; } sectors = sections; cells_in_sector = sim_grid_size / sections; //64 / 8 = 8 cells = new TOceanPVSCell[sections * sections]; //8 * 8 = 64 B.x = oc_grid_size; C.x = oc_grid_size; C.z = oc_grid_size; D.z = oc_grid_size; ALOG("1"); pvs_cell_size = float(oc_grid_size) / sectors; for (int y = 0; y < sim_grid_size; y++) for (int x = 0; x < sim_grid_size; x++) { int sectionX = x / cells_in_sector; int sectionY = y / cells_in_sector; int row = y % cells_in_sector; int col = x % cells_in_sector; int pvsi = pvsI(sectionX, sectionY); cells[pvsi].x = sectionX; cells[pvsi].z = sectionY; } //ALOG("2"); for (int y = 0; y < sections; y++) for (int x = 0; x < sections; x++) { float xper = float(x) / float(sections); float yper = float(y) / float(sections); float x2per = float(x+1) / float(sections); float y2per = float(y+1) / float(sections); int pvsi = pvsI(x, y); //ALOG("VXX: "+IntToStr(cells[pvsi].x)+ " y: "+IntToStr(cells[pvsi].z)); cells[pvsi].A.x = xper * ocean_grid_size; cells[pvsi].A.z = yper * ocean_grid_size; cells[pvsi].B.x = x2per * ocean_grid_size; cells[pvsi].B.z = yper * ocean_grid_size; cells[pvsi].C.x = x2per * ocean_grid_size; cells[pvsi].C.z = y2per * ocean_grid_size; cells[pvsi].D.x = xper * ocean_grid_size; cells[pvsi].D.z = y2per * ocean_grid_size; } //ALOG("3"); for (int i=0; i < sections*sections; i++) { int alen = cells_in_sector; // if (cells[i].z == sections-1) alen = alen - 1; cells[i].len = alen; cells[i].indices = new Pushort[cells[i].len]; cells[i].elementbuff = new unsigned int[cells[i].len]; bool add2 = true; if (cells[i].x == sections-1) add2 = false; int k = 2; if (!add2) k = 0; cells[i].ilen = cells_in_sector*2+k; for (int n=0; n < cells[i].len; n++) { cells[i].indices[n] = new unsigned short[cells[i].ilen]; cells[i].add2 = add2; } } for (int n=0; n < sectors*sectors; n++) for (int i=0; i < cells[n].len; i++) for (int j=0; j < cells[n].ilen; j++) cells[n].indices[i][j] = 0; //ALOG("4"); for (int y = 0; y < sim_grid_size-1; y++) for (int x = 0; x < sim_grid_size; x++) { int sectionX = x / cells_in_sector; int sectionY = y / cells_in_sector; int row = y % cells_in_sector; int col = x % cells_in_sector; int pvsi = pvsI(sectionX, sectionY); cells[pvsi].x = sectionX; cells[pvsi].z = sectionY; cells[pvsi].indices[row][col*2] = (unsigned short)ArrI(x,y+1); cells[pvsi].indices[row][col*2+1] = (unsigned short)ArrI(x,y); //ArrI(x,y); //return y*sim_grid_size + x; //ALOG("CXX x: "+IntToStr(x)+ " y: "+IntToStr(y)); //last element needs additional 2 indices from next first, do not do that for last column if ( (col == cells_in_sector-1) && (sectionX != sectors - 1) ) { if (!cells[pvsi].add2) ALOG("SOMETHING BAD IS HAPPENING"); cells[pvsi].indices[row][col*2 + 2] = (unsigned short)ArrI(x+1,y+1); cells[pvsi].indices[row][col*2+1 + 2] = (unsigned short)ArrI(x+1,y); // ALOG("BXX: x2y2"+IntToStr(ArrI(x+1,y+1)) + " x2y1 :"+IntToStr(ArrI(x+1,y)) +" x: "+IntToStr(x+1)+ " y: "+IntToStr(y+1)); } } //ALOG("5"); //flush to gpu for (int n=0; n < sectors*sectors; n++) { int k = 0; if (cells[n].add2) k = 2; for (int i=0; i < cells[n].len; i++) { glGenBuffers(1, &cells[n].elementbuff[i]); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, cells[n].elementbuff[i]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, cells[n].ilen * sizeof(unsigned short), cells[n].indices[i], GL_STATIC_DRAW); } glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); //ALOG("6"); for (int n=0; n < sectors*sectors; n++) { // ALOG("cell len: "+IntToStr(cells[n].len) + " additional 2: "+booltostring(cells[n].add2)); AnsiString indi; for (int i=0; i < cells[n].len; i++) { indi = ""; int ylen = cells[n].len * 2; if (cells[n].add2) ylen = ylen + 2; for (int j=0; j < ylen; j++) indi = indi + " " + IntToStr(int(cells[n].indices[i][j])); //ALOG("cx: "+IntToStr(cells[n].x)+ " cy: "+IntToStr(cells[n].z)+ " Indices: "+indi); } } } }; #endif
  3. This is an example of a typecast you would like to use If ( ((AComponent*)components[i])->type == TCTGLTrackBar ) ((TGLTrackBar*)components[i])->Init();
  4. Algorithm to convert screen point to ray

    vec3 dir = DirectionFromScreen(CursorX, CursorY, SCREEN_WIDTH, SCREEN_HEIGHT,90.0, 2.0, 1000.0, float(SCREEN_WIDTH) / float(SCREEN_HEIGHT)); ray_vb[1].v = FPP_CAM->pos + dir*(1000.0*depth*2.0); vec3 DirectionFromScreen(int x, int y, int sw, int sh, float fov, float z_near, float z_far, float aspect) { mat4 mvm = CAM_MODEL * CAM_VIEW; mvm.Transpose(); vec3 dirX, dirY; dirX.x = mvm.m[0]; dirX.y = mvm.m[4]; dirX.z = mvm.m[8]; dirY.x = mvm.m[1]; dirY.y = mvm.m[5]; dirY.z = mvm.m[9]; float a = fov / 2.0; float cotangent = 1.0 / tan( a * imopi ); float ax = z_near / cotangent; float screen_w = 2.0*ax; float screen_h = screen_w;// * yratio; screen_w = screen_w * aspect; float scr_coord_x = float(x) / float(sw); float scr_coord_y = float(sh - y) / float(sh); vec3 dir = FPP_CAM->ReturnFrontVector(); //move to lower left corner vec3 start_pos = (FPP_CAM->pos + dir * z_near) + (-dirX * (screen_w / 2.0)) + (-dirY * (screen_h/2.0)); vec3 start = start_pos + (dirX * (screen_w * scr_coord_x)) + (dirY * (screen_h * scr_coord_y)); return Normalize( vectorAB(FPP_CAM->pos, start) ); } Assuming that you have projection and view matrices defined You end up with point on far plane by. Camera_pos+z_far*direction Front vector can be computed from dirx and diry
  5. So i have a base class: template <class pos_depth, class normal_depth, class vel_depth, class mass_depth, class world_depth, class time_depth> class PComponent Now i have a second class" struct AComponent : public PComponent<float, float, float, float, float, float> However this does not compile i am not even sure if i can do such thing like that: error: Description Resource Path Location Type expected '{' before '<' token vcl.h /WiredNavalBattle/jni/Editor line 129 C/C++ Problem expected template-name before '<' token vcl.h /WiredNavalBattle/jni/Editor line 129 C/C++ Problem expected unqualified-id before '<' token vcl.h /WiredNavalBattle/jni/Editor line 129 C/C++ Problem make.exe: *** [obj/local/armeabi-v7a/objs-debug/game/constvars2.o] Error 1 WiredNavalBattle C/C++ Problem Any thoughts? Ah i forgot to include the header file, however i have another problem since in second class i want to call PComponent constructor it doesnt allow me to do that i could eaisly make a void in PComponent class which contains constructor code, and call it from AComponent (second class) but maybe theres another way?
  6. For editor purposes i want to change my matrix class which for now is template <class T> class Matrix44 { template <class T> class Matrix44 however i would like to multiply lets say Matrix44<float> with Matrix44<double> i could do this by adding template <class T, class T2> class Matrix44 But this would require me to define every matrix44 as <float, double> etc. which is not an option since i have hundreds of such vars. The change in code would be significant if not i would have to rewrite tenth thousands lines of code. Maybe theres a quick solution to this I woukld like to multiple world matrix by viewmatrix and projection matrix thus world matrix would be double and rest would be float so for now i have Matrix44<T> operator *(Matrix44<T> mat) which forces me to use only one type. There should be a way to use other type Matrix44<T> operator *(Matrix44<T2> mat) any thoughts?
  7. Computing the side planes of a 3D AABB

    Well thats really trivial question since you own all data needrd to crrate planes yoy ask herr there are plenty of ways to do this but they all involve these teo points, i recommend you draw an axis aligned box on paper then mark your points - you still cant compute other points? Well yhats so obvious that noone will tell you how to do that, when you compute all 8 points you have two options , either compute crossproduct for each side or use normal of side and a point that lies on that side to find D in your Ax+By+Cz+D=0. Aftrr that you need to chceck whenever your planes face right direction you do that by dividing min and max by 2 (Min+max)/2= cp //center point U assume you know that ABC arr your side plane normal components correspondibgto xyz in vector Then you just do dot(side nornal, cp) and check whenever they are negative or else and change the sign of a normal
  8. A little bit off topic but i always first writr then length of char array and then i writr char array anyway Memcpy is your pal, you just memcpy(&floatvar, &chartable[index],3); Something kike this you copy some amount memory to float pointer
  9. Thus adding such snall value might cause crash too try to define highp precision float shouldnt meant imo to be such small for shaders try to multiple it by 10, anyway loop doesnt return anything. If thats only a sample code then ok but you could do not calculate sum like that
  10. A little bit oftopic but physically based and actual physical calculations are two different things you better study that yourself out
  11. Ray calculation for volumetric spotlight effect

    Lets gor now dont use rotation and translation you define a cone as two functions that one outputs radius given the height. Consider a spotlight as two points one is the cone top (start pos) second is at the bottom center, the line you define points toward the direction of a spotlight. Given distance function that i talked about earlier, you compute closest point on a segment given actual depth vertex pos, and compare how much actual fragment gets the light And sorry i didnt even read your question lol
  12. OpenGL OpenGL 2D GUI system question

    No no no, you can pass pixel coords to vertex shader and there recalculate actual vertex clip position on screen not to mention y axis is flipped so you start from y=0 at bottom left corner So how to do that in shader well first of all you pass vertex pixel coords then you pass screen size in pixels then you make something like nv.x = v.x / screen_width to get percentage of screen coords this should give you a number from 0..1 then you need to multiple it by 0.5 and subtract it by -1??? I really forgot how to do this anyway you need to end with a number between -1 and 1 or was it 0.5 as I said I'm on the phone now and can't actually check that for code let others think
  13. Search Google for vkkeyscan function
  14. You could obtain was header and then put data after it closing it into some class note that sound is much more than array of shorts one positive another negative then again positive then negative etc. If you use Windows only then direct supports playing a set of bytes, or ask should support that too bass library supports that too anyway you need to sample data right etc.
  15. I just found a code which uses libavcodec to decode videos and display them on screen Canvas canvas = surfaceHolder.lockCanvas(); canvas.drawBitmap(mBitmap, mDrawLeft, mDrawTop, prFramePaint); surfaceHolder.unlockCanvasAndPost(canvas); anyway it looks like a ton of useless garbage, it first decodes then draws a bitmap, i would like to somehow transfer video data to gpu directly so i can just draw a video frame in a simple poly (made of 4 verts), however it may be undoable, anyone has any more information about it?