• Create Account

# tracegame

Member Since 26 May 2012
Offline Last Active Apr 15 2016 10:37 PM

### Proof of Momentum？？

21 March 2016 - 02:25 AM

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)

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

25 October 2015 - 09:40 PM

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.

### Need help with GLSL and Raytrace

30 September 2015 - 09:22 PM

Hi,everyone.

I am new to raytrace.and i found some example from shadertoy.

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 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);
dis = (-sqrt(g) - b) / a;

and this code really works.
why?what's going on here?

### How to update texture per pixel every frame?

20 September 2015 - 10:03 PM

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?

### DX11 beginner question,my draw line function cancel my first drawing object

15 June 2015 - 02:42 AM

i am a beginner to directx and i begin with directx11 from some youtube tutoriall

i followed this tutorial,and try to write a draw line function and it works.
only problem is if i use my draw line function it will cancel my first draw sprite.

i will upload the vs2010 project file here.hope i can.

in GameScene.cpp file,if i comment out the "void GameScene::Render" function which is used for drawing lines,2 sprites will display.
but if i use draw line,the first one won't display.
and other problem is the line i draw seems Transparent,i did not use alpha draw line and i expect they should look all the same opaque.
why they seem different?

and finally i found a new strange bug,i set my player sprite with 32 width 48 height.
enemy with 256 width 256 height.

if render them both,something strange happen my player displayed as 256x256,enemy display as 32x48.
but if i only render one of them,everything is right.i can control my player with 32x48,and enemy display as 256x256 as it should be.
why?