Java-Gaming.org Hi !
Featured games (88)
games approved by the League of Dukes
Games in Showcase (681)
Games in Android Showcase (196)
games submitted by our members
Games in WIP (744)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 [2] 3 4 ... 10
 11 
 on: 2016-06-25 17:37:37 
Started by Hydroque - Last post by ziozio
So where's your latest code then? Can we take a peek?

 12 
 on: 2016-06-25 16:58:42 
Started by CopyableCougar4 - Last post by CopyableCougar4
So I realized that I was only factoring in the bind pose matrix and not the animated matrix, but everything is still looking distorted. Since much of the code works fine until the model is animated, I *think* I can narrow down my problem to a few snippets.

They can be found here: http://pastebin.java-gaming.org/cf0c4276d4313

Also, in case this is relevant, this is how I determine the initial positions to send to the shader:
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  
for (int idx = 0; idx < submesh.getVertices().length; idx++) {
         com.digiturtle.md5.skeleton.Vertex vertex = submesh.getVertices()[idx];
         AnimatedVertex animatedVertex = new AnimatedVertex();
         Vector3f position = new Vector3f().zero();
         Vector3f normal = new Vector3f().zero();
         Vector2f textureCoords = new Vector2f().zero();
         float[] boneWeightsArray = { 0, 0, 0, 0 };
         float[] boneIndicesArray = { 0, 0, 0, 0 };
         Vector3f tmpPos = new Vector3f(), tmpPos2 = new Vector3f();
         textureCoords.set(vertex.getTextureCoords());
         for (int j = 0; j < 4 && j < vertex.getWeightCount(); j++) {
            // position += (joint_position + (joint_orientation * weight_position)) * weight_bias
            Weight weight = submesh.getWeights().get(vertex.getStartWeight() + j);
            Joint joint = skeleton.getJoints().get(weight.getJointIndex());
            tmpPos.set(weight.getPosition()).rotate(joint.getLocalTransform().getOrientation());
            tmpPos2.set(tmpPos).add(joint.getLocalTransform().getTranslation()).mul(weight.getWeightBias());
            position.add(tmpPos2);
            boneIndicesArray[j] = (float) weight.getJointIndex();
            boneWeightsArray[j] = weight.getWeightBias();
         }
         animatedVertex.setPosition(position.x, position.y, position.z);
         animatedVertex.setNormal(normal.x, normal.y, normal.z);
         animatedVertex.setTextureCoord(textureCoords.x, textureCoords.y);
         animatedVertex.setBoneWeights(boneWeightsArray[0], boneWeightsArray[1], boneWeightsArray[2], boneWeightsArray[3]);
         animatedVertex.setBoneIndices(boneIndicesArray[0], boneIndicesArray[1], boneIndicesArray[2], boneIndicesArray[3]);
         geometry.put(animatedVertex.getData());
      }


 13 
 on: 2016-06-25 16:24:21 
Started by shadowstryker - Last post by theagentd
And they also do texture atlases. So you got 1154 * texture and limited by units and ram.
No, the whole point of texture arrays is to NOT have texture atlases, as they don't handle filtering well (individual textures bleed together). Texture arrays do not have that problem.

 14 
 on: 2016-06-25 14:49:02 
Started by TritonDreyja - Last post by TritonDreyja
Lol just wait till I add bears lol.
Tbh the bunny was a homeage to Terraria. I mean it's only what motivated me to make something myself.

Thanks ags1, the art style and look were an experiment for me, and they seem to be fitting Tongue

 15 
 on: 2016-06-25 14:33:03 
Started by TritonDreyja - Last post by ags1
I watched the video, it's not my kind of game but it looks very smooth and elegant.

 16 
 on: 2016-06-25 14:31:06 
Started by TritonDreyja - Last post by Hydroque
Terraria has bunnies. Lol

 17 
 on: 2016-06-25 13:52:50 
Started by TritonDreyja - Last post by TritonDreyja
You added a bunny lol
The bunny isn't what's important, It's the fact that the Mob superclass is working properly. Now I can just spit out mobs
as long as i have graphics. Minus the crazy flying ones that shoot projectiles though.

 18 
 on: 2016-06-25 11:13:34 
Started by TritonDreyja - Last post by Hydroque
Also, the enemies won't be zombies and skeletons like all those other sandbox games... I really am wondering why someone hasn't broken the trend Tongue
You added a bunny lol

 19 
 on: 2016-06-25 06:31:55 
Started by CopyableCougar4 - Last post by Stranger
Hi.

I worked few years ago on the same problem.
I post fragments of my code. Maybe this will help.

Joint.java

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  
public class Joint implements NamedObject
{
    public final int NULL_PARENT = -1;

