How to read/adapt coding style that look like this

Started by
21 comments, last by TheChubu 10 years, 9 months ago


Actually, I believe those are coordinate planes as I am referring to the whole. His .x, .y, and .z are coordinates on those planes.

A 'coordinate plane' is the plane formed by each *pair* of axis.

Individually, the components on a vector are referred to as 'coordinates'.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Advertisement
[edit]
This post was completely wrong and helped no one. Just not my day today.
[/edit]

This is a C++ constructor:

Vec3.newTemp(target.x + target.xd * time, target.y + target.yd*time,target.z + target.zd * time);


It is equivalent to:
Vec3 newTemp;
newTemp.x = target.x + target.xd * time;
newTemp.y = target.y + target.yd * time;
newTemp.z = target.z + target.zd * time;

Except that it is Java, and it isn't equivalent.

warnexus appears to be correct, in that the result is never assigned to a variable.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Except that it is Java, and it isn't equivalent.


Ah. I missed that part (probably should watch the video now, huh?). I'm not familiar with Java, other than it is loosely based on C++.

Except that it is Java, and it isn't equivalent.


Ah. I missed that part (probably should watch the video now, huh?). I'm not familiar with Java, other than it is loosely based on C++.

I'd say its more based on plain C while trying to come up with the OO aspect on its own rather than basing it on C++ (hence no :: or -> operator, abstract instead of virtual, interfaces and so on).

At first I thought that it was a Vec3 from LWJGL default types but it isnt. I have no idea what that Vec3.nevTemp does (it looks like "nev" instead of "new" to me).

If it returns a new Vec3, then it isn't getting assigned to anything. And if it doesn't returns a new Vec3, it looks like a global static method that does something on other static stuff. Which kinda looks ugly since if other thread dares to touch the same Vec3 static, bad things could happen.

I guess it depends on experience? I looked at that line and it made perfect sense to me. "Vec3" tells me to expect x,y and z coordinates. A "d" in the variable name tells me it is a delta variable. He's constructing a new vector from an old vector, while translating it by delta values scaled by time. Without looking at the video, I would say this is part of a 3D animation system.

Where is the new vector going? It's not assigning a return value to anything. I wonder, is in unfinished code, or does Minecraft have global / thread local temp variables to avoid allocations?

As far as I know, in Java, if something is static, its static to that class in that applicaton, so no "thread globals" (unless I misunderstood what you're saying).

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator


A 'coordinate plane' is the plane formed by each *pair* of axis.



Individually, the components on a vector are referred to as 'coordinates'.

Coordinate Planes*. My mistake.

Nevermind...

I guess it depends on experience? I looked at that line and it made perfect sense to me. "Vec3" tells me to expect x,y and z coordinates. A "d" in the variable name tells me it is a delta variable. He's constructing a new vector from an old vector, while translating it by delta values scaled by time. Without looking at the video, I would say this is part of a 3D animation system.

Yeah it would depend on experience. I'm still a CS undergraduate in my senior year. Never been exposed to the production environment.


This is a C++ constructor:

But he is coding in Java not C++.

Based on coding convention, newTemp looks more like a static method with 3 parameters of his Vec3 class.

Right?

Yeah, ignore me today. I don't know why, but I'm not at my best today. I was off am nearly every count.

As far as I know, in Java, if something is static, its static to that class in that applicaton, so no "thread globals" (unless I misunderstood what you're saying).

This what I meant by thread local (not to imply I have any idea how Vec3.newTemp is really implemented):


public class Vec3 {
 
public Vec3() {
    x = y = z = 0.0f;
}
 
private float x, y, z;
 
private static final ThreadLocal<Vec3> temp = new ThreadLocal<Vec3>() {
    @Override protected Vec3 initialValue() {
        return new Vec3();
    }
};
 
public static void newTemp(float x, float y, float z)
{
    Vec3 v = temp.get();
    v.x = x;
    v.y = y;
    v.z = z;
}
}
 

This topic is closed to new replies.

Advertisement