Jump to content

  • Log In with Google      Sign In   
  • Create Account


Ilya.s

Member Since 11 Dec 2006
Offline Last Active Jun 19 2014 08:58 PM

Topics I've Started

Flowmaps distortion

13 December 2012 - 02:45 AM

I've implemented flowmaps based on the following article: http://graphicsrunner.blogspot.ru/2010/08/water-using-flow-maps.html
For smaller values of flowSpeed everything is fine, but for larger values the water surface is getting extremely distorted. Is there any solution to this problem?
Here's how do the FlowMapOffset calculation:
    flowMapOffset0 += flowSpeed * Time.deltaTime;
    flowMapOffset1 += flowSpeed * Time.deltaTime;
    if ( flowMapOffset0 >= cycle )
		 flowMapOffset0 = .0f;

Small flowSpeed:
Posted Image

Large flowSpeed:
Posted Image

Tangent space rotation

04 December 2012 - 04:13 AM

I'm trying to rotate a view direction vector in my shader into tangent space. I need this for cubemap reflections to work on an arbitrary normal mapped surface. However for some strange reason the resulting reflection is rotated by 90 degrees in the YZ plane. It used to work correctly until I introduced the tangent space rotation. I suppose that the rotated viewDir vector is rotated incorrectly by 90 degrees. What's the reason and how can I fix it?

Here's a snippet from my CG shader:

v2f vert (appdata_tan v)
{
	v2f o;
	o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
  
   float3 binormal = cross( v.normal, v.tangent.xyz ) * v.tangent.w;
   float3x3 rotation = float3x3( v.tangent.xyz, binormal, v.normal );
	o.viewDir = mul (rotation, ObjSpaceViewDir(v.vertex));
}
fixed4 frag (v2f i) : COLOR
{
half3 refl = reflect( normalize(i.viewDir), half3(0.0, 1.0, 0.0) );
refl.x = -refl.x;
texcol.rgb = texCUBE( _Cube , refl ).rgb;
return texcol;
}

Velocity of a rolling ball

30 January 2010 - 04:41 AM

Hello, I need help with calculating angular and CM (center of mass) velocity of a rolling ball. The ball is rolling on an inclined surface. What I have: - CM velocity (velocity of a ball itself) - Angular velocity ( w ) - Coefficient of friction ( coeff ) - Normal of a plane What I need to get: - New velocity of center of mass (ball itself) - New angular velocity I have already implemented collision detection and collision response (only calculating new velocity of a ball after collision, based on restitution). But I can't figure out how to make the ball roll properly on the surface. I want to take into account sliding of a ball (if tangent velocity + ball velocity is not equal to 0 then a ball slides on the surface) Thank you in advance.

Collision detection between spheres

15 January 2010 - 06:54 AM

Hello, I want to find when a collision between a static and a moving ball occurs, but the algorithm I came up with, sometimes doesn't detect a collision and the moving ball goes through the static one. The moving ball is affected by gravity and the static one is not. Here's my collision detection code:
    GLfloat whenSpheresCollide(const sphere2d &firstSphere, const sphere2d &secondSphere)
    {
    	Vector2f relativePosition = subtractVectors(firstSphere.vPosition, secondSphere.vPosition);
    	Vector2f relativeVelocity = subtractVectors(firstSphere.vVelocity, secondSphere.vVelocity);
    	
    	GLfloat radiusSum = firstSphere.radius + secondSphere.radius;
    	
    	//We'll find the time when objects collide if a collision takes place
    	
    	//r(t) = P[0] + t * V[0]
    	//
    	//d^2(t) = P[0]^2 + 2 * t * P[0] * V[0] + t^2 * V[0]^2
    	//
    	//d^2(t) = V[0]^2 * t^2 + 2t( P[0] . V[0] ) + P[0]^2
    	//
    	//d(t) = R
    	//
    	//d(t)^2 = R^2
    	//
    	//V[0]^2 * t^2 + 2t( P[0] . V[0] ) + P[0]^2 - R^2 = 0
    	//
    	//delta = ( P[0] . V[0] )^2 - V[0]^2 * (P[0]^2 - R^2)
    	//
    	//	We are interested in the lowest t:
    	//
    	//t = ( -( P[0] . V[0] ) - sqrt(delta) ) / V[0]^2
    	//
    	
    	GLfloat equationDelta = squaref( dotProduct(relativePosition, relativeVelocity) ) - squarev( relativeVelocity ) * ( squarev( relativePosition ) - squaref(radiusSum)  );
    	
    	if (equationDelta >= 0.0f)
    	{
    		GLfloat collisionTime = ( - dotProduct(relativePosition, relativeVelocity) - sqrtf(equationDelta) ) / squarev(relativeVelocity);
    		
    		if (collisionTime >= 0.0f && collisionTime <= 1.0f / GAME_FPS)
    		{
    			return collisionTime;
    		}
    	}
    	
    	return -1.0f;
    }


And here is the updating function that calls collision detection:
    void GamePhysicsManager::updateBallPhysics()
    {
    	//
    	//Update velocity
    	vVelocity->y -= constG / GAME_FPS;	//v = a * t = g * 1 sec / (updates per second)
    	
    	shouldApplyForcesToBall = TRUE;
    	
    	vPosition->x += vVelocity->x / GAME_FPS;
    	vPosition->y += vVelocity->y / GAME_FPS;

    	if ( distanceBetweenVectors( *pBall->getPositionVector(), *pBasket->getPositionVector() ) <= pBasket->getRadius() + vectorLength(*vVelocity) / GAME_FPS )
    	{
    		//Ball sphere
    		sphere2d ballSphere;
    		ballSphere.radius = pBall->getRadius();
    		ballSphere.mass = 1.0f;
    		ballSphere.vPosition = *( pBall->getPositionVector() );
    		ballSphere.vVelocity = *( pBall->getVelocityVector() );
    		
    		
    		sphere2d ringSphereRight;
    		ringSphereRight.radius = 0.05f;
    		ringSphereRight.mass = -1.0f;
    		ringSphereRight.vPosition = *( pBasket->getPositionVector() );
    		//ringSphereRight.vPosition.x += pBasket->getRadius();
    		ringSphereRight.vPosition.x += (pBasket->getRadius() - ringSphereRight.radius);
    		ringSphereRight.vVelocity = zeroVector();
    		
    		
    		GLfloat collisionTime = whenSpheresCollide(ballSphere, ringSphereRight);
    		
    		if ( collisionTime >= 0.0f )
    		{
    			DebugLog("collision");
    			respondToCollision(&ballSphere, &ringSphereRight, collisionTime, pBall->getRestitution() * 0.75f );
    		}
    				
    		//
    		//Implement selection of the results that are first to collide collision
    		
    		vVelocity->x = ballSphere.vVelocity.x;
    		vVelocity->y = ballSphere.vVelocity.y;
    		
    		vPosition->x = ballSphere.vPosition.x;
    		vPosition->y = ballSphere.vPosition.y;
    	}


Problem seems to be solved when I change FPS from 30 to 10. How does FPS affect my collision detection? Why isn't the collision being detected in 100% of cases? It's being detected only in 70% of cases. Thanks.

Index buffer in OpenGL

24 March 2008 - 04:16 AM

Hello, How is an index buffer in OpenGL organized? I understand, how vertex arrays are passed to OpenGL, but I don't understand how to explain OpenGL, which vertex corresponds to which triangle. For example, I need to pass a square. How could this be done, using index buffers? Thank you in advance, Ilya.

PARTNERS