    private final short parentIndex;
    private final String name;
    private final Vector3f bindTranslation;
    private final Quaternion4f bindRotation;
    private final Tuple3f bindScale;

    private final Matrix4f invBindPoseMatrix;

    private short index;
    private boolean isAux;

    public final boolean hasParent()
    {
        return ( index > 0 );
    }

    public final void calcInvBindPoseMatrix( Joint parent )
    {
        Matrix4f m = Matrix4f.fromPool();

        MathUtils.compose( bindTranslation, bindRotation, bindScale, m );
        invBindPoseMatrix.invert( m );
        if( parent != null )
        {
            invBindPoseMatrix.mul( invBindPoseMatrix, parent.getInvBindPoseMatrix() );
        }

        Matrix4f.toPool( m );
    }
    public Joint( String name, short index, Joint parent, Transform bindTransform, boolean isAux )
    {
        this.parentIndex = parent == null ? NULL_PARENT : parent.getIndex();
        this.name = name;
        this.index = index;
        bindTranslation = bindTransform.getTranslation( null ).getReadOnly();
        bindRotation = bindTransform.getRotation( null ).getReadOnly();
        bindScale = bindTransform.getScale( null ).getReadOnly();

        invBindPoseMatrix = new Matrix4f();
        calcInvBindPoseMatrix( parent );
        this.isAux=isAux;
    }

    public Joint( Joint joint, Joint parent )
    {
        this.parentIndex = parent == null ? NULL_PARENT : parent.getIndex();
        name = joint.name;
        index = joint.index;

        bindTranslation = joint.bindTranslation;
        bindRotation = joint.bindRotation;
        bindScale = joint.bindScale;

        invBindPoseMatrix = joint.invBindPoseMatrix;
    }
}


SkinnedMeshUpdater.java

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  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
191  
192  
193  
194  
195  
196  
197  
198  
199  
200  
201  
202  
203  
204  
205  
206  
207  
208  
209  
210  
211  
212  
213  
214  
215  
216  
217  
218  
219  
220  
221  
222  
223  
224  
225  
226  
227  
228  
229  
230  
231  
232  
233  
234  
235  
236  
237  
238  
239  
240  
241  
242  
243  
244  
245  
246  
247  
248  
249  
250  
251  
252  
253  
254  
255  
256  
257  
258  
259  
260  
261  
262  
263  
264  
265  
266  
267  
268  
269  
270  
271  
272  
273  
274  
275  
276  
277  
278  
279  
280  
281  
282  
283  
public class SkinnedMeshUpdater
{  
    private static Map<Skeleton, SkinnedMeshUpdater> skeletonToUpdater = new HashMap<Skeleton, SkinnedMeshUpdater>();
    private final Skeleton skeleton;
    private final Shape3D[] shapes;

    private final float[][] weights;
    private final short[][] jointIndices;

    private float[][] bindPoseCoords;
    private float[][] bindPoseNormals;

    private final int[] influencesPerVertex;

    private final Vector3f[] worldTranslations;
    private final Quaternion4f[] worldRotations;
    private final Tuple3f[] worldScales;

    private Matrix4f[] matrixPalette;

    public Skeleton getSkeleton()
    {
        return skeleton;
    }

    public Shape3D[] getTarget()
    {
        return shapes;
    }

    public float[][] getWeights()
    {
        return weights;
    }

    public short[][] getJointIndices()
    {
        return jointIndices;
    }

    public int[] getInfluencesPerVertex()
    {
        return influencesPerVertex;
    }

    public static SkinnedMeshUpdater create( Skeleton skeleton,
                                             Shape3D[] target,
                                             float[][] weights,
                                             short[][] jointIndices,
                                             int[] influencesPerVertex )
    {
        SkinnedMeshUpdater smu = skeletonToUpdater.get( skeleton );
        if( smu == null )
        {
            smu = new SkinnedMeshUpdater( skeleton, target, weights, jointIndices, influencesPerVertex );
        }

        return ( smu );
    }

    public void update( IAnimationData data )
    {
        if( data == null )
        {
            return;
        }
        updateSkeleton( data );
        for( int i = 0; i < shapes.length; i++ )
        {
            updateGeometry( i );
        }
    }

    private void updateSkeleton( IAnimationData data )
    {
        SkeletalKeyFrame pose = ( SkeletalKeyFrame ) data;
        Skeleton skeleton = pose.getSkeleton();
        for( int i = 0, jc = skeleton.getJointsCount(); i < jc; i++ )
        {
            Joint joint = skeleton.getJoint( i );
            setAbsolutes( joint, pose );
            short ji = joint.getIndex();
            if( joint.isAux() )
            {
                matrixPalette[ ji ].setIdentity();
            }
            else
            {
                mul( joint.getInvBindPoseMatrix(),
                        worldTranslations[ ji ],
                        worldRotations[ ji ],
                        worldScales[ ji ],

                        matrixPalette[ ji ]
                );
            }
        }
    }

