Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (804)
Games in Android Showcase (239)
games submitted by our members
Games in WIP (868)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
  JavaGaming.org - Pastebin



Author: CopyableCougar4 (posted 2016-06-25 16:56:52, viewed 980 times)

1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24   25   26   27   28   29   30   31   32   33   34   35   36   37   38   39   40   41   42   43   44   45   46   47   48   49   50   51   52   53   54   55   56   57   58   59   60   61   62   63   64   65   66   67   68   69   70   71   72   73   74   75   76   77   78   79   80   81   82   83   84   85   86   87   88   89   90   91   92   93   94   95   96   97   98   99   100   101   102   103   104   105  
package com.digiturtle.md5.skeleton;

import java.util.ArrayList;

import org.joml.Matrix4f;
import org.joml.Quaternionf;
import org.joml.Vector3f;

public class Joint {
   
   private JointID id;
   
   private ArrayList<Joint> children = new ArrayList<>();
   
   private JointTransform bindPose = new JointTransform(), localTransform, animationSequence = new JointTransform();
   
   private Matrix4f bindPoseMatrix = new Matrix4f(), invBindPoseMatrix = new Matrix4f(), boneMatrix = new Matrix4f();
   
   public Joint(JointID id) {
      this.id = id;
   }
   
   public JointID getID() {
      return id;
   }
   
   public ArrayList<Joint> getChildren() {
      return children;
   }
   
   public boolean equals(Object object) {
      return (object instanceof Joint) && ((Joint) object).id.equals(id);
   }
   
   public JointTransform getAnimationSequence() {
      return animationSequence;
   }

   public JointTransform getBindPose() {
      return bindPose;
   }

   public void computeBoneMatrix() {
      computeBoneMatrix(null);
   }
   
   public void computeBindPoseMatrix() {
      computeBindPoseMatrix(null);
   }
   
   private Vector3f translation = new Vector3f(), scale = new Vector3f();
   
   private Quaternionf orientation = new Quaternionf();
   
   private void computeBoneMatrix(Joint parent) {
      translation.set(animationSequence.getTranslation());
      orientation.set(animationSequence.getOrientation());
      scale.set(animationSequence.getScale());
      if (parent != null) {
         parent.orientation.transform(translation);
         translation.mul(parent.scale).add(parent.translation);
         parent.orientation.mul(orientation, orientation);
         scale.mul(parent.scale);
      }
      boneMatrix.translationRotateScale(translation, orientation, scale);
      // Keep this last line
      children.forEach(joint -> joint.computeBoneMatrix(this));
   }
   
   private void computeBindPoseMatrix(Joint parent) {
      translation.set(bindPose.getTranslation());
      orientation.set(bindPose.getOrientation());
      scale.set(bindPose.getScale());
      if (parent != null) {
         parent.orientation.transform(translation);
         translation.mul(parent.scale).add(parent.translation);
         parent.orientation.mul(orientation, orientation);
         scale.mul(parent.scale);
      }
      bindPoseMatrix.translationRotateScale(translation, orientation, scale).invert(invBindPoseMatrix);
      // Keep this last line
      children.forEach(joint -> joint.computeBindPoseMatrix(this));
   }
   
   public JointTransform getLocalTransform() {
      return localTransform;
   }

   public void setLocalTransform(JointTransform localTransform) {
      this.localTransform = localTransform;
   }

   public Matrix4f getBindPoseMatrix() {
      return bindPoseMatrix;
   }

   public Matrix4f getInvBindPoseMatrix() {
      return invBindPoseMatrix;
   }

   public Matrix4f getBoneMatrix() {
      return boneMatrix;
   }

}


1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24   25   26   27   28   29   30   31   32  
#version 150 core

uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform mat4 modelMatrix;

in vec3 in_Position;
in vec3 in_Normal;
in vec2 in_TextureCoord;
in vec4 in_BoneIndices;
in vec4 in_BoneWeights;

uniform mat4 boneMat[64];
uniform mat4 bindPose[64];

out vec2 pass_TextureCoord;

void main(void) {
   vec4 newVertex = vec4(0.0);
   vec4 newNormal = vec4(0.0);
   
   mat4 boneTransform = ((boneMat[int(in_BoneIndices.x)] * bindPose[int(in_BoneIndices.x)]) * in_BoneWeights.x) + 
                  ((boneMat[int(in_BoneIndices.y)] * bindPose[int(in_BoneIndices.y)]) * in_BoneWeights.y) + 
                  ((boneMat[int(in_BoneIndices.z)] * bindPose[int(in_BoneIndices.z)]) * in_BoneWeights.z) + 
                  ((boneMat[int(in_BoneIndices.w)] * bindPose[int(in_BoneIndices.w)]) * in_BoneWeights.w);
   
   newVertex = boneTransform * vec4(in_Position, 1.0);
   newNormal = boneTransform * vec4(in_Normal, 0.0);

   gl_Position = (projectionMatrix * viewMatrix * modelMatrix) * vec4(newVertex.xyz, 1.0);
   pass_TextureCoord = in_TextureCoord;
}


