Sie sind nicht angemeldet.

colombus

Piratenschreck

  • »colombus« ist der Autor dieses Themas

Beiträge: 566

Registrierungsdatum: 7. Mai 2016

  • Nachricht senden

1

Sonntag, 18. Juli 2010, 09:07

programmer quelle code wie benützlich....

hallo!

Also hier, sowie ich kein programmer bin, werde ich mal, in den Begeisterte Programmer Hilfe leisten.
So dass sie ihren Augen Groß offen halten können, für zu Verstehen, wass als programmation stuffe sie erwartet, in dem fall dass sie für ein spiel wollen tools bearbeiten.

Also zu erst, als Quellecode.
ein Loader für 3DS file zu loaden.
hier die programmation handelt sich um C++
Aber vergisst nicht, hier handelt es sich um ein alte quellecode (2001) also es sind sicher änderungen eingetretten, aber die Base bleibt weiterhin die Base.
und so, als test, kann ja mal einer Versuchen ob das program die neue 3DS file hochladet, oder ob es fehler eintretten.

Quellcode

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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
# //***********************************************************************//
# // //
# // - "Talk to me like I'm a 3 year old!" Programming Lessons - //
# // //
# // $Author: DigiBen digiben@gametutorials.com //
# // $Program: 3DS Loader //
# // $Description: Demonstrates how to load a .3ds file format //
# // $Date: 10/6/01 //
# // //
# //***********************************************************************//
#
# #include <math.h>
# #include "3ds.h"
#
# // This file handles all of the code needed to load a .3DS file.
# // Basically, how it works is, you load a chunk, then you check
# // the chunk ID. Depending on the chunk ID, you load the information
# // that is stored in that chunk. If you do not want to read that information,
# // you read past it. You know how many bytes to read past the chunk because
# // every chunk stores the length in bytes of that chunk.
#
# ///////////////////////////////// CLOAD3DS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
# /////
# ///// This constructor initializes the tChunk data
# /////
# ///////////////////////////////// CLOAD3DS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
#
# CLoad3DS::CLoad3DS()
# {
# m_CurrentChunk = new tChunk; // Initialize and allocate our current chunk
# m_TempChunk = new tChunk; // Initialize and allocate a temporary chunk
# }
#
# ///////////////////////////////// IMPORT 3DS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
# /////
# ///// This is called by the client to open the .3ds file, read it, then clean up
# /////
# ///////////////////////////////// IMPORT 3DS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
#
# bool CLoad3DS::Import3DS(t3DModel *pModel, const char *strFileName)
# {
# char strMessage[255] = {0};
#
# // Open the 3DS file
# m_FilePointer = fopen(strFileName, "rb");
#
# // Make sure we have a valid file pointer (we found the file)
# if(!m_FilePointer)
# {
# // sprintf(strMessage, "Unable to find the file: %s!", strFileName);
# // cout << strMessage << endl;
# return false;
# }
#
# // Once we have the file open, we need to read the very first data chunk
# // to see if it's a 3DS file. That way we don't read an invalid file.
# // If it is a 3DS file, then the first chunk ID will be equal to PRIMARY (some hex num)
#
# // Read the first chuck of the file to see if it's a 3DS file
# ReadChunk(m_CurrentChunk);
#
# // Make sure this is a 3DS file
# if (m_CurrentChunk->ID != __H3DS__PRIMARY)
# {
# // sprintf(strMessage, "Unable to load PRIMARY chuck from file: %s!", strFileName);
# // cout << strMessage << endl;
# return false;
# }
#
# // Now we actually start reading in the data. ProcessNextChunk() is recursive
#
# // Begin loading objects, by calling this recursive function
# ProcessNextChunk(pModel, m_CurrentChunk);
#
# // After we have read the whole 3DS file, we want to calculate our own vertex normals.
# ComputeNormals(pModel);
#
# // Clean up after everything
# CleanUp();
#
# return true;
# }
#
# ///////////////////////////////// CLEAN UP \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
# /////
# ///// This function cleans up our allocated memory and closes the file
# /////
# ///////////////////////////////// CLEAN UP \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
#
# void CLoad3DS::CleanUp()
# {
#
# fclose(m_FilePointer); // Close the current file pointer
# delete m_CurrentChunk; // Free the current chunk
# delete m_TempChunk; // Free our temporary chunk
# }
#
#
# ///////////////////////////////// PROCESS NEXT CHUNK\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
# /////
# ///// This function reads the main sections of the .3DS file, then dives deeper with recursion
# /////
# ///////////////////////////////// PROCESS NEXT CHUNK\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
#
# void CLoad3DS::ProcessNextChunk(t3DModel *pModel, tChunk *pPreviousChunk)
# {
# t3DObject newObject = {0}; // This is used to add to our object list
# tMaterialInfo newTexture = {0}; // This is used to add to our material list
# unsigned int version = 0; // This will hold the file version
# int buffer[50000] = {0}; // This is used to read past unwanted data
#
# m_CurrentChunk = new tChunk; // Allocate a new chunk
#
# // Below we check our chunk ID each time we read a new chunk. Then, if
# // we want to extract the information from that chunk, we do so.
# // If we don't want a chunk, we just read past it.
#
# // Continue to read the sub chunks until we have reached the length.
# // After we read ANYTHING we add the bytes read to the chunk and then check
# // check against the length.
# while (pPreviousChunk->bytesRead < pPreviousChunk->length)
# {
# // Read next Chunk
# ReadChunk(m_CurrentChunk);
#
# // Check the chunk ID
# switch (m_CurrentChunk->ID)
# {
# case __H3DS__VERSION3DS: // This holds the version of the file
#
# // This chunk has an unsigned short that holds the file version.
# // Since there might be new additions to the 3DS file format in 4.0,
# // we give a warning to that problem.
#
# // Read the file version and add the bytes read to our bytesRead variable
# m_CurrentChunk->bytesRead += fread(&version, 1, m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_FilePointer);
#
# // If the file version is over 3, give a warning that there could be a problem
# // if (version > 0x03)
# // cout << "This 3DS file is over version 3 so it may load incorrectly" << endl;
# break;
#
# case __H3DS__OBJECTINFO: // This holds the version of the mesh
#
# // This chunk holds the version of the mesh. It is also the head of the MATERIAL
# // and OBJECT chunks. From here on we start reading in the material and object info.
#
# // Read the next chunk
# ReadChunk(m_TempChunk);
#
# // Get the version of the mesh
# m_TempChunk->bytesRead += fread(&version, 1, m_TempChunk->length - m_TempChunk->bytesRead, m_FilePointer);
#
# // Increase the bytesRead by the bytes read from the last chunk
# m_CurrentChunk->bytesRead += m_TempChunk->bytesRead;
#
# // Go to the next chunk, which is the object has a texture, it should be MATERIAL, then OBJECT.
# ProcessNextChunk(pModel, m_CurrentChunk);
# break;
#
# case __H3DS__MATERIAL: // This holds the material information
#
# // This chunk is the header forthe material info chunks
#
# // Increase the number of materials
# pModel->numOfMaterials++;
#
# // Add a empty texture structure to our texture list.
# // If you are unfamiliar with STL's "vector" class, all push_back()
# // does is add a new node onto the list. I used the vector class
# // so I didn't need to write my own link list functions.
# pModel->pMaterials.push_back(newTexture);
#
# // Proceed to the material loading function
# ProcessNextMaterialChunk(pModel, m_CurrentChunk);
# break;
#
# case __H3DS__OBJECT: // This holds the name of the object being read
#
# // This chunk is the header forthe object info chunks. It also
# // holds the name of the object.
#
# // Increase the object count
# pModel->numOfObjects++;
#
# // Add a new tObject node to our list of objects (like a link list)
# pModel->pObject.push_back(newObject);
#
# // Initialize the object and all it's data members
# memset(&(pModel->pObject[pModel->numOfObjects - 1]), 0, sizeof(t3DObject));
#
# // Get the name of the object and store it, then add the read bytes to our byte counter.
# m_CurrentChunk->bytesRead += GetString(pModel->pObject[pModel->numOfObjects - 1].strName);
#
# // Now proceed to read in the rest of the object information
# ProcessNextObjectChunk(pModel, &(pModel->pObject[pModel->numOfObjects - 1]), m_CurrentChunk);
# break;
#
# case __H3DS__EDITKEYFRAME:
#
# // Because I wanted to make this a SIMPLE tutorial as possible, I did not include
# // the key frame information. This chunk is the header forall the animation info.
# // In a later tutorial this will be the subject and explained thoroughly.
#
# //ProcessNextKeyFrameChunk(pModel, m_CurrentChunk);
#
# // Read past this chunk and add the bytes read to the byte counter
# m_CurrentChunk->bytesRead += fread(buffer, 1, m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_FilePointer);
# break;
#
# default:
#
# // If we didn't care about a chunk, then we get here. We still need
# // to read past the unknown or ignored chunk and add the bytes read to the byte counter.
# m_CurrentChunk->bytesRead += fread(buffer, 1, m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_FilePointer);
# break;
# }
#
# // Add the bytes read from the last chunk to the previous chunk passed in.
# pPreviousChunk->bytesRead += m_CurrentChunk->bytesRead;
# }
#
# // Free the current chunk and set it back to the previous chunk (since it started that way)
# delete m_CurrentChunk;
# m_CurrentChunk = pPreviousChunk;
# }
#
#
# ///////////////////////////////// PROCESS NEXT OBJECT CHUNK \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
# /////
# ///// This function handles all the information about the objects in the file
# /////
# ///////////////////////////////// PROCESS NEXT OBJECT CHUNK \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
#
# void CLoad3DS::ProcessNextObjectChunk(t3DModel *pModel, t3DObject *pObject, tChunk *pPreviousChunk)
# {
# int buffer[50000] = {0}; // This is used to read past unwanted data
#
# // Allocate a new chunk to work with
# m_CurrentChunk = new tChunk;
#
# // Continue to read these chunks until we read the end of this sub chunk
# while (pPreviousChunk->bytesRead < pPreviousChunk->length)
# {
# // Read the next chunk
# ReadChunk(m_CurrentChunk);
#
# // Check which chunk we just read
# switch (m_CurrentChunk->ID)
# {
# case __H3DS__OBJECT_MESH: // This lets us know that we are reading a new object
#
# // We found a new object, so let's read in it's info using recursion
# ProcessNextObjectChunk(pModel, pObject, m_CurrentChunk);
# break;
#
# case __H3DS__OBJECT_VERTICES: // This is the objects vertices
# ReadVertices(pObject, m_CurrentChunk);
# break;
#
# case __H3DS__OBJECT_FACES: // This is the objects face information
# ReadVertexIndices(pObject, m_CurrentChunk);
# break;
#
# case __H3DS__OBJECT_MATERIAL: // This holds the material name that the object has
#
# // This chunk holds the name of the material that the object has assigned to it.
# // This could either be just a color or a texture map. This chunk also holds
# // the faces that the texture is assigned to (In the case that there is multiple
# // textures assigned to one object, or it just has a texture on a part of the object.
# // Since most of my game objects just have the texture around the whole object, and
# // they aren't multitextured, I just want the material name.
#
# // We now will read the name of the material assigned to this object
# ReadObjectMaterial(pModel, pObject, m_CurrentChunk);
# break;
#
# case __H3DS__OBJECT_UV: // This holds the UV texture coordinates forthe object
#
# // This chunk holds all of the UV coordinates forour object. Let's read them in.
# ReadUVCoordinates(pObject, m_CurrentChunk);
# break;
#
# default:
#
# // Read past the ignored or unknown chunks
# m_CurrentChunk->bytesRead += fread(buffer, 1, m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_FilePointer);
# break;
# }
#
# // Add the bytes read from the last chunk to the previous chunk passed in.
# pPreviousChunk->bytesRead += m_CurrentChunk->bytesRead;
# }
#
# // Free the current chunk and set it back to the previous chunk (since it started that way)
# delete m_CurrentChunk;
# m_CurrentChunk = pPreviousChunk;
# }
#
#
# ///////////////////////////////// PROCESS NEXT MATERIAL CHUNK \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
# /////
# ///// This function handles all the information about the material (Texture)
# /////
# ///////////////////////////////// PROCESS NEXT MATERIAL CHUNK \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
#
# void CLoad3DS::ProcessNextMaterialChunk(t3DModel *pModel, tChunk *pPreviousChunk)
# {
# int buffer[50000] = {0}; // This is used to read past unwanted data
#
# // Allocate a new chunk to work with
# m_CurrentChunk = new tChunk;
#
# // Continue to read these chunks until we read the end of this sub chunk
# while (pPreviousChunk->bytesRead < pPreviousChunk->length)
# {
# // Read the next chunk
# ReadChunk(m_CurrentChunk);
#
# // Check which chunk we just read in
# switch (m_CurrentChunk->ID)
# {
# case __H3DS__MATNAME: // This chunk holds the name of the material
#
# // Here we read in the material name
# m_CurrentChunk->bytesRead += fread(pModel->pMaterials[pModel->numOfMaterials - 1].strName, 1, m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_FilePointer);
# break;
#
# case __H3DS__MATDIFFUSE: // This holds the R G B color of our object
# ReadColorChunk(&(pModel->pMaterials[pModel->numOfMaterials - 1]), m_CurrentChunk);
# break;
#
# case __H3DS__MATMAP: // This is the header forthe texture info
#
# // Proceed to read in the material information
# ProcessNextMaterialChunk(pModel, m_CurrentChunk);
# break;
#
# case __H3DS__MATMAPFILE: // This stores the file name of the material
#
# // Here we read in the material's file name
# m_CurrentChunk->bytesRead += fread(pModel->pMaterials[pModel->numOfMaterials - 1].strFile, 1, m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_FilePointer);
# break;
#
# default:
#
# // Read past the ignored or unknown chunks
# m_CurrentChunk->bytesRead += fread(buffer, 1, m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_FilePointer);
# break;
# }
#
# // Add the bytes read from the last chunk to the previous chunk passed in.
# pPreviousChunk->bytesRead += m_CurrentChunk->bytesRead;
# }
#
# // Free the current chunk and set it back to the previous chunk (since it started that way)
# delete m_CurrentChunk;
# m_CurrentChunk = pPreviousChunk;
# }
#
# ///////////////////////////////// READ CHUNK \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
# /////
# ///// This function reads in a chunk ID and it's length in bytes
# /////
# ///////////////////////////////// READ CHUNK \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
#
# void CLoad3DS::ReadChunk(tChunk *pChunk)
# {
# // This reads the chunk ID which is 2 bytes.
# // The chunk ID is like OBJECT or MATERIAL. It tells what data is
# // able to be read in within the chunks section.
# pChunk->bytesRead = fread(&pChunk->ID, 1, 2, m_FilePointer);
#
# // Then, we read the length of the chunk which is 4 bytes.
# // This is how we know how much to read in, or read past.
# pChunk->bytesRead += fread(&pChunk->length, 1, 4, m_FilePointer);
# }
#
# ///////////////////////////////// GET STRING \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
# /////
# ///// This function reads in a string of characters
# /////
# ///////////////////////////////// GET STRING \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
#
# int CLoad3DS::GetString(char *pBuffer)
# {
# int index = 0;
#
# // Read 1 byte of data which is the first letter of the string
# fread(pBuffer, 1, 1, m_FilePointer);
#
# // Loop until we get NULL
# while (*(pBuffer + index++) != 0) {
#
# // Read in a character at a time until we hit NULL.
# fread(pBuffer + index, 1, 1, m_FilePointer);
# }
#
# // Return the string length, which is how many bytes we read in (including the NULL)
# return strlen(pBuffer) + 1;
# }
#
#
# ///////////////////////////////// READ COLOR \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
# /////
# ///// This function reads in the RGB color data
# /////
# ///////////////////////////////// READ COLOR \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
#
# void CLoad3DS::ReadColorChunk(tMaterialInfo *pMaterial, tChunk *pChunk)
# {
# // Read the color chunk info
# ReadChunk(m_TempChunk);
#
# // Read in the R G B color (3 bytes - 0 through 255)
# m_TempChunk->bytesRead += fread(pMaterial->color, 1, m_TempChunk->length - m_TempChunk->bytesRead, m_FilePointer);
#
# // Add the bytes read to our chunk
# pChunk->bytesRead += m_TempChunk->bytesRead;
# }
#
#
# ///////////////////////////////// READ VERTEX INDECES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
# /////
# ///// This function reads in the indices forthe vertex array
# /////
# ///////////////////////////////// READ VERTEX INDECES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
#
# void CLoad3DS::ReadVertexIndices(t3DObject *pObject, tChunk *pPreviousChunk)
# {
# unsigned short index = 0; // This is used to read in the current face index
# int j;
#
# // In order to read in the vertex indices forthe object, we need to first
# // read in the number of them, then read them in. Remember,
# // we only want 3 of the 4 values read in foreach face. The fourth is
# // a visibility flag for3D Studio Max that doesn't mean anything to us.
#
# // Read in the number of faces that are in this object (int)
# pPreviousChunk->bytesRead += fread(&pObject->numOfFaces, 1, 2, m_FilePointer);
#
# // Alloc enough memory forthe faces and initialize the structure
# pObject->pFaces = new tFace [pObject->numOfFaces];
# memset(pObject->pFaces, 0, sizeof(tFace) * pObject->numOfFaces);
#
# // Go through all of the faces in this object
# for(int i = 0; i < pObject->numOfFaces; i++)
# {
# // Next, we read in the A then B then C index forthe face, but ignore the 4th value.
# // The fourth value is a visibility flag for3D Studio Max, we don't care about this.
# for(j = 0; j < 4; j++)
# {
# // Read the first vertice index forthe current face
# pPreviousChunk->bytesRead += fread(&index, 1, sizeof(index), m_FilePointer);
#
# if(j < 3)
# {
# // Store the index in our face structure.
# pObject->pFaces[i].vertIndex[j] = index;
# }
# }
# }
# }
#
#
# ///////////////////////////////// READ UV COORDINATES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
# /////
# ///// This function reads in the UV coordinates forthe object
# /////
# ///////////////////////////////// READ UV COORDINATES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
#
# void CLoad3DS::ReadUVCoordinates(t3DObject *pObject, tChunk *pPreviousChunk)
# {
# // In order to read in the UV indices forthe object, we need to first
# // read in the amount there are, then read them in.
#
# // Read in the number of UV coordinates there are (int)
# pPreviousChunk->bytesRead += fread(&pObject->numTexVertex, 1, 2, m_FilePointer);
#
# // Allocate memory to hold the UV coordinates
# pObject->pTexVerts = new vec2 [pObject->numTexVertex];
#
# // Read in the texture coodinates (an array 2 float)
# pPreviousChunk->bytesRead += fread(pObject->pTexVerts, 1, pPreviousChunk->length - pPreviousChunk->bytesRead, m_FilePointer);
# }
#
#
# ///////////////////////////////// READ VERTICES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
# /////
# ///// This function reads in the vertices forthe object
# /////
# ///////////////////////////////// READ VERTICES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
#
# void CLoad3DS::ReadVertices(t3DObject *pObject, tChunk *pPreviousChunk)
# {
# // Like most chunks, before we read in the actual vertices, we need
# // to find out how many there are to read in. Once we have that number
# // we then fread() them into our vertice array.
#
# // Read in the number of vertices (int)
# pPreviousChunk->bytesRead += fread(&(pObject->numOfVerts), 1, 2, m_FilePointer);
#
# // Allocate the memory forthe verts and initialize the structure
# pObject->pVerts = new vec3 [pObject->numOfVerts];
# memset(pObject->pVerts, 0, sizeof(vec3) * pObject->numOfVerts);
#
# // Read in the array of vertices (an array of 3 floats)
# pPreviousChunk->bytesRead += fread(pObject->pVerts, 1, pPreviousChunk->length - pPreviousChunk->bytesRead, m_FilePointer);
#
# // Now we should have all of the vertices read in. Because 3D Studio Max
# // Models with the Z-Axis pointing up (strange and ugly I know!), we need
# // to flip the y values with the z values in our vertices. That way it
# // will be normal, with Y pointing up. If you prefer to work with Z pointing
# // up, then just delete this next loop. Also, because we swap the Y and Z
# // we need to negate the Z to make it come out correctly.
#
# // Go through all of the vertices that we just read and swap the Y and Z values
# for(int i = 0; i < pObject->numOfVerts; i++)
# {
# // Store off the Y value
# float fTempY = pObject->pVerts[i].y;
#
# // Set the Y value to the Z value
# pObject->pVerts[i].y = pObject->pVerts[i].z;
#
# // Set the Z value to the Y value,
# // but negative Z because 3D Studio max does the opposite.
# pObject->pVerts[i].z = -fTempY;
# }
# }
#
#
# ///////////////////////////////// READ OBJECT MATERIAL \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
# /////
# ///// This function reads in the material name assigned to the object and sets the materialID
# /////
# ///////////////////////////////// READ OBJECT MATERIAL \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
#
# void CLoad3DS::ReadObjectMaterial(t3DModel *pModel, t3DObject *pObject, tChunk *pPreviousChunk)
# {
# char strMaterial[255] = {0}; // This is used to hold the objects material name
# int buffer[50000] = {0}; // This is used to read past unwanted data
#
# // *What is a material?* - A material is either the color or the texture map of the object.
# // It can also hold other information like the brightness, shine, etc... Stuff we don't
# // really care about. We just want the color, or the texture map file name really.
#
# // Here we read the material name that is assigned to the current object.
# // strMaterial should now have a string of the material name, like "Material #2" etc..
# pPreviousChunk->bytesRead += GetString(strMaterial);
#
# // Now that we have a material name, we need to go through all of the materials
# // and check the name against each material. When we find a material in our material
# // list that matches this name we just read in, then we assign the materialID
# // of the object to that material index. You will notice that we passed in the
# // model to this function. This is because we need the number of textures.
# // Yes though, we could have just passed in the model and not the object too.
#
# // Go through all of the textures
# for(int i = 0; i < pModel->numOfMaterials; i++)
# {
# // If the material we just read in matches the current texture name
# if(strcmp(strMaterial, pModel->pMaterials[i].strName) == 0)
# {
# // Set the material ID to the current index 'i' and stop checking
# pObject->materialID = i;
#
# // Now that we found the material, check if it's a texture map.
# // If the strFile has a string length of 1 and over it's a texture
# if(strlen(pModel->pMaterials[i].strFile) > 0) {
#
# // Set the object's flag to say it has a texture map to bind.
# pObject->bHasTexture = true;
# }
# break;
# }
# else
# {
# // Set the ID to -1 to show there is no material forthis object
# pObject->materialID = -1;
# }
# }
#
# // Read past the rest of the chunk since we don't care about shared vertices
# // You will notice we subtract the bytes already read in this chunk from the total length.
# pPreviousChunk->bytesRead += fread(buffer, 1, pPreviousChunk->length - pPreviousChunk->bytesRead, m_FilePointer);
# }
#
# ///////////////////////////////// COMPUTER NORMALS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
# /////
# ///// This function computes the normals and vertex normals of the objects
# /////
# ///////////////////////////////// COMPUTER NORMALS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
#
# void CLoad3DS::ComputeNormals(t3DModel *pModel)
# {
# vec3 vVector1, vVector2, vNormal, vPoly[3];
# int i,j;
#
# // If there are no objects, we can skip this part
# if(pModel->numOfObjects <= 0)
# return;
#
# // What are vertex normals? And how are they different from other normals?
# // Well, if you find the normal to a triangle, you are finding a "Face Normal".
# // If you give OpenGL a face normal forlighting, it will make your object look
# // really flat and not very round. If we find the normal foreach vertex, it makes
# // the smooth lighting look. This also covers up blocky looking objects and they appear
# // to have more polygons than they do. Basically, what you do is first
# // calculate the face normals, then you take the average of all the normals around each
# // vertex. It's just averaging. That way you get a better approximation forthat vertex.
#
# // Go through each of the objects to calculate their normals
# for(int index = 0; index < pModel->numOfObjects; index++)
# {
# // Get the current object
# t3DObject *pObject = &(pModel->pObject[index]);
#
# // Here we allocate all the memory we need to calculate the normals
# vec3 *pNormals = new vec3 [pObject->numOfFaces];
# vec3 *pTempNormals = new vec3 [pObject->numOfFaces];
# pObject->pNormals = new vec3 [pObject->numOfVerts];
#
# // Go though all of the faces of this object
# for(i=0; i < pObject->numOfFaces; i++)
# {
# // To cut down LARGE code, we extract the 3 points of this face
# vPoly[0] = pObject->pVerts[pObject->pFaces[i].vertIndex[0]];
# vPoly[1] = pObject->pVerts[pObject->pFaces[i].vertIndex[1]];
# vPoly[2] = pObject->pVerts[pObject->pFaces[i].vertIndex[2]];
#
# // Now let's calculate the face normals (Get 2 vectors and find the cross product of those 2)
#
# vVector1 = Vector(vPoly[0], vPoly[2]); // Get the vector of the polygon (we just need 2 sides forthe normal)
# vVector2 = Vector(vPoly[2], vPoly[1]); // Get a second vector of the polygon
#
# vNormal = Cross(vVector1, vVector2); // Return the cross product of the 2 vectors (normalize vector, but not a unit vector)
# pTempNormals[i] = vNormal; // Save the un-normalized normal forthe vertex normals
# vNormal.normalize(); // Normalize the cross product to give us the polygons normal
#
# pNormals[i] = vNormal; // Assign the normal to the list of normals
# }
#
# //////////////// Now Get The Vertex Normals /////////////////
#
# vec3 vSum;
# vec3 vZero = vSum;
# int shared=0;
#
# for(i = 0; i < pObject->numOfVerts; i++) // Go through all of the vertices
# {
# for(j = 0; j < pObject->numOfFaces; j++) // Go through all of the triangles
# { // Check if the vertex is shared by another face
# if (pObject->pFaces[j].vertIndex[0] == i ||
# pObject->pFaces[j].vertIndex[1] == i ||
# pObject->pFaces[j].vertIndex[2] == i)
# {
# vSum += pTempNormals[j];// Add the un-normalized normal of the shared face
# shared++; // Increase the number of shared triangles
# }
# }
#
# // Get the normal by dividing the sum by the shared. We negate the shared so it has the normals pointing out.
# pObject->pNormals[i] = vSum / float(-shared);
#
# // Normalize the normal forthe final vertex normal
# pObject->pNormals[i].normalize();
#
# vSum = vZero; // Reset the sum
# shared = 0; // Reset the shared
# }
#
# // Free our memory and start over on the next object
# delete [] pTempNormals;
# delete [] pNormals;
# }
# }
#
#
# /////////////////////////////////////////////////////////////////////////////////
# //
# // * QUICK NOTES *
# //
# // This was a HUGE amount of knowledge and probably the largest tutorial yet!
# // In the next tutorial we will show you how to load a text file format called .obj.
# // This is the most common 3D file format that almost ANY 3D software will import.
# //
# // Once again I should point out that the coordinate system of OpenGL and 3DS Max are different.
# // Since 3D Studio Max Models with the Z-Axis pointing up (strange and ugly I know! :),
# // we need to flip the y values with the z values in our vertices. That way it
# // will be normal, with Y pointing up. Also, because we swap the Y and Z we need to negate
# // the Z to make it come out correctly. This is also explained and done in ReadVertices().
# //
# // CHUNKS: What is a chunk anyway?
# //
# // "The chunk ID is a unique code which identifies the type of data in this chunk
# // and also may indicate the existence of subordinate chunks. The chunk length indicates
# // the length of following data to be associated with this chunk. Note, this may
# // contain more data than just this chunk. If the length of data is greater than that
# // needed to fill in the information forthe chunk, additional subordinate chunks are
# // attached to this chunk immediately following any data needed forthis chunk, and
# // should be parsed out. These subordinate chunks may themselves contain subordinate chunks.
# // Unfortunately, there is no indication of the length of data, which is owned by the current
# // chunk, only the total length of data attached to the chunk, which means that the only way
# // to parse out subordinate chunks is to know the exact format of the owning chunk. On the
# // other hand, if a chunk is unknown, the parsing program can skip the entire chunk and
# // subordinate chunks in one jump. " - Jeff Lewis (werewolf@worldgate.com)
# //
# // In a short amount of words, a chunk is defined this way:
# // 2 bytes - Stores the chunk ID (OBJECT, MATERIAL, PRIMARY, etc...)
# // 4 bytes - Stores the length of that chunk. That way you know when that
# // chunk is done and there is a new chunk.
# //
# // So, to start reading the 3DS file, you read the first 2 bytes of it, then
# // the length (using fread()). It should be the PRIMARY chunk, otherwise it isn't
# // a .3DS file.
# //
# // Below is a list of the order that you will find the chunks and all the know chunks.
# // If you go to www.wosit.org you can find a few documents on the 3DS file format.
# // You can also take a look at the 3DS Format.rtf that is included with this tutorial.
# //
# //
# //
# // MAIN3DS (0x4D4D)
# // |
# // +--EDIT3DS (0x3D3D)
# // | |
# // | +--EDIT_MATERIAL (0xAFFF)
# // | | |
# // | | +--MAT_NAME01 (0xA000) (See mli Doc)
# // | |
# // | +--EDIT_CONFIG1 (0x0100)
# // | +--EDIT_CONFIG2 (0x3E3D)
# // | +--EDIT_VIEW_P1 (0x7012)
# // | | |
# // | | +--TOP (0x0001)
# // | | +--BOTTOM (0x0002)
# // | | +--LEFT (0x0003)
# // | | +--RIGHT (0x0004)
# // | | +--FRONT (0x0005)
# // | | +--BACK (0x0006)
# // | | +--USER (0x0007)
# // | | +--CAMERA (0xFFFF)
# // | | +--LIGHT (0x0009)
# // | | +--DISABLED (0x0010)
# // | | +--BOGUS (0x0011)
# // | |
# // | +--EDIT_VIEW_P2 (0x7011)
# // | | |
# // | | +--TOP (0x0001)
# // | | +--BOTTOM (0x0002)
# // | | +--LEFT (0x0003)
# // | | +--RIGHT (0x0004)
# // | | +--FRONT (0x0005)
# // | | +--BACK (0x0006)
# // | | +--USER (0x0007)
# // | | +--CAMERA (0xFFFF)
# // | | +--LIGHT (0x0009)
# // | | +--DISABLED (0x0010)
# // | | +--BOGUS (0x0011)
# // | |
# // | +--EDIT_VIEW_P3 (0x7020)
# // | +--EDIT_VIEW1 (0x7001)
# // | +--EDIT_BACKGR (0x1200)
# // | +--EDIT_AMBIENT (0x2100)
# // | +--EDIT_OBJECT (0x4000)
# // | | |
# // | | +--OBJ_TRIMESH (0x4100)
# // | | | |
# // | | | +--TRI_VERTEXL (0x4110)
# // | | | +--TRI_VERTEXOPTIONS (0x4111)
# // | | | +--TRI_MAPPINGCOORS (0x4140)
# // | | | +--TRI_MAPPINGSTANDARD (0x4170)
# // | | | +--TRI_FACEL1 (0x4120)
# // | | | | |
# // | | | | +--TRI_SMOOTH (0x4150)
# // | | | | +--TRI_MATERIAL (0x4130)
# // | | | |
# // | | | +--TRI_LOCAL (0x4160)
# // | | | +--TRI_VISIBLE (0x4165)
# // | | |
# // | | +--OBJ_LIGHT (0x4600)
# // | | | |
# // | | | +--LIT_OFF (0x4620)
# // | | | +--LIT_SPOT (0x4610)
# // | | | +--LIT_UNKNWN01 (0x465A)
# // | | |
# // | | +--OBJ_CAMERA (0x4700)
# // | | | |
# // | | | +--CAM_UNKNWN01 (0x4710)
# // | | | +--CAM_UNKNWN02 (0x4720)
# // | | |
# // | | +--OBJ_UNKNWN01 (0x4710)
# // | | +--OBJ_UNKNWN02 (0x4720)
# // | |
# // | +--EDIT_UNKNW01 (0x1100)
# // | +--EDIT_UNKNW02 (0x1201)
# // | +--EDIT_UNKNW03 (0x1300)
# // | +--EDIT_UNKNW04 (0x1400)
# // | +--EDIT_UNKNW05 (0x1420)
# // | +--EDIT_UNKNW06 (0x1450)
# // | +--EDIT_UNKNW07 (0x1500)
# // | +--EDIT_UNKNW08 (0x2200)
# // | +--EDIT_UNKNW09 (0x2201)
# // | +--EDIT_UNKNW10 (0x2210)
# // | +--EDIT_UNKNW11 (0x2300)
# // | +--EDIT_UNKNW12 (0x2302)
# // | +--EDIT_UNKNW13 (0x2000)
# // | +--EDIT_UNKNW14 (0xAFFF)
# // |
# // +--KEYF3DS (0xB000)
# // |
# // +--KEYF_UNKNWN01 (0xB00A)
# // +--............. (0x7001) ( viewport, same as editor )
# // +--KEYF_FRAMES (0xB008)
# // +--KEYF_UNKNWN02 (0xB009)
# // +--KEYF_OBJDES (0xB002)
# // |
# // +--KEYF_OBJHIERARCH (0xB010)
# // +--KEYF_OBJDUMMYNAME (0xB011)
# // +--KEYF_OBJUNKNWN01 (0xB013)
# // +--KEYF_OBJUNKNWN02 (0xB014)
# // +--KEYF_OBJUNKNWN03 (0xB015)
# // +--KEYF_OBJPIVOT (0xB020)
# // +--KEYF_OBJUNKNWN04 (0xB021)
# // +--KEYF_OBJUNKNWN05 (0xB022)
# //
# // Once you know how to read chunks, all you have to know is the ID you are looking for
# // and what data is stored after that ID. You need to get the file format forthat.
# // I can give it to you if you want, or you can go to www.wosit.org forseveral versions.
# // Because this is a proprietary format, it isn't a official document.
# //
# // I know there was a LOT of information blown over, but it is too much knowledge for
# // one tutorial. In the animation tutorial that I eventually will get to, some of
# // the things explained here will be explained in more detail. I do not claim that
# // this is the best .3DS tutorial, or even a GOOD one :) But it is a good start, and there
# // isn't much code out there that is simple when it comes to reading .3DS files.
# // So far, this is the best I have seen. That is why I made it :)
# //
# // I would like to thank www.wosit.org and Terry Caton (tcaton@umr.edu) forhis help on this.
# //
# // Let me know if this helps you out!
# //
# //
# // Ben Humphrey (DigiBen)
# // Game Programmer
# // DigiBen@GameTutorials.com
# // Co-Web Host of www.GameTutorials.com
# //
# // 

