Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Martin Perry

Member Since 23 Feb 2012
Offline Last Active Apr 23 2015 12:44 AM

Topics I've Started

WinAPI - Raw input and mouse acceleration

06 March 2015 - 01:22 AM

I am using RAW input. All is working correctly, if I disable mouse acceleration. But that is not really a user-friendly solution. How can I use raw input with mouse acceleration? I mean, how to multilply retrieved values to get the same effect as windows primary do?

 

Second approach would be to disable acceleration only for my application. I kind of already tried that, but I dont like this solution. When app crash, default values are not set back and acceleration stays turned off.


Drag object with mouse - lock axis

01 January 2015 - 05:20 AM

I have created object draging by mouse. I am using this code to calculate dx, dy in screen space

 

pos = object position in world space

    float objDistCam = pos.Distance(this->camera->GetPosition());

    MyMath::Vector4 P = MyMath::Vector4(0, 0, objDistCam, 1.0f);
    MyMath::Vector4 S = MyMath::Vector4::Transform(P, this->camera->GetCameraMatrices()->projectionMatrix);
    S *= 1.0f / S.W;


    MyMath::Vector4  S2 = S;
    S2.X = S2.X + (((float)-pointBasedControl->GetChangeX()) / (this->camera->GetViewport()->Width * 0.5f));
    S2.Y = S2.Y + (((float)pointBasedControl->GetChangeY()) / (this->camera->GetViewport()->Height * 0.5f));



    MyMath::Matrix4x4 inv = MyMath::Matrix4x4::Invert(this->camera->GetCameraMatrices()->projectionMatrix);
    MyMath::Vector4 P2 = MyMath::Vector4::Transform(S2, inv);
    P2 *= 1.0f / P2.W;


    dx = P.X - P2.X;
    dy = P.Y - P2.Y;

Final object position is calculated like this

pos += camera_right * dx + camera_up * dy;

Now, this works.

 

If I lock single axis, lets say X (pos.X += camera_right.X * dx + camera_up.X * dy), it wors as well. Problem is, if axis system is not aligned with world axis and object is rotated. Then this leads to object moving in "world" X axis, not in "object" one. How to correct this?


Bezier triangle partial second-order derivatives

27 December 2014 - 11:30 AM

I am using this article: http://www.gamasutra.com/view/feature/131389/b%C3%A9zier_triangles_and_npatches.php?print=1 and this topic: http://www.gamedev.net/topic/624397-bezier-triangle-partial-derivatives/

 

So far, I have first-order derivates of bezier triangle patch. But hot to calculate second one?

 

In some article, I have found this:

 

Attached File  Clipboard02.png   50.81KB   1 downloads

 

But I am not sure, if it is correct - for example, third sum in Fuu seems incorrect with (i - 1).


Isometric game and 2D or 3D characters

03 November 2014 - 04:07 AM

I am doing some isometric game. I am using combination of 3D (mostly terrain) / 2D (details) for world graphics. Now I have moved to characters, like player, enemies etc.

 

Should I use 3D skinned mesh or set of 2D sprites. I can see advantages and disadvantages for both ways, but dont exactly know, what is better solution.


View space spot-light move with camera

18 October 2014 - 05:31 AM

I have spot light calculated in view space. I had it working in World Space, but now If I put camera in the same position as light, it is working. But if I start moving camera around, light start to rotates.

 

I have so far "hard coded" everything in fragment shader. WorldMatrix is Identity.

vec3 vNormalVS = (vec4(vNormalWS, 0.0) * (en_mViewInvTransposed)).xyz;

vec4 vPosVS = vec4(vPosWS.xyz, 1.0) * en_mView;

vec4 lightPosVS = vec4(en_spotLight.vPointWS.xyz, 1.0) * en_mView;
vec4 lightDirVS = vec4(en_spotLight.vDirWS.xyz, 1.0) * en_mView;

vPhong = CalcSpotLight(
  vec3(10.0, 10.0, 10.0),
  vPosVS.xyz,
  en_spotLight.vColor,
  lightPosVS.xyz,
  normalize(lightDirVS.xyz),
  en_spotLight.vAtt.xyz,
  en_spotLight.fFallOffCos,
  mat,
  normalize(vNormalVS));

Now, I am just doing simple fallOff

vec4 CalcSpotLight(vec3 vIntensity, vec3 vPos,
                  vec4 vLColor, vec3 vLPos, vec3 vLDir, vec3 vAtt, float fFallOffCos,
                  Material mat, vec3 vNormal)
{
    
    vec3 vLightToPixel = normalize(vPos - vLPos);
    float fSpotFactor = dot(vLightToPixel, vLDir);
    
        
    if (fSpotFactor > fFallOffCos)
    {
        return vec4(1,0,0,0);
        
        //vec4 vColor = CalcPointLight(vIntensity, vPos, vLColor, vLPos, vAtt, mat, vNormal);
    
        //return vColor * (1.0 - (1.0 - fSpotFactor) * 1.0 / (1.0 - fFallOffCos));
    }
    
    return vec4(0,1,0,0);    
}

But even this is not working and red / green color are moving along with camera. If I put camera into light position, all is correct. It is probably something stupid, but after half a day, I am really lost :-(

 

I have tested vPosVS and result seems correct (4 color quad centered at screen center).


PARTNERS