# tracegame

Members

41

164 Neutral

• Rank
Member
1. ## Need Explanation With Distance Between Two Segments

Thank you for your great help,now I understand. :D
2. ## Need Explanation With Distance Between Two Segments

The code below is from book Real-Time Collection Detection ch5.cpp file Some of them I don't know where it come from.   float denom = a*e-b*b;   and   (b*f - c*e) / denom   what does this mean?I know a is square length of d1,e is square length of d2,b is d1 projection on d2, but what does a*e-b*b means?where this guy come from,for what reason?any rule or fomular related?? Can somebody point me the direction or something to figure this out.Thanks // Computes closest points C1 and C2 of S1(s)=P1+s*(Q1-P1) and // S2(t)=P2+t*(Q2-P2), returning s and t. Function result is squared // distance between between S1(s) and S2(t) float ClosestPtSegmentSegment(Point p1, Point q1, Point p2, Point q2, float &s, float &t, Point &c1, Point &c2) { Vector d1 = q1 - p1; // Direction vector of segment S1 Vector d2 = q2 - p2; // Direction vector of segment S2 Vector r = p1 - p2; float a = Dot(d1, d1); // Squared length of segment S1, always nonnegative float e = Dot(d2, d2); // Squared length of segment S2, always nonnegative float f = Dot(d2, r); // Check if either or both segments degenerate into points if (a <= EPSILON && e <= EPSILON) { // Both segments degenerate into points s = t = 0.0f; c1 = p1; c2 = p2; return Dot(c1 - c2, c1 - c2); } if (a <= EPSILON) { // First segment degenerates into a point s = 0.0f; t = f / e; // s = 0 => t = (b*s + f) / e = f / e t = Clamp(t, 0.0f, 1.0f); } else { float c = Dot(d1, r); if (e <= EPSILON) { // Second segment degenerates into a point t = 0.0f; s = Clamp(-c / a, 0.0f, 1.0f); // t = 0 => s = (b*t - c) / a = -c / a } else { // The general nondegenerate case starts here float b = Dot(d1, d2); float denom = a*e-b*b; // Always nonnegative,======================================Here is the one ====================================== // If segments not parallel, compute closest point on L1 to L2, and // clamp to segment S1. Else pick arbitrary s (here 0) if (denom != 0.0f) { s = Clamp((b*f - c*e) / denom, 0.0f, 1.0f);//======================================Here is the other one ====================================== } else s = 0.0f; // Compute point on L2 closest to S1(s) using // t = Dot((P1+D1*s)-P2,D2) / Dot(D2,D2) = (b*s + f) / e t = (b*s + f) / e; // If t in [0,1] done. Else clamp t, recompute s for the new value // of t using s = Dot((P2+D2*t)-P1,D1) / Dot(D1,D1)= (t*b - c) / a // and clamp s to [0, 1] if (t < 0.0f) { t = 0.0f; s = Clamp(-c / a, 0.0f, 1.0f); } else if (t > 1.0f) { t = 1.0f; s = Clamp((b - c) / a, 0.0f, 1.0f); } } } c1 = p1 + d1 * s; c2 = p2 + d2 * t; return Dot(c1 - c2, c1 - c2); }
3. ## Proof of Momentum??

Find a friend to help work this out,i'm really not good at Algebra. Why prove it,because usually i just copy,paste codes without thinking, now i'm trying to do things step by step,and try to figure out why these code work, no more blackbox coding.   anyway thanks for the reply,post a few places,just got reply here.     [attachment=31191:Momentum.png]
4. ## Proof of Momentum??

Read a book about physics - Foundation AS3 Animation Making Things Move and there is the equation i can not prove. why (m0 * v0) + (m1 * v1) = (m0 * v0F) + (m1 * v1F) (m0 * v0^2) + (m1 * v1^2) = (m0 * v0F^2) + (m1 * v1F^2) can get v0F=((m0-m1)*v0+2*m1*v1)/(m0+m1) v1F=((m1-m0)*v0+2*m0*v0)/(m0+m1)   [attachment=31182:momentum_prove.png]

6. ## How to do collision like mario with gap dash?

Thank you for the infomation and keywords.Really helps. and i came back to post some actually code i searched from github. it's a html mario game with gap dash and some other cool stuff,complete mario 1 clone works on my chrome not firefox,a little strange,but guess may help someone,i will just leave the link. https://github.com/FullScreenShenanigans/FullScreenMario
7. ## How to do collision like mario with gap dash?

well,Dash here is really means Run,cause mario does not have a flash burst dash like Mega man. I'm not good at english,gap dash is some word i googled from internet.Maybe it called something else. But i guess you know what i mean if you have played Mario.Run across one tile gap works in every version of mario
8. ## How to do collision like mario with gap dash?

I have written some simple 2D platform game now. and i'd like to write a mario clone myself. problem is how to do a gap dash which means when i am on running mode i can dash foward for one tile gap. If not running,i will walk down the one tile gap,and falling down. I think if i just change the speed,i can not promise to pass the hole tile. cause if i stand some place i still may run exact to the hole positon. Then i think maybe i can large the collision rectangle when i was on running mode by 1 or 2 pixels. which can promise if it is one tile gap,i will not run down,cause i fill the whole collisioin area by enlarging the rectangle. but i am not sure this is a good idea. What's the usual way to do gap dash collison? Want to learn some new and better ideas.
9. ## OpenGL Need help with GLSL and Raytrace