colombus

Piratenschreck

  • »colombus« ist der Autor dieses Themas

Beiträge: 566

Registrierungsdatum: 7. Mai 2016

  • Nachricht senden

2

Sonntag, 18. Juli 2010, 09:14

und dieser weitere quellecode ist dann der "3ds.h" files wie man benötigt.


Quellcode

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
# #ifndef __H3DS__
# #define __H3DS__
#
# #include "Mathlib.h"
# #include <vector>
#
#
# //>------ Primary Chunk, at the beginning of each file
# #define __H3DS__PRIMARY 0x4D4D
#
# //>------ Main Chunks
# #define __H3DS__OBJECTINFO 0x3D3D // This gives the version of the mesh and is found right before the material and object information
# #define __H3DS__VERSION3DS 0x0002 // This gives the version of the .3ds file
# #define __H3DS__EDITKEYFRAME 0xB000 // This is the header forall of the key frame info
#
# //>------ sub defines of OBJECTINFO
# #define __H3DS__MATERIAL 0xAFFF // This stored the texture info
# #define __H3DS__OBJECT 0x4000 // This stores the faces, vertices, etc...
#
# //>------ sub defines of MATERIAL
# #define __H3DS__MATNAME 0xA000 // This holds the material name
# #define __H3DS__MATDIFFUSE 0xA020 // This holds the color of the object/material
# #define __H3DS__MATMAP 0xA200 // This is a header fora new material
# #define __H3DS__MATMAPFILE 0xA300 // This holds the file name of the texture
#
# #define __H3DS__OBJECT_MESH 0x4100 // This lets us know that we are reading a new object
#
# //>------ sub defines of OBJECT_MESH
# #define __H3DS__OBJECT_VERTICES 0x4110 // The objects vertices
# #define __H3DS__OBJECT_FACES 0x4120 // The objects faces
# #define __H3DS__OBJECT_MATERIAL 0x4130 // This is found if the object has a material, either texture map or color
# #define __H3DS__OBJECT_UV 0x4140 // The UV texture coordinates
#
#
# // Here is our structure for our 3DS indicies (since .3DS stores 4 unsigned shorts)
# struct tIndices {
# unsigned short a, b, c, bVisible; // This will hold point1, 2, and 3 index's into the vertex array plus a visible flag
# };
#
# // This holds the chunk info
# struct tChunk {
# unsigned short int ID; // The chunk's ID
# unsigned int length; // The length of the chunk
# unsigned int bytesRead; // The amount of bytes read within that chunk
# };
#
# // This is our face structure. This is is used forindexing into the vertex
# // and texture coordinate arrays. From this information we know which vertices
# // from our vertex array go to which face, along with the correct texture coordinates.
# struct tFace {
# int vertIndex[3]; // indicies forthe verts that make up this triangle
# int coordIndex[3]; // indicies forthe tex coords to texture this face
# };
#
# // This holds the information fora material. It may be a texture map of a color.
# // Some of these are not used, but I left them because you will want to eventually
# // read in the UV tile ratio and the UV tile offset forsome models.
# struct tMaterialInfo {
# char strName[255]; // The texture name
# char strFile[255]; // The texture file name (If this is set it's a texture map)
# unsigned char color[3]; // The color of the object (R, G, B)
# unsigned int texureId; // the texture ID
# float uTile; // u tiling of texture (Currently not used)
# float vTile; // v tiling of texture (Currently not used)
# float uOffset; // u offset of texture (Currently not used)
# float vOffset; // v offset of texture (Currently not used)
# } ;
#
# // This holds all the information forour model/scene.
# // You should eventually turn into a robust class that
# // has loading/drawing/querying functions like:
# // LoadModel(...); DrawObject(...); DrawModel(...); DestroyModel(...);
# struct t3DObject {
# int numOfVerts; // The number of verts in the model
# int numOfFaces; // The number of faces in the model
# int numTexVertex; // The number of texture coordinates
# int materialID; // The texture ID to use, which is the index into our texture array
# bool bHasTexture; // This is true if there is a texture map forthis object
# char strName[255]; // The name of the object
# vec3 *pVerts; // The object's vertices
# vec3 *pNormals; // The object's normals
# vec2 *pTexVerts; // The texture's UV coordinates
# tFace *pFaces; // The faces information of the object
# };
#
# // This holds our model information. This should also turn into a robust class.
# // We use STL's (Standard Template Library) vector class to ease our link list burdens. :)
# struct t3DModel {
# int numOfObjects; // The number of objects in the model
# int numOfMaterials; // The number of materials forthe model
# std::vector<tMaterialInfo> pMaterials; // The list of material information (Textures and colors)
# std::vector<t3DObject> pObject; // The object list forour model
# };
#
# // This class handles all of the loading code
# class CLoad3DS {
# public:
# CLoad3DS(); // This inits the data members
#
# // This is the function that you call to load the 3DS
# bool Import3DS(t3DModel *pModel, const char *strFileName);
#
# private:
# // This reads in a string and saves it in the char array passed in
# int GetString(char *);
#
# // This reads the next chunk
# void ReadChunk(tChunk *);
#
# // This reads the next large chunk
# void ProcessNextChunk(t3DModel *pModel, tChunk *);
#
# // This reads the object chunks
# void ProcessNextObjectChunk(t3DModel *pModel, t3DObject *pObject, tChunk *);
#
# // This reads the material chunks
# void ProcessNextMaterialChunk(t3DModel *pModel, tChunk *);
#
# // This reads the RGB value forthe object's color
# void ReadColorChunk(tMaterialInfo *pMaterial, tChunk *pChunk);
#
# // This reads the objects vertices
# void ReadVertices(t3DObject *pObject, tChunk *);
#
# // This reads the objects face information
# void ReadVertexIndices(t3DObject *pObject, tChunk *);
#
# // This reads the texture coodinates of the object
# void ReadUVCoordinates(t3DObject *pObject, tChunk *);
#
# // This reads in the material name assigned to the object and sets the materialID
# void ReadObjectMaterial(t3DModel *pModel, t3DObject *pObject, tChunk *pPreviousChunk);
#
# // This computes the vertex normals forthe object (used forlighting)
# void ComputeNormals(t3DModel *pModel);
#
# // This frees memory and closes the file
# void CleanUp();
#
# // The file pointer
# FILE *m_FilePointer;
#
# // These are used through the loading process to hold the chunk information
# tChunk *m_CurrentChunk;
# tChunk *m_TempChunk;
# };
#
#
# #endif // __H3DS__
#
#
# /////////////////////////////////////////////////////////////////////////////////
# //
# // * QUICK NOTES *
# //
# // This file is created in the hopes that you can just plug it into your code
# // easily. You will probably want to query more chunks though foranimation, etc..
# //
# //
# // Ben Humphrey (DigiBen)
# // Game Programmer
# // DigiBen@GameTutorials.com
# // Co-Web Host of www.GameTutorials.com
# //
# // 

