Changeset 284 for trunk/nv/interface/vertex.hh
- Timestamp:
- 07/20/14 23:45:56 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/interface/vertex.hh
r282 r284 663 663 } 664 664 665 inline uint32 interpolate_raw_linear( uint32 count, float factor, const float* k1, const float* k2, float* result ) 666 { 667 for ( uint32 i = 0; i < count; ++i ) 668 { 669 result[i] = k1[i] + factor * (k2[i] - k1[i]); 670 } 671 return count; 672 } 673 674 inline uint32 interpolate_raw_quat( float factor, const float* k1, const float* k2, float* result ) 675 { 676 *((quat*)(result)) = interpolate( *((quat*)(k1)), *((quat*)(k2)), factor ); 677 return 4; 678 } 679 680 inline uint32 interpolate_raw( const key_descriptor_slot& slot, float factor, const float* k1, const float* k2, float* result ) 681 { 682 uint32 count = get_datatype_info( slot.etype ).elements; 683 switch ( slot.vslot ) 684 { 685 case animation_slot::TIME: return 0; 686 case animation_slot::POSITION: return interpolate_raw_linear( count, factor, k1, k2, result ); 687 case animation_slot::ROTATION: return interpolate_raw_quat( factor, k1, k2, result ); 688 case animation_slot::SCALE: return interpolate_raw_linear( count, factor, k1, k2, result ); 689 case animation_slot::TFORM: return 690 interpolate_raw_linear( 3, factor, k1, k2, result ) + 691 interpolate_raw_quat( factor, k1 + 3, k2 + 3, result + 3 ); 692 default: 693 return 0; 694 }; 695 } 696 697 inline quat make_quat_fixed( const float* data ) 698 { 699 quat result; 700 memcpy((float*)(&result), data, sizeof(quat)); 701 return result; 702 } 703 704 inline mat4 extract_matrix_raw( const key_descriptor& desc, const float* data ) 705 { 706 if ( desc.count == 1 ) 707 { 708 switch ( desc.slots[0].vslot ) 709 { 710 case animation_slot::TIME: return mat4(); 711 case animation_slot::POSITION: return glm::translate( mat4(),glm::make_vec3( data ) ); 712 case animation_slot::ROTATION: return glm::mat4_cast( make_quat_fixed( data ) ); 713 case animation_slot::SCALE: return glm::scale( mat4(),glm::make_vec3( data ) ); 714 case animation_slot::TFORM: return transform( glm::make_vec3( data ), make_quat_fixed( data + 3 ) ).extract(); 715 default: 716 return mat4(); 717 }; 718 } 719 else 720 { 721 mat4 position; 722 mat4 rotation; 723 mat4 scale; 724 for ( uint32 i = 0; i < desc.count; ++i ) 725 { 726 uint32 offset = desc.slots[i].offset / 4; 727 switch ( desc.slots[i].vslot ) 728 { 729 case animation_slot::TIME: break; 730 case animation_slot::POSITION: 731 position = glm::translate( position,glm::make_vec3( data + offset ) ); break; 732 case animation_slot::ROTATION: 733 rotation = glm::mat4_cast( make_quat_fixed( data + offset ) ); break; 734 case animation_slot::SCALE: 735 scale = glm::scale( mat4(),glm::make_vec3( data + offset ) ); break; 736 case animation_slot::TFORM: return transform( glm::make_vec3( data + offset ), make_quat_fixed( data + offset + 3 ) ).extract(); 737 default: 738 break; 739 } 740 } 741 return position * rotation * scale; 742 } 743 } 744 745 inline transform extract_transform_raw( const key_descriptor& desc, const float* data ) 746 { 747 if ( desc.count == 1 ) 748 { 749 switch ( desc.slots[0].vslot ) 750 { 751 case animation_slot::TIME: return transform(); 752 case animation_slot::POSITION: return transform( glm::make_vec3( data ) ); 753 case animation_slot::ROTATION: return transform( make_quat_fixed( data ) ); 754 case animation_slot::SCALE: return transform(); 755 case animation_slot::TFORM: return transform( glm::make_vec3( data ), make_quat_fixed( data + 3 ) ); 756 default: 757 return transform(); 758 }; 759 } 760 else 761 { 762 vec3 position; 763 quat rotation; 764 for ( uint32 i = 0; i < desc.count; ++i ) 765 { 766 uint32 offset = desc.slots[i].offset / 4; 767 switch ( desc.slots[i].vslot ) 768 { 769 case animation_slot::TIME: break; 770 case animation_slot::POSITION: 771 position = glm::make_vec3( data + offset ); break; 772 case animation_slot::ROTATION: 773 rotation = make_quat_fixed( data + offset ); break; 774 case animation_slot::SCALE: break; 775 case animation_slot::TFORM: return transform( glm::make_vec3( data + offset ), make_quat_fixed( data + 3 ) ); 776 default: 777 break; 778 } 779 } 780 return transform( position, rotation ); 781 } 782 } 783 665 784 } 666 785
Note: See TracChangeset
for help on using the changeset viewer.