Laravel login using username or email

Laravel comes with their own auth system, so you don’t have to build login, registration, and authentication system from scratch.

By default, Laravel uses email for authentication. If you want to use username, you have to make little tweak to your controller as explained in their documentation.

But, what if you want to use either email or username for authentication? In this post, I’ll show you how to do that.

Continue reading Laravel login using username or email

Using ADB through WIFI for Android Development

Most of the time, I use emulator for android development. But, using emulator can eat my memory and slowing down my development. Doesn’t help that the fact that Android Studio also take most of my desktop resource.

Real device deployment is way to go. But, sometimes dealing with USB cable is not pleasant experience. So, the solution is using WiFi to connect with my device.

Continue reading Using ADB through WIFI for Android Development

Snap vector direction to nearest axis

I have this case when I need to get my character direction is snapped to the nearest axis. Kinda look like this.

My solution is to find the largest axis absolute value of axis. Then, change the largest one to 1 and the others 2 with 0. Change largest axis sign with its original sign.

Example, we have Vector3(-0.5f, 0.1f, 0). The snapped direction is Vector3(-1,0,0).

Vector3 SnappedToNearestAxis(Vector3 direction){
    float x = Abs(direction.x);
    float y = Abs(direction.y);
    float z = Abs(direction.z);
    if (x > y && x > z){
        return Vector3(Sign(direction.x),0,0);
    } else if (y > x && y > z){
        return Vector3(0,Sign(direction.y),0);
    } else {
        return Vector3(0,0,Sign(direction.z));
    }
}

How to get reflection vector?

Reflection Vector

This is one of the problems I encounter often. It might be useful to put solution here.
If you are in hurry or don’t need any explanation, I’ll just leave solution below.

v2 = v1 – 2(v1.n)n

v1.n is dot product & n must be normalized.

Vector3 ReflectVector(Vector3 inputVector, Vector3 normal) {
    float dn = 2 * inputVector.DotProduct(normal);
    return inputVector - normal * dn;
}
Continue reading How to get reflection vector?