colombus

Piratenschreck

  • »colombus« ist der Autor dieses Themas

Beiträge: 566

Registrierungsdatum: 7. Mai 2016

  • Nachricht senden

3

Sonntag, 18. Juli 2010, 09:59

hier ein File manager cpp
der selbe wie benutzt war für die 3DS file zu loaden, hier handelt es sich nur um den file manager.
Also hier wurde Opengl als Viewer benutzt,

Quellcode

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
    * #include <windows.h>
    * #include <gl/gl.h>
    * #include "FileManager.h"
    * #include "globales.h"
    * #include "CObjet3D.h"
    * #include "CLogout.h"
    *
    * // Load 3D File
    * bool Load3DFile(const char *filename) {
    * if(!filename) {
    * OPENFILENAME ofnload; // Dialogbox Loading structure
    * ZeroMemory(&ofnload,sizeof(OPENFILENAME));
    * ofnload.hwndOwner = mainhWnd;
    * ofnload.lpstrFilter="know Extend files\0*.3ds;*.ms3d;*.obj\0Objet 3D Studio (.3ds)\0*.3ds\0Objet Milkshape 3D (.ms3d)\0*.ms3d\0Wavefront 3D (.obj)\0*.obj\0All files\0*.*\0\0";
    * ofnload.lpstrFile = 3DFile;
    * ofnload.nMaxFile = 3DFile.GetSize(); // Max size from buffer
    * ofnload.lpstrTitle = "Loading from 3D File";
    * ofnload.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;
    * ofnload.lStructSize = sizeof(ofnload); // Recovery structure size
    * if(!GetOpenFileName(&ofnload))
    * return false;
    * return Load3DFile(ofnload.lpstrFile); // Loading File
    * }
    * CString ficext(filename);
    * ficext.Cut(ficext.FindFromEnd('.'));
    * int format = __HCObjet3D__FORMAT_UNKNOW;
    * if(ficext.CompareNoCase(".3ds"))
    * format = __HCObjet3D__FORMAT_3DS;
    * else if(ficext.CompareNoCase(".ms3d"))
    * format = __HCObjet3D__FORMAT_MS3D;
    * else if(ficext.CompareNoCase(".obj"))
    * format = __HCObjet3D__FORMAT_OBJ;
    * CObjet3D *tmp3D = new CObjet3D();
    * objLoaded = tmp3D->Load(filename,format);
    * if(objLoaded) {
    * if(objet3D) delete 3D Object;
    * displayGroup = -1;
    * objet3D = tmp3D;
    * objet3D->GetBounds(min3Dim,max3Dim);
    * float border = (float)fabs(min3Dim.x); // we search value most significant
    * if(fabs(max3Dim.x) > border) border = (float)fabs(max3Dim.x);
    * if(fabs(min3Dim.y) > border) border = (float)fabs(min3Dim.y);
    * if(fabs(max3Dim.y) > border) border = (float)fabs(max3Dim.y);
    * min2Dim.x = min3Dim.x - border * 0.1f; // and we add 10% boundingbox of 2D
    * min2Dim.y = min3Dim.z - border * 0.1f; // for it is always visible
    * max2Dim.x = max3Dim.x + border * 0.1f;
    * max2Dim.y = max3Dim.z + border * 0.1f;
    * modelRatio = (max2Dim.x-min2Dim.x)/(max2Dim.y-min2Dim.y);
    * vec3 vtmp = max3Dim-min3Dim;
    * remoteness3D = vtmp.length() * 1.5f;
    * remoteness2D = remoteness3D;
    * maxRemoteness = remoteness3D * 10.0f;
    * objScale = 1.0f;
    * InitTreeView(filename);
    * } else {
    * DEBUGLOG1("Failed to load 3D file\n%s",filename)
    * }
    * return objLoaded;
    * }
    *
    * // recovery of file name and load it in the case of a drag'n drop
    * bool GetDropedFile(HDROP dropedFile) {
    * char *New3DFile = new char[DragQueryFile(dropedFile,0,NULL,0)+1]; // allocation to drag'n drop file
    * DragQueryFile(dropedFile,0,NouveauFichier3D,DragQueryFile(dropedFile,0,NULL,0)+1); // Filename Recovery into buffer
    * bool result = Load3DFile(New3DFile); // Object Loading
    * delete[] New3DFile;
    * return result;
    * }