    private void updateGeometry( int shapeIdx )
    {
        Shape3D shape = shapes[ shapeIdx ];
        Geometry geom = shape.getGeometry();
        float[] bindPoseCoords = this.bindPoseCoords[ shapeIdx ];
        float[] bindPoseNormals = this.bindPoseNormals[ shapeIdx ];
        int influencesPerVertex = this.influencesPerVertex[ shapeIdx ];
        float[] weights = this.weights[ shapeIdx ];
        short[] jointIndices = this.jointIndices[ shapeIdx ];

        float x, y, z;
        float nX = 0, nY = 0, nZ = 0;
        float vSumX, vSumY, vSumZ;
        float nSumX, nSumY, nSumZ;
        float tmpX, tmpY, tmpZ;

        for( int i = 0; i < geom.getVertexCount(); i++ )
        {
            x = bindPoseCoords[ i * 3 ];
            y = bindPoseCoords[ i * 3 + 1 ];
            z = bindPoseCoords[ i * 3 + 2 ];
            if( geom.hasNormals() )
            {
                nX = bindPoseNormals[ i * 3 ];
                nY = bindPoseNormals[ i * 3 + 1 ];
                nZ = bindPoseNormals[ i * 3 + 2 ];
            }
            vSumX = 0f;
            vSumY = 0f;
            vSumZ = 0f;

            nSumX = 0f;
            nSumY = 0f;
            nSumZ = 0f;

            float wSum = 0f;
            float weight;
            for( int j = 0; j < influencesPerVertex; j++ )
            {
                if( j != influencesPerVertex - 1 )
                {
                    weight = weights[ i * ( influencesPerVertex - 1 ) + j ];
                    wSum += weight;
                }
                else
                {
                    weight = 1 - wSum;
                }
                if( weight == 0f )
                {
                    continue;
                }
                final int jointIndex = jointIndices[ i * influencesPerVertex + j ];
                if( jointIndex == 0 )
                {
                    JAGTLog.debug( "jindex=0, influencesPerVertex=", influencesPerVertex );
                }
                Matrix4f m = matrixPalette[ jointIndex ];
                //vertices
                tmpX = m.m00() * x + m.m01() * y + m.m02() * z + m.m03();
                tmpY = m.m10() * x + m.m11() * y + m.m12() * z + m.m13();
                tmpZ = m.m20() * x + m.m21() * y + m.m22() * z + m.m23();

                vSumX += tmpX * weight;
                vSumY += tmpY * weight;
                vSumZ += tmpZ * weight;

                //normals
                if( geom.hasNormals() )
                {
                    tmpX = m.m00() * nX + m.m01() * nY + m.m02() * nZ;
                    tmpY = m.m10() * nX + m.m11() * nY + m.m12() * nZ;
                    tmpZ = m.m20() * nX + m.m21() * nY + m.m22() * nZ;

                    nSumX += tmpX * weight;
                    nSumY += tmpY * weight;
                    nSumZ += tmpZ * weight;
                }
            }

            geom.setCoordinateWithoutOpenGlHandling( i, vSumX, vSumY, vSumZ );
            if( geom.hasNormals() )
            {
                geom.setNormalWithoutOpenGlHandling( i, nSumX, nSumY, nSumZ );
            }
        }
        geom.setBoundsDirty();
        geom.getOpenGLReference_DL_GeomData().invalidateNames();
        geom.getOpenGLReference_DL().invalidateNames();

        shape.updateBounds( false );
    }

    private static void mul( Matrix4f matrix, Vector3f translation, Quaternion4f rotation, Tuple3f scale, Matrix4f out )
    {
        //out.set( matrix );
        Matrix4f tmp = Matrix4f.fromPool();

        tmp.setIdentity();
        tmp.setTranslation( translation );
        out.set( tmp );

        tmp.set( rotation );
        out.mul( tmp );

        tmp.setIdentity();
        tmp.m00( scale.getX() );
        tmp.m11( scale.getY() );
        tmp.m22( scale.getZ() );
        out.mul( tmp );

        out.mul( matrix/* , out */ );

        Matrix4f.toPool( tmp );
    }