1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24   25   26   27   28   29   30   31   32   33   34   35   36   37   38   39   40   41   42   43   44   45   46   47   48   49   50   51   52   53   54   55   56   57   58   59   60   61   62   63   64   65   66   67   68   69   70   71   72   73   74   75   76   77   78   79   80   81   82   83   84   85   86   87   88   89   90   91   92   93   94  
package com.digiturtle.md5.skeleton;

import org.joml.Matrix4f;
import org.joml.Quaternionf;
import org.joml.Vector3f;

public class JointTransform {
   
   private Vector3f offset, scaling;
   
   private Quaternionf rotation;
   
   public JointTransform() {
      this(new Vector3f(0, 0, 0), new Vector3f(1, 1, 1), new Quaternionf(0, 0, 0, 1));
   }
   
   public JointTransform(Vector3f offset, Vector3f scaling, Quaternionf rotation) {
      this.offset = offset;
      this.scaling = scaling;
      this.rotation = rotation;
   }

   public Vector3f getTranslation() {
      return offset;
   }

   public Vector3f getScale() {
      return scaling;
   }

   public Quaternionf getOrientation() {
      return rotation;
   }
   
   public void invert() {
      offset.negate();
      rotation.conjugate();
      scaling.set(1f / scaling.x, 1f / scaling.y, 1f / scaling.z);
   }
   
   public void set(JointTransform source) {
      offset.x = source.offset.x;
      offset.y = source.offset.y;
      offset.z = source.offset.z;
      scaling.x = source.scaling.x;
      scaling.y = source.scaling.y;
      scaling.z = source.scaling.z;
      rotation.x = source.rotation.x;
      rotation.y = source.rotation.y;
      rotation.z = source.rotation.z;
      rotation.w = source.rotation.w;
   }
   
   public void reset() {
      offset.x = 0;
      offset.y = 0;
      offset.z = 0;
      scaling.x = 1;
      scaling.y = 1;
      scaling.z = 1;
      rotation.x = 0;
      rotation.y = 0;
      rotation.z = 0;
      rotation.w = 1;
   }
   
   public void computeMatrix(Matrix4f matrix) {
      matrix.translationRotateScale(offset, rotation, scaling);
   }
   
   public boolean isIdentity() {
      return offset.x == 0 && offset.y == 0 && offset.z == 0 && scaling.x == 1 && scaling.y == 1 && scaling.z == 1 && 
            rotation.x == 0 && rotation.y == 0 && rotation.z == 0 && rotation.w == 1;
   }
   
   public String toString() {
      return "JointTransform[" + offset + "\t" + rotation + "\t" + scaling + "]";
   }
   
   // Usage: start.lerp(end, t, destination);
   
   public void lerp(JointTransform end, float t, JointTransform destination) {
      offset.lerp(end.offset, t, destination.offset);
      rotation.slerp(end.rotation, t, destination.rotation);
      scaling.lerp(end.scaling, t, destination.scaling);
   }

   public void identity() {
      offset.zero();
      scaling.set(1, 1, 1);
      rotation.set(0, 0, 0, 1);
   }
   
}


1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24   25  
package com.digiturtle.md5.skeleton;

public class JointID {
   
   private String id;
   
   public JointID(String id) {
      this.id = id;
   }
   
   public int hashCode() {
      int hash = super.hashCode();
      hash = 31 * hash + id.hashCode();
      return hash;
   }
   
   public boolean equals(Object object) {
      return (object instanceof JointID) && ((JointID) object).id.equals(id);
   }
   
   public String toString() {
      return "JointID[" + id + "]";
   }

}





Dump your java code here :



Special syntax:
  • To highlight a line (yellow background), prefix it with '@@'
  • To indicate that a line should be removed (red background), prefix it with '-'
  • To indicate that a line should be added (green background), prefix it with '+'
  • To post multiple snippets, seperate them by '~~~~'
  EOF
 
Riven (521 views)
2019-09-04 15:33:17

hadezbladez (5494 views)
2018-11-16 13:46:03

hadezbladez (2396 views)
2018-11-16 13:41:33

hadezbladez (5754 views)
2018-11-16 13:35:35

hadezbladez (1217 views)
2018-11-16 13:32:03

EgonOlsen (4658 views)
2018-06-10 19:43:48

EgonOlsen (5667 views)
2018-06-10 19:43:44

EgonOlsen (3193 views)
2018-06-10 19:43:20

DesertCoockie (4093 views)
2018-05-13 18:23:11

nelsongames (5048 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!