colombus

Piratenschreck

  • »colombus« ist der Autor dieses Themas

Beiträge: 566

Registrierungsdatum: 7. Mai 2016

  • Nachricht senden

4

Sonntag, 18. Juli 2010, 10:12

hier kommt der clogout.h file wie gerufen ist von dem manager

Quellcode

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
# #ifndef __HCLogout__
# #define __HCLogout__
#
# // CLogout is a singleton ie a class that can have only one instance
# // Initialising singleton with the following line and then open the file with the method Open("...")
# // CLogout *logfic = CLogout::Start();
# #include <fstream>
# #include <iostream>
#
# // Log file definition for debug mode
# #ifdef _DEBUG
# #define DEBUGLOG(str) logfic->Write(str);
# #define DEBUGLOG1(str,a) logfic->Write(str,a);
# #define DEBUGLOG2(str,a,b) logfic->Write(str,a,b);
# #define DEBUGLOG3(str,a,b,c) logfic->Write(str,a,b,c);
# #define DEBUGLOG4(str,a,b,c,d) logfic->Write(str,a,b,c,d);
# #define DEBUGLOG5(str,a,b,c,d,e) logfic->Write(str,a,b,c,d,e);
# #else
# #define DEBUGLOG(str)
# #define DEBUGLOG1(str,a)
# #define DEBUGLOG2(str,a,b)
# #define DEBUGLOG3(str,a,b,c)
# #define DEBUGLOG4(str,a,b,c,d)
# #define DEBUGLOG5(str,a,b,c,d,e)
# #endif
#
# class CLogout {
# public:
# static CLogout* Start(void) {
# if (_Active) return _pInstance;
# _Active = true;
# _pInstance = new CLogout;
# return _pInstance;
# }
# ~CLogout() {
# this->_Active = false;
# this->Close();
# }
# bool Open(const char *filename);
# bool Write(const char *str, ...);
# void Close(void);
# private:
# CLogout() {}
# CLogout(const CLogout&) {}
# CLogout& operator =(const CLogout&) {}
#
# std::ofstream _pFile;
# static CLogout *_pInstance;
# static bool _Active;
# };
#
# extern CLogout *logfic;
#
# #endif // __HCLogout__ 