    //doesn't work  when non-uniform scales
    private void setAbsolutes( Joint joint, SkeletalKeyFrame frame )
    {
        if( joint.hasParent() )
        {
            short parentIndex = joint.getParentIndex();
            short localIndex = joint.getIndex();
            MathUtils.mul(
                    worldTranslations[ parentIndex ],
                    worldRotations[ parentIndex ],
                    worldScales[ parentIndex ],

                    frame.getTranslations()[ localIndex ],
                    frame.getRotations()[ localIndex ],
                    frame.getScales()[ localIndex ],

                    worldTranslations[ localIndex ],
                    worldRotations[ localIndex ],
                    worldScales[ localIndex ]
            );
        }
        else
        {
            short localIndex = joint.getIndex();
            worldTranslations[ localIndex ].set( frame.getTranslations()[ localIndex ] );
            worldRotations[ localIndex ].set( frame.getRotations()[ localIndex ] );
            worldScales[ localIndex ].set( frame.getScales()[ localIndex ] );
        }
    }

    public SkinnedMeshUpdater( Skeleton skeleton, Shape3D[] target, float[][] weights, short[][] jointIndices, int[] influencesPerVertex )
    {
        this.skeleton = skeleton;
        this.shapes = target;
        this.weights = weights;
        this.jointIndices = jointIndices;
        this.influencesPerVertex = influencesPerVertex;

        worldTranslations = new Vector3f[ skeleton.getJointsCount() ];
        worldRotations = new Quaternion4f[ skeleton.getJointsCount() ];
        worldScales = new Tuple3f[ skeleton.getJointsCount() ];
        matrixPalette = new Matrix4f[ skeleton.getJointsCount() ];

        for( int i = 0; i < worldTranslations.length; i++ )
        {
            worldTranslations[ i ] = new Vector3f();
            worldRotations[ i ] = new Quaternion4f();
            worldScales[ i ] = new Tuple3f();
            matrixPalette[ i ] = new Matrix4f();
        }

        bindPoseCoords = new float[ target.length ][];
        bindPoseNormals = new float[ target.length ][];

        for( int i = 0; i < target.length; i++ )
        {
            int numVertices = target[ i ].getGeometry().getVertexCount();
            Geometry geom = target[ i ].getGeometry();
            bindPoseCoords[ i ] = new float[ numVertices * 3 ];
            geom.getCoordinates( 0, bindPoseCoords[ i ] );
            if( geom.hasNormals() )
            {
                bindPoseNormals[ i ] = new float[ numVertices * 3 ];
                geom.getNormals( 0, bindPoseNormals[ i ] );
            }
        }
    }
}


 20 
 on: 2016-06-25 04:10:26 
Started by TritonDreyja - Last post by TritonDreyja
So this is cool but how is it going to be different / better from Terraria? Also, it's very slow on my computer.. and my computer is no slouch.

The latest available download is from a year ago... that explains the performance lol. The new port is way easier on the graphics card, and made my PC perform this at ridiculous framerates, so your problems will be fixed with the next release Smiley

Other than that, this game will be different (idk about better) than Terraria because this game will highlight RPG elements. It will have a storyline that requires mob grinding and stat managing to complete. It will have interactions, conversations and outcomes based on quests and stuff. The 3 underground biomes will be really original and they will not dissapoint any player, I promise you that Wink

Other than that, I'll still have pride in saying I created everything for this game. Soundtrack, graphics, programming, ideas, all of it is from me. And in my mind, that is what will really make it great.

Also, the enemies won't be zombies and skeletons like all those other sandbox games... I really am wondering why someone hasn't broken the trend Tongue

Pages: 1 [2] 3 4 ... 10
 
CopyableCougar4 (13 views)
2016-06-25 16:56:52

Hydroque (51 views)
2016-06-22 02:17:53

SwampChicken (52 views)
2016-06-20 13:22:57

SwampChicken (52 views)
2016-06-20 13:22:49

SwampChicken (48 views)
2016-06-20 13:22:26

Hydroque (89 views)
2016-06-15 08:22:50

Hydroque (81 views)
2016-06-13 06:40:55

DarkCart (199 views)
2016-05-29 02:30:33

Hydroque (168 views)
2016-05-26 14:45:46

Mac70 (171 views)
2016-05-24 21:16:33
Making a Dynamic Plugin System
by Hydroque
2016-06-25 00:13:25

Java Data structures
by BinaryMonkL
2016-06-13 21:22:09

Java Data structures
by BinaryMonkL
2016-06-13 21:20:42

FPS Camera Tutorial
by Hydroque
2016-05-22 05:40:58

Website offering 3D Models specifically for games for free
by vusman
2016-05-18 17:23:09

Website offering 3D Models specifically for games for free
by vusman
2016-05-09 08:50:56

Website offering 3D Models specifically for games for free
by vusman
2016-05-06 11:10:21

Website offering 3D Models specifically for games for free
by vusman
2016-04-29 12:56:17
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!