Hi,everyone. I am new to raytrace.and i found some example from shadertoy. link below https://www.shadertoy.com/view/ld2Gz3 with a little work,i can run this shader in opengl now. my question is there is some equation i do not understand. it is about ray intersect with sphere. here is the code. void intersectSphere(const Sphere sphere, const Ray ray, Material material, inout Output o) { vec3 d = ray.origin - sphere.origin; float a = dot(ray.direction, ray.direction); float b = dot(ray.direction, d); float c = dot(d, d) - sphere.radius * sphere.radius; float g = b*b - a*c; if(g &gt; 0.0) { float dis = (-sqrt(g) - b) / a; if(dis &gt; 0.0 &amp;&amp; dis &lt; o.dis) { o.dis = dis; o.origin = ray.origin + ray.direction * dis; o.normal = (o.origin - sphere.origin) / sphere.radius; o.material = material; } } } as i know g should equal to b*b - 4*a*c; but this code is g = b*b - a*c; and dis should equal to (-sqrt(g) - b) / (2*a); but instead it is dis = (-sqrt(g) - b) / a; and this code really works. why?what's going on here?
10. ## OpenGL How to update texture per pixel every frame?

thank you,PBO is exactly what i want.
11. ## OpenGL How to update texture per pixel every frame?

New to OpenGL. I want to write pixel to texture oen by one. In directx 11.I do something below hr = mDeviceContext->Map(pNewTexture, subresource, D3D11_MAP_READ_WRITE, 0, &resource); float* source = static_cast< float* >(resource.pData); then i can direct operate source for (int i = 0; i < 512; ++i) { source[i] = height; } then unmap it mDeviceContext->Unmap(pNewTexture, 0); and copy to the texture i want to mDeviceContext->CopyResource(audioTex, pNewTexture); all done what is the equivalent code in OpenGL? i try to write like glBindBuffer(GL_TEXTURE_BUFFER, tex2); void *ptr = glMapBuffer(GL_TEXTURE_BUFFER, GL_WRITE_ONLY); unsigned char data[] = {0,100,100,100}; memcpy(ptr, data, sizeof(data)); glUnmapBuffer(GL_TEXTURE_BUFFER); glBindBuffer(GL_TEXTURE_BUFFER, 0); but this does not seem to change the texture. instead it accidently change my vertex position. strange what is the right way to do this?
12. ## DX11 DX11 beginner question,my draw line function cancel my first drawing object

Fixed sprite render problem,It is because of the wrong order setting buffer by the tutorial author.   And the Transparent line problem is because of the windows style.   This is strange and i think i need some help maybe.   In the create window part like int nStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP; //int nStyle = WS_OVERLAPPED | WS_SYSMENU | WS_VISIBLE | WS_MINIMIZEBOX; hwnd = CreateWindowEx(WS_EX_APPWINDOW, windowTitle, windowTitle, nStyle, posX, posY, screenWidth, screenHeight, NULL, NULL, m_hInstance, NULL); If use WS_POPUP style which is same as Rastertek_DX11 tutorial did,the line display as opaque, which is what i need. But this will make the window undraggable.And there is no minimize and window boarder.Not good for dragging around.   If i use the WS_OVERLAPPED style,The line will display as some of them transparent.Which is not what i wanted.   So how can i set the window style to be draggable and the line displayed as opaque?   WS_OVERLAPPED and WS_POPUP doesn't seem to work together.       OK,solved.Leave the link for who have same problem.Actually the window size and client size are not the same.   The line looks transparent is becuase the client image was scaled.Not the original aspect ratio.   http://stackoverflow.com/questions/431470/window-border-width-and-height-in-win32-how-do-i-get-it
13. ## DX11 DX11 beginner question,my draw line function cancel my first drawing object

Thank you,Buckeye for replying so patiently.   And apologize for my bad english and posted so many scaring code segment.   I guess maybe the tutorial render pipeline is wrong.   Bucase i found some other example from Rastertek DX11 tutorial,Tutorial 26  Transparency   And drop my draw line function there,and everything works fine.no sprite size problem,no draw line cancel problem, no transparent line problem at all.   I think i can manage to fix the problem by myself now.   And thanks again for the kind reply.
14. ## DX11 DX11 beginner question,my draw line function cancel my first drawing object

1.Check that the draw-line and the draw-sprite functions each work correctly by themselves. yes,they do.and no they don't if they work together.If run only one type they really works.   2.Check the states each function must have set correctly, and ensure they're set as necessary by each function at the time it's called. since i am new to dx,i am not 100% sure of this.just follow the tutorial,there is not too many explain in that video.so some code i am not really understanding very well.   3.Does your call m_entityManager->Render( ... ) work properly if blending is disabled same as right now. if render single object,works with z off blend off if render both still get wrong size,or reverse size.   does this mean the render state wrong?what shall do?post some state function up here? to be honest,those bunch of state description really scares.