Bomi

Meister der Kleintools

Beiträge: 3 175

Registrierungsdatum: 2. Mai 2003

  • Nachricht senden

5

Sonntag, 18. Juli 2010, 10:19

RE: programmer quelle code wie benützlich....

Es wäre sinnvoller, die Listings in den Anhang zu packen. So kann da kaum jemand etwas mit anfangen, da viele IDEs an den Zeilennummern scheitern...
  ATH, Bomi

Contests: 2008 BEC BOC 1602 | 2007 BEC BOC | 2006 BEC BOC | 2005 BEC BOC | 2004 BEC

ANNOTunesANNOToolsMetropolaris, Georgolaris1602-Zeugs1503-SzenarienDieter's 1503-Editor

colombus

Piratenschreck

  • »colombus« ist der Autor dieses Themas

Beiträge: 566

Registrierungsdatum: 7. Mai 2016

  • Nachricht senden

6

Sonntag, 18. Juli 2010, 10:22

hier kommt jetzt für milkshape 3d objekte quellecode.
also milshape3D.cpp file

Quellcode

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
# // milkshape3D.cpp: implementation of the Cmilkshape3D class.
# //
# //////////////////////////////////////////////////////////////////////
#
# #include "milkshape3D.h"
# #include "CString.h"
# #include "CLogout.h"
#
# //------------------------------------------------------------------//
# //------------------------------------------------------------------//
# //---- METHODES DE LA CLASSE MS3D ----------------------------------//
# //------------------------------------------------------------------//
# //------------------------------------------------------------------//
#
# //------------------------------------------------------------------//
# //- bool Load(char*) -----------------------------------------------//
# //------------------------------------------------------------------//
# //- Description: This function loads an .ms3d (milkshape 3d's -//
# //- native format) into the class. The .ms3d format -//
# //- is very useful, as milkshape has support for the -//
# //- most popular models out there. -//
# //------------------------------------------------------------------//
# //- Ok, all of this stuff is mine, so get off my back. :) -//
# //------------------------------------------------------------------//
# bool CMilkshape3D::Load(const char *filename) {
# FILE* file;
# CString NomtexTemp;
# MS3D_HEADER header;
# int loop;
#
# // Open the .ms3d model file
# file = fopen(filename, "rb");
# if(!file) {
# DEBUGLOG1("Could not load %s correctly", filename);
# return false;
# }
#
# // Read the header data in
# fread(&header.id, sizeof(char), 10, file);
# fread(&header.version, 1, sizeof(int), file);
#
# if(strncmp(header.id, "MS3D000000", 10) !=0 ) {
# DEBUGLOG1("%s if not a valid .ms3d", filename);
# return false;
# }
# if((header.version != 3) && (header.version != 4)) {
# DEBUGLOG1("%s if not a valid .ms3d", filename);
# return false;
# }
#
# // Read the vertex data in
# fread(&numVertices, sizeof(unsigned short), 1, file);
# this->pVertices = new MS3D_VERTEX[numVertices];
# for(loop=0; loop<numVertices; loop++) {
# fread(&this->pVertices[loop].flags, sizeof(char), 1, file);
# fread( this->pVertices[loop].vertex, sizeof(float), 3, file);
# fread(&this->pVertices[loop].boneID, sizeof(char), 1, file);
# fread(&this->pVertices[loop].refCount, sizeof(char), 1, file);
# }
#
# // Read the triangle data in
# fread(&numTriangles, sizeof(unsigned short), 1, file);
# this->pTriangles = new MS3D_TRIANGLE[numTriangles];
# for(loop=0; loop<numTriangles; loop++) {
# fread(&this->pTriangles[loop].flags, sizeof(unsigned short), 1, file);
# fread( this->pTriangles[loop].vertexIndices, sizeof(unsigned short), 3, file);
# fread( this->pTriangles[loop].vertexNormals[0], sizeof(float), 3, file);
# fread( this->pTriangles[loop].vertexNormals[1], sizeof(float), 3, file);
# fread( this->pTriangles[loop].vertexNormals[2], sizeof(float), 3, file);
# fread( this->pTriangles[loop].u, sizeof(float), 3, file);
# fread( this->pTriangles[loop].v, sizeof(float), 3, file);
# fread(&this->pTriangles[loop].smoothingGroup, sizeof(unsigned char), 1, file);
# fread(&this->pTriangles[loop].groupIndex, sizeof(unsigned char), 1, file);
# }
#
# // Read the group data in
# fread(&numGroups, sizeof(unsigned short), 1, file);
# this->pGroups = new MS3D_GROUP[numGroups];
# for(loop=0; loop<numGroups; loop++) {
# fread(&this->pGroups[loop].flags, sizeof(unsigned char), 1, file);
# fread( this->pGroups[loop].name, sizeof(char), 32, file);
# fread(&this->pGroups[loop].numTriangles, sizeof(unsigned short), 1, file);
#
# this->pGroups[loop].triangleIndices = new unsigned short[this->pGroups[loop].numTriangles];
#
# fread( this->pGroups[loop].triangleIndices, sizeof(unsigned short), this->pGroups[loop].numTriangles,file);
# fread(&this->pGroups[loop].materialIndex, sizeof(char), 1, file);
# // DEBUGLOG1("Grp index %d",groups[loop].materialIndex);
# }
#
# // we also read materials :
# fread(&numMaterials, sizeof(unsigned short), 1, file);
#
# // Dynamic memory allocation :
# this->pMaterials = new MS3D_MATERIAL[numMaterials];
#
# for(loop=0; loop<numMaterials; loop++) {
# fread( this->pMaterials[loop].name , sizeof(char), 32, file);
# fread(&this->pMaterials[loop].ambient, sizeof(float), 4, file);
# fread(&this->pMaterials[loop].diffuse, sizeof(float), 4, file);
# fread(&this->pMaterials[loop].specular, sizeof(float), 4, file);
# fread(&this->pMaterials[loop].emissive, sizeof(float), 4, file);
# fread(&this->pMaterials[loop].shininess, sizeof(float), 1, file);
# fread(&this->pMaterials[loop].transparency, sizeof(float), 1, file);
# fread(&this->pMaterials[loop].mode , sizeof(char), 1, file);
# fread( this->pMaterials[loop].texture , sizeof(char), 128, file);
# fread( this->pMaterials[loop].alphamap , sizeof(char), 128, file);
# }
# fclose(file);
# DEBUGLOG1("Loaded %s correctly", filename);
# return true;
# }

colombus

Piratenschreck

  • »colombus« ist der Autor dieses Themas

Beiträge: 566

Registrierungsdatum: 7. Mai 2016

  • Nachricht senden

7

Sonntag, 18. Juli 2010, 10:28

hallo bomi!

wie herr?
du kann man nicht einfach Copy and paste von dem code bearbeiten, denn mit copy and paste funktion, hier werden ja die zeile nummern nicht mitgenommen, nur wass drinn geschrieben ist.

ich Bearbeite eine menge Copy paste von den quelle code, und füge sie direct in Code blocker edtor ein, niemals hat er mir die zeilen zugeschrieben.

es war ja von dies wie du gesprochen hast, oder nicht?

aber ich habe besser gefunden, für dein problem zu lösen, und dass es auch kein zu große menge quelle code in dem forum gibt.

also ich werde ab jetzt, alle quelle file wie für ein gültig sind, alle in Zip einpacken, und sie dann anhängen, so habt hier gleich alle file in eine packung.

So könnt ihr dann selbst die file raushollen wie ihr benötigt, als hilfe.


edit by Mod: bitte Mehrfachpostings vermeiden - den "ändern Button" benutzen um seinen eigenen Beitrag zu editieren!!

colombus

Piratenschreck

  • »colombus« ist der Autor dieses Themas

Beiträge: 566

Registrierungsdatum: 7. Mai 2016

  • Nachricht senden

8

Montag, 19. Juli 2010, 21:43

Also jetzt, zeit gestern, arbeite ich wie ein pferd bei der übersetzung.

so kann es nicht weiter gehen, also mach ich euch ein Vorschlag!
ich wolte nur euch die programmen quelle geben, so dass ihr sie anschauen könnt, und sieht wie es programmiert war, für die 3D programmierung zu verstehen.

Aber hier, wenn ich das Vollständige program quelle code in den zip file einziehen will, also hier, muss ich alles übersetzen, und dies hat ja kein zweck!
denn hier was nötigt ist, sind die 3ds, milkshape und obj object, sowie die targa,jpg, und bmp loader program quelle.
also mathlib ist auch interesant, aber der rest.

denn anderst, habe ich alein für dies program zu übersetzen, mehr als 7 tage.
und wenn ich so weitere programme finde, so benötige ich jedes mal zeit für sie in englisch zu übersetzen.

Denn ich denke fenster programme, oder ein file manager, dies kennt ja jeder.
denn in deutschland, gebe es auch programmer forum.
und in solche foren findet man gut die info von den fenster oder über die file manager zu programmieren.

colombus

Piratenschreck

  • »colombus« ist der Autor dieses Themas

Beiträge: 566

Registrierungsdatum: 7. Mai 2016

  • Nachricht senden

9

Dienstag, 20. Juli 2010, 13:24

here sources files
»colombus« hat folgende Datei angehängt:

colombus

Piratenschreck

  • »colombus« ist der Autor dieses Themas

Beiträge: 566

Registrierungsdatum: 7. Mai 2016

  • Nachricht senden

10

Dienstag, 20. Juli 2010, 20:53

hier als weitere info. Ein tutorial in english über den benutzt von dem opengl.
http://www.cprogramming.com/tutorial/ope…gl_program.html

und hier, gebe es information über den floating point.
http://www.cprogramming.com/tutorial/flo…ting_point.html

also hier dies ist die start phase über den floating point, so am ende der seite, könnt ihr bemerken das ein weiter link gibt.

Zitat

Next: Floating Point Representation

also dies führt dan zu dem zweiten teil, und so bei der zweite seite gebe es auch noch ein drittes seite link.

also drei seite wie über den floating point gesprochen wird.

und hier, also hier gebe es wirklich die größte quelle code für info zu haben über wie kann dies oder dies anderst programmiert werden.
sie müssen schon zu dem ende der seite gehen für alle kategorien bemerken.

http://www.planet-source-code.com/vb/def…Id=3#categories

Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von »colombus« (20. Juli 2010, 20:55)


colombus

Piratenschreck

  • »colombus« ist der Autor dieses Themas

Beiträge: 566

Registrierungsdatum: 7. Mai 2016

  • Nachricht senden

11

Freitag, 30. Juli 2010, 23:09

ach du heiliger stroh sack, jetzt ist mein messer in meine tasche aufgegangen....
(bitte nicht so dramatisch dieser spruch nehmen, denn, dieser spruch, ist ein elßassiger spruch, wie man ansagt, wenn man gebluft ist.)

Also, ja hier habe ich die antwort bekommen, und so war ich gebluft.
denn hier, benötigt man gar nicht alle quelle code in delphi umwandeln.
neh!

noch leichter, für delphi programmer.
die benutlische kode.
benötigt man nur in .dll file compilieren, und diese zu den delphi programm anhängen.
so kann man 3ds loader benutzen wie original mit eine andere programmiere sprache gekodet wurden.

also dies weis ich nicht ob, man mit alle sprach kode, .dll file kann kompilieren, sowie java kode sprache.

also hier muss man schon kompiler haben, und sie in .dll file umwandeln.
also hier denke ich schon dass drkohler, oder die andere programmierer wie mit delphi kode arbeiten mich verstanden haben.

also hier benötigt man sich auch nicht mehr den kopf zu verbrechen, für die .GR2 von dem spiel zu laden.
denn hier, kann man ganz einfach die Gr2 export dll file benutzen, für sie in ein delphi programm anhängen, und so blitz schnell haben wir ein 3ds file loader/konverter.

und so laden wir die 3ds file mit eine dll file, und speichern wir gr2 file mit der andere dll file.

aber diese dll, sowie diese gr2 exporter mit dem 3ds max sdk gearbeitet wurde, also hier für den moment könnte man nur 3ds file zu gr2 file konvertieren.
keine obj oder ms3d file.

Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »colombus« (30. Juli 2010, 23:22)