diff options
author | Chris Tuchs | 2011-05-08 03:06:23 -0700 |
---|---|---|
committer | Chris Tuchs | 2011-05-08 03:06:23 -0700 |
commit | 7f1cbfae2af93ec11f79b8e2d1db22822ffb6dc7 (patch) | |
tree | fe9134ed7c34b81a39570d0988b7147f153bd9bb | |
parent | Windows build change I am sure of (diff) | |
download | meta-impy-7f1cbfae2af93ec11f79b8e2d1db22822ffb6dc7.zip meta-impy-7f1cbfae2af93ec11f79b8e2d1db22822ffb6dc7.tar.gz meta-impy-7f1cbfae2af93ec11f79b8e2d1db22822ffb6dc7.tar.bz2 meta-impy-7f1cbfae2af93ec11f79b8e2d1db22822ffb6dc7.tar.xz |
Windows build changes, maybe only needed for vc2005. Mostly snprintf -> ll_snprintf, namespace hacks confused vc2005
Diffstat (limited to '')
-rwxr-xr-x | linden/indra/gpg.vs/inc.vs/unistd.h | 6 | ||||
-rw-r--r-- | linden/indra/llcharacter/llkeyframemotion.cpp | 8 | ||||
-rw-r--r-- | linden/indra/llcharacter/llmultigesture.cpp | 2 | ||||
-rw-r--r-- | linden/indra/llcommon/llmd5.cpp | 2 | ||||
-rw-r--r-- | linden/indra/llcommon/llprocessor.cpp | 36 | ||||
-rw-r--r-- | linden/indra/llcommon/llstring.cpp | 12 | ||||
-rw-r--r-- | linden/indra/llcommon/llstring.h | 10 | ||||
-rw-r--r-- | linden/indra/llmessage/lldatapacker.cpp | 94 | ||||
-rw-r--r-- | linden/indra/llmessage/llinstantmessage.cpp | 4 | ||||
-rw-r--r-- | linden/indra/llmessage/message.cpp | 4 | ||||
-rwxr-xr-x | linden/indra/llprimitive/lltextureentry.cpp | 2 | ||||
-rw-r--r-- | linden/indra/llrender/llgldbg.cpp | 4 | ||||
-rwxr-xr-x | linden/indra/llwindow/glh/glh_linear.h | 3242 | ||||
-rw-r--r-- | linden/indra/lscript/lscript_compile/lscript_tree.cpp | 16 | ||||
-rw-r--r-- | linden/indra/lscript/lscript_execute/lscript_execute.cpp | 8 | ||||
-rw-r--r-- | linden/indra/lscript/lscript_library/lscript_library.cpp | 14 |
16 files changed, 1732 insertions, 1732 deletions
diff --git a/linden/indra/gpg.vs/inc.vs/unistd.h b/linden/indra/gpg.vs/inc.vs/unistd.h index b88428c..28650a3 100755 --- a/linden/indra/gpg.vs/inc.vs/unistd.h +++ b/linden/indra/gpg.vs/inc.vs/unistd.h | |||
@@ -45,9 +45,9 @@ typedef int socklen_t; | |||
45 | #endif | 45 | #endif |
46 | 46 | ||
47 | // !s0rr0w! | 47 | // !s0rr0w! |
48 | #define SIZEOF_UINT64_T 8 | 48 | //#define SIZEOF_UINT64_T 8 |
49 | #define UINT64_C(C) (C) | 49 | //#define UINT64_C(C) (C) |
50 | typedef unsigned __int64 uint64_t; | 50 | //typedef unsigned __int64 uint64_t; |
51 | 51 | ||
52 | #if WIN32 /* [$PLOTR$] */ | 52 | #if WIN32 /* [$PLOTR$] */ |
53 | #ifndef snprintf | 53 | #ifndef snprintf |
diff --git a/linden/indra/llcharacter/llkeyframemotion.cpp b/linden/indra/llcharacter/llkeyframemotion.cpp index 6e80e8d..a12526b 100644 --- a/linden/indra/llcharacter/llkeyframemotion.cpp +++ b/linden/indra/llcharacter/llkeyframemotion.cpp | |||
@@ -1882,17 +1882,17 @@ BOOL LLKeyframeMotion::serialize(LLDataPacker& dp) const | |||
1882 | success &= dp.packU8(shared_constraintp->mChainLength, "chain_length"); | 1882 | success &= dp.packU8(shared_constraintp->mChainLength, "chain_length"); |
1883 | success &= dp.packU8(shared_constraintp->mConstraintType, "constraint_type"); | 1883 | success &= dp.packU8(shared_constraintp->mConstraintType, "constraint_type"); |
1884 | char volume_name[16]; /* Flawfinder: ignore */ | 1884 | char volume_name[16]; /* Flawfinder: ignore */ |
1885 | snprintf(volume_name, sizeof(volume_name), "%s", /* Flawfinder: ignore */ | 1885 | ll_snprintf(volume_name, sizeof(volume_name), "%s", /* Flawfinder: ignore */ |
1886 | mCharacter->findCollisionVolume(shared_constraintp->mSourceConstraintVolume)->getName().c_str()); | 1886 | mCharacter->findCollisionVolume(shared_constraintp->mSourceConstraintVolume)->getName().c_str()); |
1887 | success &= dp.packBinaryDataFixed((U8*)volume_name, 16, "source_volume"); | 1887 | success &= dp.packBinaryDataFixed((U8*)volume_name, 16, "source_volume"); |
1888 | success &= dp.packVector3(shared_constraintp->mSourceConstraintOffset, "source_offset"); | 1888 | success &= dp.packVector3(shared_constraintp->mSourceConstraintOffset, "source_offset"); |
1889 | if (shared_constraintp->mConstraintTargetType == CONSTRAINT_TARGET_TYPE_GROUND) | 1889 | if (shared_constraintp->mConstraintTargetType == CONSTRAINT_TARGET_TYPE_GROUND) |
1890 | { | 1890 | { |
1891 | snprintf(volume_name,sizeof(volume_name), "%s", "GROUND"); /* Flawfinder: ignore */ | 1891 | ll_snprintf(volume_name,sizeof(volume_name), "%s", "GROUND"); /* Flawfinder: ignore */ |
1892 | } | 1892 | } |
1893 | else | 1893 | else |
1894 | { | 1894 | { |
1895 | snprintf(volume_name, sizeof(volume_name),"%s", /* Flawfinder: ignore */ | 1895 | ll_snprintf(volume_name, sizeof(volume_name),"%s", /* Flawfinder: ignore */ |
1896 | mCharacter->findCollisionVolume(shared_constraintp->mTargetConstraintVolume)->getName().c_str()); | 1896 | mCharacter->findCollisionVolume(shared_constraintp->mTargetConstraintVolume)->getName().c_str()); |
1897 | } | 1897 | } |
1898 | success &= dp.packBinaryDataFixed((U8*)volume_name, 16, "target_volume"); | 1898 | success &= dp.packBinaryDataFixed((U8*)volume_name, 16, "target_volume"); |
@@ -2171,7 +2171,7 @@ void LLKeyframeDataCache::dumpDiagInfo() | |||
2171 | 2171 | ||
2172 | llinfos << "-----------------------------------------------------" << llendl; | 2172 | llinfos << "-----------------------------------------------------" << llendl; |
2173 | llinfos << "Motions\tTotal Size" << llendl; | 2173 | llinfos << "Motions\tTotal Size" << llendl; |
2174 | snprintf(buf, sizeof(buf), "%d\t\t%d bytes", (S32)sKeyframeDataMap.size(), total_size ); /* Flawfinder: ignore */ | 2174 | ll_snprintf(buf, sizeof(buf), "%d\t\t%d bytes", (S32)sKeyframeDataMap.size(), total_size ); /* Flawfinder: ignore */ |
2175 | llinfos << buf << llendl; | 2175 | llinfos << buf << llendl; |
2176 | llinfos << "-----------------------------------------------------" << llendl; | 2176 | llinfos << "-----------------------------------------------------" << llendl; |
2177 | } | 2177 | } |
diff --git a/linden/indra/llcharacter/llmultigesture.cpp b/linden/indra/llcharacter/llmultigesture.cpp index 7fe21db..189c714 100644 --- a/linden/indra/llcharacter/llmultigesture.cpp +++ b/linden/indra/llcharacter/llmultigesture.cpp | |||
@@ -474,7 +474,7 @@ std::string LLGestureStepWait::getLabel() const | |||
474 | if (mFlags & WAIT_FLAG_TIME) | 474 | if (mFlags & WAIT_FLAG_TIME) |
475 | { | 475 | { |
476 | char buffer[64]; /* Flawfinder: ignore */ | 476 | char buffer[64]; /* Flawfinder: ignore */ |
477 | snprintf(buffer, sizeof(buffer), "%.1f seconds", (double)mWaitSeconds); /* Flawfinder: ignore */ | 477 | ll_snprintf(buffer, sizeof(buffer), "%.1f seconds", (double)mWaitSeconds); /* Flawfinder: ignore */ |
478 | label += buffer; | 478 | label += buffer; |
479 | } | 479 | } |
480 | else if (mFlags & WAIT_FLAG_ALL_ANIM) | 480 | else if (mFlags & WAIT_FLAG_ALL_ANIM) |
diff --git a/linden/indra/llcommon/llmd5.cpp b/linden/indra/llcommon/llmd5.cpp index 887979b..42b289d 100644 --- a/linden/indra/llcommon/llmd5.cpp +++ b/linden/indra/llcommon/llmd5.cpp | |||
@@ -264,7 +264,7 @@ LLMD5::LLMD5(const unsigned char *string, const unsigned int number) | |||
264 | init(); | 264 | init(); |
265 | update(string, (U32)strlen((const char *) string)); /* Flawfinder: ignore */ | 265 | update(string, (U32)strlen((const char *) string)); /* Flawfinder: ignore */ |
266 | update((const unsigned char *) colon, (U32)strlen(colon)); /* Flawfinder: ignore */ | 266 | update((const unsigned char *) colon, (U32)strlen(colon)); /* Flawfinder: ignore */ |
267 | snprintf(tbuf, sizeof(tbuf), "%i", number); /* Flawfinder: ignore */ | 267 | ll_snprintf(tbuf, sizeof(tbuf), "%i", number); /* Flawfinder: ignore */ |
268 | update((const unsigned char *) tbuf, (U32)strlen(tbuf)); /* Flawfinder: ignore */ | 268 | update((const unsigned char *) tbuf, (U32)strlen(tbuf)); /* Flawfinder: ignore */ |
269 | finalize(); | 269 | finalize(); |
270 | } | 270 | } |
diff --git a/linden/indra/llcommon/llprocessor.cpp b/linden/indra/llcommon/llprocessor.cpp index 469e544..a5b9d11 100644 --- a/linden/indra/llcommon/llprocessor.cpp +++ b/linden/indra/llcommon/llprocessor.cpp | |||
@@ -591,7 +591,7 @@ bool CProcessor::AnalyzeIntelProcessor() | |||
591 | mov sig3, edx | 591 | mov sig3, edx |
592 | } | 592 | } |
593 | // Then we convert the data to a readable string | 593 | // Then we convert the data to a readable string |
594 | snprintf( /* Flawfinder: ignore */ | 594 | ll_snprintf( /* Flawfinder: ignore */ |
595 | CPUInfo.strProcessorSerial, | 595 | CPUInfo.strProcessorSerial, |
596 | sizeof(CPUInfo.strProcessorSerial), | 596 | sizeof(CPUInfo.strProcessorSerial), |
597 | "%04lX-%04lX-%04lX-%04lX-%04lX-%04lX", | 597 | "%04lX-%04lX-%04lX-%04lX-%04lX-%04lX", |
@@ -604,7 +604,7 @@ bool CProcessor::AnalyzeIntelProcessor() | |||
604 | else | 604 | else |
605 | { | 605 | { |
606 | // If there's no serial number support we just put "No serial number" | 606 | // If there's no serial number support we just put "No serial number" |
607 | snprintf( /* Flawfinder: ignore */ | 607 | ll_snprintf( /* Flawfinder: ignore */ |
608 | CPUInfo.strProcessorSerial, | 608 | CPUInfo.strProcessorSerial, |
609 | sizeof(CPUInfo.strProcessorSerial), | 609 | sizeof(CPUInfo.strProcessorSerial), |
610 | "No Processor Serial Number"); | 610 | "No Processor Serial Number"); |
@@ -953,7 +953,7 @@ bool CProcessor::AnalyzeAMDProcessor() | |||
953 | if ((ecxreg >> 24) > 0) | 953 | if ((ecxreg >> 24) > 0) |
954 | { | 954 | { |
955 | CPUInfo._L1.Data.bPresent = true; | 955 | CPUInfo._L1.Data.bPresent = true; |
956 | snprintf(CPUInfo._L1.Data.strSize, sizeof(CPUInfo._L1.Data.strSize), "%d KB", ecxreg >> 24); /* Flawfinder: ignore */ | 956 | ll_snprintf(CPUInfo._L1.Data.strSize, sizeof(CPUInfo._L1.Data.strSize), "%d KB", ecxreg >> 24); /* Flawfinder: ignore */ |
957 | CPUInfo._L1.Data.uiAssociativeWays = (ecxreg >> 15) & 0xFF; | 957 | CPUInfo._L1.Data.uiAssociativeWays = (ecxreg >> 15) & 0xFF; |
958 | CPUInfo._L1.Data.uiLineSize = ecxreg & 0xFF; | 958 | CPUInfo._L1.Data.uiLineSize = ecxreg & 0xFF; |
959 | } | 959 | } |
@@ -961,7 +961,7 @@ bool CProcessor::AnalyzeAMDProcessor() | |||
961 | if ((edxreg >> 24) > 0) | 961 | if ((edxreg >> 24) > 0) |
962 | { | 962 | { |
963 | CPUInfo._L1.Instruction.bPresent = true; | 963 | CPUInfo._L1.Instruction.bPresent = true; |
964 | snprintf(CPUInfo._L1.Instruction.strSize, sizeof(CPUInfo._L1.Instruction.strSize), "%d KB", edxreg >> 24); /* Flawfinder: ignore */ | 964 | ll_snprintf(CPUInfo._L1.Instruction.strSize, sizeof(CPUInfo._L1.Instruction.strSize), "%d KB", edxreg >> 24); /* Flawfinder: ignore */ |
965 | CPUInfo._L1.Instruction.uiAssociativeWays = (edxreg >> 15) & 0xFF; | 965 | CPUInfo._L1.Instruction.uiAssociativeWays = (edxreg >> 15) & 0xFF; |
966 | CPUInfo._L1.Instruction.uiLineSize = edxreg & 0xFF; | 966 | CPUInfo._L1.Instruction.uiLineSize = edxreg & 0xFF; |
967 | } | 967 | } |
@@ -985,7 +985,7 @@ bool CProcessor::AnalyzeAMDProcessor() | |||
985 | if (((ecxreg >> 12) & 0xF) > 0) | 985 | if (((ecxreg >> 12) & 0xF) > 0) |
986 | { | 986 | { |
987 | CPUInfo._L2.bPresent = true; | 987 | CPUInfo._L2.bPresent = true; |
988 | snprintf(CPUInfo._L2.strSize, sizeof(CPUInfo._L2.strSize), "%d KB", ecxreg >> 16); /* Flawfinder: ignore */ | 988 | ll_snprintf(CPUInfo._L2.strSize, sizeof(CPUInfo._L2.strSize), "%d KB", ecxreg >> 16); /* Flawfinder: ignore */ |
989 | switch ((ecxreg >> 12) & 0xF) | 989 | switch ((ecxreg >> 12) & 0xF) |
990 | { | 990 | { |
991 | case 1: | 991 | case 1: |
@@ -1078,9 +1078,9 @@ bool CProcessor::AnalyzeUnknownProcessor() | |||
1078 | strcpy(CPUInfo.strProcessorSerial, "Unknown / Not supported"); /*Flawfinder: ignore*/ | 1078 | strcpy(CPUInfo.strProcessorSerial, "Unknown / Not supported"); /*Flawfinder: ignore*/ |
1079 | 1079 | ||
1080 | // For the family, model and brand id we can only print the numeric value | 1080 | // For the family, model and brand id we can only print the numeric value |
1081 | snprintf(CPUInfo.strBrandID, sizeof(CPUInfo.strBrandID), "Brand-ID number %d", CPUInfo.uiBrandID); /* Flawfinder: ignore */ | 1081 | ll_snprintf(CPUInfo.strBrandID, sizeof(CPUInfo.strBrandID), "Brand-ID number %d", CPUInfo.uiBrandID); /* Flawfinder: ignore */ |
1082 | snprintf(CPUInfo.strFamily, sizeof(CPUInfo.strFamily), "Family number %d", CPUInfo.uiFamily); /* Flawfinder: ignore */ | 1082 | ll_snprintf(CPUInfo.strFamily, sizeof(CPUInfo.strFamily), "Family number %d", CPUInfo.uiFamily); /* Flawfinder: ignore */ |
1083 | snprintf(CPUInfo.strModel, sizeof(CPUInfo.strModel), "Model number %d", CPUInfo.uiModel); /* Flawfinder: ignore */ | 1083 | ll_snprintf(CPUInfo.strModel, sizeof(CPUInfo.strModel), "Model number %d", CPUInfo.uiModel); /* Flawfinder: ignore */ |
1084 | 1084 | ||
1085 | // And thats it | 1085 | // And thats it |
1086 | return true; | 1086 | return true; |
@@ -1397,7 +1397,7 @@ FORCEINLINE static void TranslateTLB(ProcessorTLB *tlb) | |||
1397 | 1397 | ||
1398 | // We just check if the TLB is present | 1398 | // We just check if the TLB is present |
1399 | if (tlb->bPresent) | 1399 | if (tlb->bPresent) |
1400 | snprintf(tlb->strTLB,sizeof(tlb->strTLB), "%s page size, %s, %d entries", tlb->strPageSize, TranslateAssociativeWays(tlb->uiAssociativeWays, buf), tlb->uiEntries); /* Flawfinder: ignore */ | 1400 | ll_snprintf(tlb->strTLB,sizeof(tlb->strTLB), "%s page size, %s, %d entries", tlb->strPageSize, TranslateAssociativeWays(tlb->uiAssociativeWays, buf), tlb->uiEntries); /* Flawfinder: ignore */ |
1401 | else | 1401 | else |
1402 | strcpy(tlb->strTLB, "Not present"); /* Flawfinder: ignore */ | 1402 | strcpy(tlb->strTLB, "Not present"); /* Flawfinder: ignore */ |
1403 | } | 1403 | } |
@@ -1409,7 +1409,7 @@ FORCEINLINE static void TranslateCache(ProcessorCache *cache) | |||
1409 | if (cache->bPresent) | 1409 | if (cache->bPresent) |
1410 | { | 1410 | { |
1411 | // If present we construct the string | 1411 | // If present we construct the string |
1412 | snprintf(cache->strCache, sizeof(cache->strCache), "%s cache size, %s, %d bytes line size", cache->strSize, TranslateAssociativeWays(cache->uiAssociativeWays, buf), cache->uiLineSize); /* Flawfinder: ignore */ | 1412 | ll_snprintf(cache->strCache, sizeof(cache->strCache), "%s cache size, %s, %d bytes line size", cache->strSize, TranslateAssociativeWays(cache->uiAssociativeWays, buf), cache->uiLineSize); /* Flawfinder: ignore */ |
1413 | if (cache->bSectored) | 1413 | if (cache->bSectored) |
1414 | strncat(cache->strCache, ", sectored", sizeof(cache->strCache)-strlen(cache->strCache)-1); /* Flawfinder: ignore */ | 1414 | strncat(cache->strCache, ", sectored", sizeof(cache->strCache)-strlen(cache->strCache)-1); /* Flawfinder: ignore */ |
1415 | } | 1415 | } |
@@ -1737,7 +1737,7 @@ const ProcessorInfo *CProcessor::GetCPUInfo() | |||
1737 | } | 1737 | } |
1738 | 1738 | ||
1739 | if(ncpus > 1) | 1739 | if(ncpus > 1) |
1740 | snprintf(strCPUName, sizeof(strCPUName), "%d x ", ncpus); | 1740 | ll_snprintf(strCPUName, sizeof(strCPUName), "%d x ", ncpus); |
1741 | 1741 | ||
1742 | kstat_read(kc, CPU_stats_list, NULL); | 1742 | kstat_read(kc, CPU_stats_list, NULL); |
1743 | ksinfo = (kstat_named_t *)CPU_stats_list->ks_data; | 1743 | ksinfo = (kstat_named_t *)CPU_stats_list->ks_data; |
@@ -1845,7 +1845,7 @@ static void TranslateTLB(ProcessorTLB *tlb) | |||
1845 | 1845 | ||
1846 | // We just check if the TLB is present | 1846 | // We just check if the TLB is present |
1847 | if (tlb->bPresent) | 1847 | if (tlb->bPresent) |
1848 | snprintf(tlb->strTLB, sizeof(tlb->strTLB), "%s page size, %s, %d entries", tlb->strPageSize, TranslateAssociativeWays(tlb->uiAssociativeWays, buf), tlb->uiEntries); /* Flawfinder: ignore */ | 1848 | ll_snprintf(tlb->strTLB, sizeof(tlb->strTLB), "%s page size, %s, %d entries", tlb->strPageSize, TranslateAssociativeWays(tlb->uiAssociativeWays, buf), tlb->uiEntries); /* Flawfinder: ignore */ |
1849 | else | 1849 | else |
1850 | strcpy(tlb->strTLB, "Not present"); /* Flawfinder: ignore */ | 1850 | strcpy(tlb->strTLB, "Not present"); /* Flawfinder: ignore */ |
1851 | } | 1851 | } |
@@ -1857,7 +1857,7 @@ static void TranslateCache(ProcessorCache *cache) | |||
1857 | if (cache->bPresent) | 1857 | if (cache->bPresent) |
1858 | { | 1858 | { |
1859 | // If present we construct the string | 1859 | // If present we construct the string |
1860 | snprintf(cache->strCache,sizeof(cache->strCache), "%s cache size, %s, %d bytes line size", cache->strSize, TranslateAssociativeWays(cache->uiAssociativeWays, buf), cache->uiLineSize); /* Flawfinder: ignore */ | 1860 | ll_snprintf(cache->strCache,sizeof(cache->strCache), "%s cache size, %s, %d bytes line size", cache->strSize, TranslateAssociativeWays(cache->uiAssociativeWays, buf), cache->uiLineSize); /* Flawfinder: ignore */ |
1861 | if (cache->bSectored) | 1861 | if (cache->bSectored) |
1862 | strncat(cache->strCache, ", sectored", sizeof(cache->strCache)-strlen(cache->strCache)-1); /* Flawfinder: ignore */ | 1862 | strncat(cache->strCache, ", sectored", sizeof(cache->strCache)-strlen(cache->strCache)-1); /* Flawfinder: ignore */ |
1863 | } | 1863 | } |
@@ -2003,7 +2003,7 @@ const ProcessorInfo *CProcessor::GetCPUInfo() | |||
2003 | } | 2003 | } |
2004 | else | 2004 | else |
2005 | { | 2005 | { |
2006 | snprintf(strCPUName, sizeof(strCPUName), "%d x ", ncpu); /* Flawfinder: ignore */ | 2006 | ll_snprintf(strCPUName, sizeof(strCPUName), "%d x ", ncpu); /* Flawfinder: ignore */ |
2007 | } | 2007 | } |
2008 | 2008 | ||
2009 | #if __ppc__ | 2009 | #if __ppc__ |
@@ -2100,7 +2100,7 @@ const ProcessorInfo *CProcessor::GetCPUInfo() | |||
2100 | if(l1dcachesize != 0) | 2100 | if(l1dcachesize != 0) |
2101 | { | 2101 | { |
2102 | CPUInfo._L1.Data.bPresent = true; | 2102 | CPUInfo._L1.Data.bPresent = true; |
2103 | snprintf(CPUInfo._L1.Data.strSize, sizeof(CPUInfo._L1.Data.strSize), "%d KB", l1dcachesize / 1024); /* Flawfinder: ignore */ | 2103 | ll_snprintf(CPUInfo._L1.Data.strSize, sizeof(CPUInfo._L1.Data.strSize), "%d KB", l1dcachesize / 1024); /* Flawfinder: ignore */ |
2104 | // CPUInfo._L1.Data.uiAssociativeWays = ???; | 2104 | // CPUInfo._L1.Data.uiAssociativeWays = ???; |
2105 | CPUInfo._L1.Data.uiLineSize = cachelinesize; | 2105 | CPUInfo._L1.Data.uiLineSize = cachelinesize; |
2106 | } | 2106 | } |
@@ -2108,7 +2108,7 @@ const ProcessorInfo *CProcessor::GetCPUInfo() | |||
2108 | if(l1icachesize != 0) | 2108 | if(l1icachesize != 0) |
2109 | { | 2109 | { |
2110 | CPUInfo._L1.Instruction.bPresent = true; | 2110 | CPUInfo._L1.Instruction.bPresent = true; |
2111 | snprintf(CPUInfo._L1.Instruction.strSize, sizeof(CPUInfo._L1.Instruction.strSize), "%d KB", l1icachesize / 1024); /* Flawfinder: ignore */ | 2111 | ll_snprintf(CPUInfo._L1.Instruction.strSize, sizeof(CPUInfo._L1.Instruction.strSize), "%d KB", l1icachesize / 1024); /* Flawfinder: ignore */ |
2112 | // CPUInfo._L1.Instruction.uiAssociativeWays = ???; | 2112 | // CPUInfo._L1.Instruction.uiAssociativeWays = ???; |
2113 | CPUInfo._L1.Instruction.uiLineSize = cachelinesize; | 2113 | CPUInfo._L1.Instruction.uiLineSize = cachelinesize; |
2114 | } | 2114 | } |
@@ -2116,7 +2116,7 @@ const ProcessorInfo *CProcessor::GetCPUInfo() | |||
2116 | if(l2cachesize != 0) | 2116 | if(l2cachesize != 0) |
2117 | { | 2117 | { |
2118 | CPUInfo._L2.bPresent = true; | 2118 | CPUInfo._L2.bPresent = true; |
2119 | snprintf(CPUInfo._L2.strSize, sizeof(CPUInfo._L2.strSize), "%d KB", l2cachesize / 1024); /* Flawfinder: ignore */ | 2119 | ll_snprintf(CPUInfo._L2.strSize, sizeof(CPUInfo._L2.strSize), "%d KB", l2cachesize / 1024); /* Flawfinder: ignore */ |
2120 | // CPUInfo._L2.uiAssociativeWays = ???; | 2120 | // CPUInfo._L2.uiAssociativeWays = ???; |
2121 | CPUInfo._L2.uiLineSize = cachelinesize; | 2121 | CPUInfo._L2.uiLineSize = cachelinesize; |
2122 | } | 2122 | } |
@@ -2124,7 +2124,7 @@ const ProcessorInfo *CProcessor::GetCPUInfo() | |||
2124 | if(l3cachesize != 0) | 2124 | if(l3cachesize != 0) |
2125 | { | 2125 | { |
2126 | CPUInfo._L2.bPresent = true; | 2126 | CPUInfo._L2.bPresent = true; |
2127 | snprintf(CPUInfo._L2.strSize, sizeof(CPUInfo._L2.strSize), "%d KB", l3cachesize / 1024); /* Flawfinder: ignore */ | 2127 | ll_snprintf(CPUInfo._L2.strSize, sizeof(CPUInfo._L2.strSize), "%d KB", l3cachesize / 1024); /* Flawfinder: ignore */ |
2128 | // CPUInfo._L2.uiAssociativeWays = ???; | 2128 | // CPUInfo._L2.uiAssociativeWays = ???; |
2129 | CPUInfo._L2.uiLineSize = cachelinesize; | 2129 | CPUInfo._L2.uiLineSize = cachelinesize; |
2130 | } | 2130 | } |
diff --git a/linden/indra/llcommon/llstring.cpp b/linden/indra/llcommon/llstring.cpp index 32a75c0..030f1c3 100644 --- a/linden/indra/llcommon/llstring.cpp +++ b/linden/indra/llcommon/llstring.cpp | |||
@@ -609,20 +609,20 @@ bool LLStringOps::isHexString(const std::string& str) | |||
609 | 609 | ||
610 | #if LL_WINDOWS | 610 | #if LL_WINDOWS |
611 | // documentation moved to header. Phoenix 2007-11-27 | 611 | // documentation moved to header. Phoenix 2007-11-27 |
612 | namespace snprintf_hack | 612 | //namespace snprintf_hack |
613 | { | 613 | //{ |
614 | int snprintf(char *str, size_t size, const char *format, ...) | 614 | int ll_snprintf(char *str, size_t size, const char *format, ...) |
615 | { | 615 | { |
616 | va_list args; | 616 | va_list args; |
617 | va_start(args, format); | 617 | va_start(args, format); |
618 | 618 | ||
619 | int num_written = _vsnprintf(str, size, format, args); /* Flawfinder: ignore */ | 619 | int num_written = _vsnprintf(str, size, format, args); /* Flawfinder: ignore */ |
620 | va_end(args); | 620 | va_end(args); |
621 | 621 | ||
622 | str[size-1] = '\0'; // always null terminate | 622 | str[size-1] = '\0'; // always null terminate |
623 | return num_written; | 623 | return num_written; |
624 | } | 624 | } |
625 | } | 625 | //} |
626 | 626 | ||
627 | std::string ll_convert_wide_to_string(const wchar_t* in) | 627 | std::string ll_convert_wide_to_string(const wchar_t* in) |
628 | { | 628 | { |
@@ -642,9 +642,9 @@ std::string ll_convert_wide_to_string(const wchar_t* in) | |||
642 | // We will need two more bytes for the double NULL ending | 642 | // We will need two more bytes for the double NULL ending |
643 | // created in WideCharToMultiByte(). | 643 | // created in WideCharToMultiByte(). |
644 | char* pout = new char [len_out + 2]; | 644 | char* pout = new char [len_out + 2]; |
645 | memset(pout, 0, len_out + 2); | ||
646 | if(pout) | 645 | if(pout) |
647 | { | 646 | { |
647 | memset(pout, 0, len_out + 2); | ||
648 | WideCharToMultiByte( | 648 | WideCharToMultiByte( |
649 | CP_ACP, | 649 | CP_ACP, |
650 | 0, | 650 | 0, |
diff --git a/linden/indra/llcommon/llstring.h b/linden/indra/llcommon/llstring.h index 1717479..881ba83 100644 --- a/linden/indra/llcommon/llstring.h +++ b/linden/indra/llcommon/llstring.h | |||
@@ -483,12 +483,12 @@ LL_COMMON_API std::string utf8str_removeCRLF(const std::string& utf8str); | |||
483 | */ | 483 | */ |
484 | 484 | ||
485 | // Deal with the differeneces on Windows | 485 | // Deal with the differeneces on Windows |
486 | namespace snprintf_hack | 486 | //namespace snprintf_hack |
487 | { | 487 | //{ |
488 | LL_COMMON_API int snprintf(char *str, size_t size, const char *format, ...); | 488 | LL_COMMON_API int ll_snprintf(char *str, size_t size, const char *format, ...); |
489 | } | 489 | //} |
490 | 490 | ||
491 | using snprintf_hack::snprintf; | 491 | //using snprintf_hack::snprintf; |
492 | 492 | ||
493 | /** | 493 | /** |
494 | * @brief Convert a wide string to std::string | 494 | * @brief Convert a wide string to std::string |
diff --git a/linden/indra/llmessage/lldatapacker.cpp b/linden/indra/llmessage/lldatapacker.cpp index b746b5a..8270ddf 100644 --- a/linden/indra/llmessage/lldatapacker.cpp +++ b/linden/indra/llmessage/lldatapacker.cpp | |||
@@ -671,7 +671,7 @@ void LLDataPackerBinaryBuffer::dumpBufferToLog() | |||
671 | S32 cur_line = 0; | 671 | S32 cur_line = 0; |
672 | for (i = 0; i < mBufferSize; i++) | 672 | for (i = 0; i < mBufferSize; i++) |
673 | { | 673 | { |
674 | snprintf(line_buffer + cur_line_pos*3, sizeof(line_buffer) - cur_line_pos*3, "%02x ", mBufferp[i]); /* Flawfinder: ignore */ | 674 | ll_snprintf(line_buffer + cur_line_pos*3, sizeof(line_buffer) - cur_line_pos*3, "%02x ", mBufferp[i]); /* Flawfinder: ignore */ |
675 | cur_line_pos++; | 675 | cur_line_pos++; |
676 | if (cur_line_pos >= 16) | 676 | if (cur_line_pos >= 16) |
677 | { | 677 | { |
@@ -696,14 +696,14 @@ BOOL LLDataPackerAsciiBuffer::packString(const std::string& value, const char *n | |||
696 | int numCopied = 0; | 696 | int numCopied = 0; |
697 | if (mWriteEnabled) | 697 | if (mWriteEnabled) |
698 | { | 698 | { |
699 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%s\n", value.c_str()); /* Flawfinder: ignore */ | 699 | numCopied = ll_snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%s\n", value.c_str()); /* Flawfinder: ignore */ |
700 | } | 700 | } |
701 | else | 701 | else |
702 | { | 702 | { |
703 | numCopied = value.length() + 1; /*Flawfinder: ignore*/ | 703 | numCopied = value.length() + 1; /*Flawfinder: ignore*/ |
704 | } | 704 | } |
705 | 705 | ||
706 | // snprintf returns number of bytes that would have been written | 706 | // ll_snprintf returns number of bytes that would have been written |
707 | // had the output not being truncated. In that case, it will | 707 | // had the output not being truncated. In that case, it will |
708 | // return either -1 or value >= passed in size value . So a check needs to be added | 708 | // return either -1 or value >= passed in size value . So a check needs to be added |
709 | // to detect truncation, and if there is any, only account for the | 709 | // to detect truncation, and if there is any, only account for the |
@@ -741,9 +741,9 @@ BOOL LLDataPackerAsciiBuffer::packBinaryData(const U8 *value, S32 size, const ch | |||
741 | int numCopied = 0; | 741 | int numCopied = 0; |
742 | if (mWriteEnabled) | 742 | if (mWriteEnabled) |
743 | { | 743 | { |
744 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%010d ", size); /* Flawfinder: ignore */ | 744 | numCopied = ll_snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%010d ", size); /* Flawfinder: ignore */ |
745 | 745 | ||
746 | // snprintf returns number of bytes that would have been | 746 | // ll_snprintf returns number of bytes that would have been |
747 | // written had the output not being truncated. In that case, | 747 | // written had the output not being truncated. In that case, |
748 | // it will retuen >= passed in size value. so a check needs | 748 | // it will retuen >= passed in size value. so a check needs |
749 | // to be added to detect truncation, and if there is any, only | 749 | // to be added to detect truncation, and if there is any, only |
@@ -761,7 +761,7 @@ BOOL LLDataPackerAsciiBuffer::packBinaryData(const U8 *value, S32 size, const ch | |||
761 | BOOL bBufferFull = FALSE; | 761 | BOOL bBufferFull = FALSE; |
762 | for (i = 0; i < size && !bBufferFull; i++) | 762 | for (i = 0; i < size && !bBufferFull; i++) |
763 | { | 763 | { |
764 | numCopied = snprintf(mCurBufferp, getBufferSize()-getCurrentSize(), "%02x ", value[i]); /* Flawfinder: ignore */ | 764 | numCopied = ll_snprintf(mCurBufferp, getBufferSize()-getCurrentSize(), "%02x ", value[i]); /* Flawfinder: ignore */ |
765 | if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) | 765 | if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) |
766 | { | 766 | { |
767 | numCopied = getBufferSize()-getCurrentSize(); | 767 | numCopied = getBufferSize()-getCurrentSize(); |
@@ -773,7 +773,7 @@ BOOL LLDataPackerAsciiBuffer::packBinaryData(const U8 *value, S32 size, const ch | |||
773 | 773 | ||
774 | if (!bBufferFull) | 774 | if (!bBufferFull) |
775 | { | 775 | { |
776 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(), "\n"); /* Flawfinder: ignore */ | 776 | numCopied = ll_snprintf(mCurBufferp,getBufferSize()-getCurrentSize(), "\n"); /* Flawfinder: ignore */ |
777 | if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) | 777 | if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) |
778 | { | 778 | { |
779 | numCopied = getBufferSize()-getCurrentSize(); | 779 | numCopied = getBufferSize()-getCurrentSize(); |
@@ -835,7 +835,7 @@ BOOL LLDataPackerAsciiBuffer::packBinaryDataFixed(const U8 *value, S32 size, con | |||
835 | BOOL bBufferFull = FALSE; | 835 | BOOL bBufferFull = FALSE; |
836 | for (i = 0; i < size && !bBufferFull; i++) | 836 | for (i = 0; i < size && !bBufferFull; i++) |
837 | { | 837 | { |
838 | numCopied = snprintf(mCurBufferp, getBufferSize()-getCurrentSize(), "%02x ", value[i]); /* Flawfinder: ignore */ | 838 | numCopied = ll_snprintf(mCurBufferp, getBufferSize()-getCurrentSize(), "%02x ", value[i]); /* Flawfinder: ignore */ |
839 | if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) | 839 | if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) |
840 | { | 840 | { |
841 | numCopied = getBufferSize()-getCurrentSize(); | 841 | numCopied = getBufferSize()-getCurrentSize(); |
@@ -847,7 +847,7 @@ BOOL LLDataPackerAsciiBuffer::packBinaryDataFixed(const U8 *value, S32 size, con | |||
847 | } | 847 | } |
848 | if (!bBufferFull) | 848 | if (!bBufferFull) |
849 | { | 849 | { |
850 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(), "\n"); /* Flawfinder: ignore */ | 850 | numCopied = ll_snprintf(mCurBufferp,getBufferSize()-getCurrentSize(), "\n"); /* Flawfinder: ignore */ |
851 | if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) | 851 | if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) |
852 | { | 852 | { |
853 | numCopied = getBufferSize()-getCurrentSize(); | 853 | numCopied = getBufferSize()-getCurrentSize(); |
@@ -901,15 +901,15 @@ BOOL LLDataPackerAsciiBuffer::packU8(const U8 value, const char *name) | |||
901 | int numCopied = 0; | 901 | int numCopied = 0; |
902 | if (mWriteEnabled) | 902 | if (mWriteEnabled) |
903 | { | 903 | { |
904 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%d\n", value); /* Flawfinder: ignore */ | 904 | numCopied = ll_snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%d\n", value); /* Flawfinder: ignore */ |
905 | } | 905 | } |
906 | else | 906 | else |
907 | { | 907 | { |
908 | // just do the write to a temp buffer to get the length | 908 | // just do the write to a temp buffer to get the length |
909 | numCopied = snprintf(DUMMY_BUFFER, sizeof(DUMMY_BUFFER), "%d\n", value); /* Flawfinder: ignore */ | 909 | numCopied = ll_snprintf(DUMMY_BUFFER, sizeof(DUMMY_BUFFER), "%d\n", value); /* Flawfinder: ignore */ |
910 | } | 910 | } |
911 | 911 | ||
912 | // snprintf returns number of bytes that would have been written | 912 | // ll_snprintf returns number of bytes that would have been written |
913 | // had the output not being truncated. In that case, it will | 913 | // had the output not being truncated. In that case, it will |
914 | // return either -1 or value >= passed in size value . So a check needs to be added | 914 | // return either -1 or value >= passed in size value . So a check needs to be added |
915 | // to detect truncation, and if there is any, only account for the | 915 | // to detect truncation, and if there is any, only account for the |
@@ -949,14 +949,14 @@ BOOL LLDataPackerAsciiBuffer::packU16(const U16 value, const char *name) | |||
949 | int numCopied = 0; | 949 | int numCopied = 0; |
950 | if (mWriteEnabled) | 950 | if (mWriteEnabled) |
951 | { | 951 | { |
952 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%d\n", value); /* Flawfinder: ignore */ | 952 | numCopied = ll_snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%d\n", value); /* Flawfinder: ignore */ |
953 | } | 953 | } |
954 | else | 954 | else |
955 | { | 955 | { |
956 | numCopied = snprintf(DUMMY_BUFFER, sizeof(DUMMY_BUFFER), "%d\n", value); /* Flawfinder: ignore */ | 956 | numCopied = ll_snprintf(DUMMY_BUFFER, sizeof(DUMMY_BUFFER), "%d\n", value); /* Flawfinder: ignore */ |
957 | } | 957 | } |
958 | 958 | ||
959 | // snprintf returns number of bytes that would have been written | 959 | // ll_snprintf returns number of bytes that would have been written |
960 | // had the output not being truncated. In that case, it will | 960 | // had the output not being truncated. In that case, it will |
961 | // return either -1 or value >= passed in size value . So a check needs to be added | 961 | // return either -1 or value >= passed in size value . So a check needs to be added |
962 | // to detect truncation, and if there is any, only account for the | 962 | // to detect truncation, and if there is any, only account for the |
@@ -997,13 +997,13 @@ BOOL LLDataPackerAsciiBuffer::packU32(const U32 value, const char *name) | |||
997 | int numCopied = 0; | 997 | int numCopied = 0; |
998 | if (mWriteEnabled) | 998 | if (mWriteEnabled) |
999 | { | 999 | { |
1000 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%u\n", value); /* Flawfinder: ignore */ | 1000 | numCopied = ll_snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%u\n", value); /* Flawfinder: ignore */ |
1001 | } | 1001 | } |
1002 | else | 1002 | else |
1003 | { | 1003 | { |
1004 | numCopied = snprintf(DUMMY_BUFFER, sizeof(DUMMY_BUFFER), "%u\n", value); /* Flawfinder: ignore */ | 1004 | numCopied = ll_snprintf(DUMMY_BUFFER, sizeof(DUMMY_BUFFER), "%u\n", value); /* Flawfinder: ignore */ |
1005 | } | 1005 | } |
1006 | // snprintf returns number of bytes that would have been written | 1006 | // ll_snprintf returns number of bytes that would have been written |
1007 | // had the output not being truncated. In that case, it will | 1007 | // had the output not being truncated. In that case, it will |
1008 | // return either -1 or value >= passed in size value . So a check needs to be added | 1008 | // return either -1 or value >= passed in size value . So a check needs to be added |
1009 | // to detect truncation, and if there is any, only account for the | 1009 | // to detect truncation, and if there is any, only account for the |
@@ -1041,13 +1041,13 @@ BOOL LLDataPackerAsciiBuffer::packS32(const S32 value, const char *name) | |||
1041 | int numCopied = 0; | 1041 | int numCopied = 0; |
1042 | if (mWriteEnabled) | 1042 | if (mWriteEnabled) |
1043 | { | 1043 | { |
1044 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%d\n", value); /* Flawfinder: ignore */ | 1044 | numCopied = ll_snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%d\n", value); /* Flawfinder: ignore */ |
1045 | } | 1045 | } |
1046 | else | 1046 | else |
1047 | { | 1047 | { |
1048 | numCopied = snprintf(DUMMY_BUFFER, sizeof(DUMMY_BUFFER), "%d\n", value); /* Flawfinder: ignore */ | 1048 | numCopied = ll_snprintf(DUMMY_BUFFER, sizeof(DUMMY_BUFFER), "%d\n", value); /* Flawfinder: ignore */ |
1049 | } | 1049 | } |
1050 | // snprintf returns number of bytes that would have been written | 1050 | // ll_snprintf returns number of bytes that would have been written |
1051 | // had the output not being truncated. In that case, it will | 1051 | // had the output not being truncated. In that case, it will |
1052 | // return either -1 or value >= passed in size value . So a check needs to be added | 1052 | // return either -1 or value >= passed in size value . So a check needs to be added |
1053 | // to detect truncation, and if there is any, only account for the | 1053 | // to detect truncation, and if there is any, only account for the |
@@ -1085,13 +1085,13 @@ BOOL LLDataPackerAsciiBuffer::packF32(const F32 value, const char *name) | |||
1085 | int numCopied = 0; | 1085 | int numCopied = 0; |
1086 | if (mWriteEnabled) | 1086 | if (mWriteEnabled) |
1087 | { | 1087 | { |
1088 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%f\n", value); /* Flawfinder: ignore */ | 1088 | numCopied = ll_snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%f\n", value); /* Flawfinder: ignore */ |
1089 | } | 1089 | } |
1090 | else | 1090 | else |
1091 | { | 1091 | { |
1092 | numCopied = snprintf(DUMMY_BUFFER, sizeof(DUMMY_BUFFER), "%f\n", value); /* Flawfinder: ignore */ | 1092 | numCopied = ll_snprintf(DUMMY_BUFFER, sizeof(DUMMY_BUFFER), "%f\n", value); /* Flawfinder: ignore */ |
1093 | } | 1093 | } |
1094 | // snprintf returns number of bytes that would have been written | 1094 | // ll_snprintf returns number of bytes that would have been written |
1095 | // had the output not being truncated. In that case, it will | 1095 | // had the output not being truncated. In that case, it will |
1096 | // return either -1 or value >= passed in size value . So a check needs to be added | 1096 | // return either -1 or value >= passed in size value . So a check needs to be added |
1097 | // to detect truncation, and if there is any, only account for the | 1097 | // to detect truncation, and if there is any, only account for the |
@@ -1129,13 +1129,13 @@ BOOL LLDataPackerAsciiBuffer::packColor4(const LLColor4 &value, const char *name | |||
1129 | int numCopied = 0; | 1129 | int numCopied = 0; |
1130 | if (mWriteEnabled) | 1130 | if (mWriteEnabled) |
1131 | { | 1131 | { |
1132 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%f %f %f %f\n", value.mV[0], value.mV[1], value.mV[2], value.mV[3]); /* Flawfinder: ignore */ | 1132 | numCopied = ll_snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%f %f %f %f\n", value.mV[0], value.mV[1], value.mV[2], value.mV[3]); /* Flawfinder: ignore */ |
1133 | } | 1133 | } |
1134 | else | 1134 | else |
1135 | { | 1135 | { |
1136 | numCopied = snprintf(DUMMY_BUFFER,sizeof(DUMMY_BUFFER),"%f %f %f %f\n", value.mV[0], value.mV[1], value.mV[2], value.mV[3]); /* Flawfinder: ignore */ | 1136 | numCopied = ll_snprintf(DUMMY_BUFFER,sizeof(DUMMY_BUFFER),"%f %f %f %f\n", value.mV[0], value.mV[1], value.mV[2], value.mV[3]); /* Flawfinder: ignore */ |
1137 | } | 1137 | } |
1138 | // snprintf returns number of bytes that would have been written | 1138 | // ll_snprintf returns number of bytes that would have been written |
1139 | // had the output not being truncated. In that case, it will | 1139 | // had the output not being truncated. In that case, it will |
1140 | // return either -1 or value >= passed in size value . So a check needs to be added | 1140 | // return either -1 or value >= passed in size value . So a check needs to be added |
1141 | // to detect truncation, and if there is any, only account for the | 1141 | // to detect truncation, and if there is any, only account for the |
@@ -1172,13 +1172,13 @@ BOOL LLDataPackerAsciiBuffer::packColor4U(const LLColor4U &value, const char *na | |||
1172 | int numCopied = 0; | 1172 | int numCopied = 0; |
1173 | if (mWriteEnabled) | 1173 | if (mWriteEnabled) |
1174 | { | 1174 | { |
1175 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%d %d %d %d\n", value.mV[0], value.mV[1], value.mV[2], value.mV[3]); /* Flawfinder: ignore */ | 1175 | numCopied = ll_snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%d %d %d %d\n", value.mV[0], value.mV[1], value.mV[2], value.mV[3]); /* Flawfinder: ignore */ |
1176 | } | 1176 | } |
1177 | else | 1177 | else |
1178 | { | 1178 | { |
1179 | numCopied = snprintf(DUMMY_BUFFER,sizeof(DUMMY_BUFFER),"%d %d %d %d\n", value.mV[0], value.mV[1], value.mV[2], value.mV[3]); /* Flawfinder: ignore */ | 1179 | numCopied = ll_snprintf(DUMMY_BUFFER,sizeof(DUMMY_BUFFER),"%d %d %d %d\n", value.mV[0], value.mV[1], value.mV[2], value.mV[3]); /* Flawfinder: ignore */ |
1180 | } | 1180 | } |
1181 | // snprintf returns number of bytes that would have been written | 1181 | // ll_snprintf returns number of bytes that would have been written |
1182 | // had the output not being truncated. In that case, it will | 1182 | // had the output not being truncated. In that case, it will |
1183 | // return either -1 or value >= passed in size value . So a check needs to be added | 1183 | // return either -1 or value >= passed in size value . So a check needs to be added |
1184 | // to detect truncation, and if there is any, only account for the | 1184 | // to detect truncation, and if there is any, only account for the |
@@ -1222,13 +1222,13 @@ BOOL LLDataPackerAsciiBuffer::packVector2(const LLVector2 &value, const char *na | |||
1222 | int numCopied = 0; | 1222 | int numCopied = 0; |
1223 | if (mWriteEnabled) | 1223 | if (mWriteEnabled) |
1224 | { | 1224 | { |
1225 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%f %f\n", value.mV[0], value.mV[1]); /* Flawfinder: ignore */ | 1225 | numCopied = ll_snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%f %f\n", value.mV[0], value.mV[1]); /* Flawfinder: ignore */ |
1226 | } | 1226 | } |
1227 | else | 1227 | else |
1228 | { | 1228 | { |
1229 | numCopied = snprintf(DUMMY_BUFFER,sizeof(DUMMY_BUFFER),"%f %f\n", value.mV[0], value.mV[1]); /* Flawfinder: ignore */ | 1229 | numCopied = ll_snprintf(DUMMY_BUFFER,sizeof(DUMMY_BUFFER),"%f %f\n", value.mV[0], value.mV[1]); /* Flawfinder: ignore */ |
1230 | } | 1230 | } |
1231 | // snprintf returns number of bytes that would have been written | 1231 | // ll_snprintf returns number of bytes that would have been written |
1232 | // had the output not being truncated. In that case, it will | 1232 | // had the output not being truncated. In that case, it will |
1233 | // return either -1 or value >= passed in size value . So a check needs to be added | 1233 | // return either -1 or value >= passed in size value . So a check needs to be added |
1234 | // to detect truncation, and if there is any, only account for the | 1234 | // to detect truncation, and if there is any, only account for the |
@@ -1266,13 +1266,13 @@ BOOL LLDataPackerAsciiBuffer::packVector3(const LLVector3 &value, const char *na | |||
1266 | int numCopied = 0; | 1266 | int numCopied = 0; |
1267 | if (mWriteEnabled) | 1267 | if (mWriteEnabled) |
1268 | { | 1268 | { |
1269 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%f %f %f\n", value.mV[0], value.mV[1], value.mV[2]); /* Flawfinder: ignore */ | 1269 | numCopied = ll_snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%f %f %f\n", value.mV[0], value.mV[1], value.mV[2]); /* Flawfinder: ignore */ |
1270 | } | 1270 | } |
1271 | else | 1271 | else |
1272 | { | 1272 | { |
1273 | numCopied = snprintf(DUMMY_BUFFER,sizeof(DUMMY_BUFFER),"%f %f %f\n", value.mV[0], value.mV[1], value.mV[2]); /* Flawfinder: ignore */ | 1273 | numCopied = ll_snprintf(DUMMY_BUFFER,sizeof(DUMMY_BUFFER),"%f %f %f\n", value.mV[0], value.mV[1], value.mV[2]); /* Flawfinder: ignore */ |
1274 | } | 1274 | } |
1275 | // snprintf returns number of bytes that would have been written | 1275 | // ll_snprintf returns number of bytes that would have been written |
1276 | // had the output not being truncated. In that case, it will | 1276 | // had the output not being truncated. In that case, it will |
1277 | // return either -1 or value >= passed in size value . So a check needs to be added | 1277 | // return either -1 or value >= passed in size value . So a check needs to be added |
1278 | // to detect truncation, and if there is any, only account for the | 1278 | // to detect truncation, and if there is any, only account for the |
@@ -1309,13 +1309,13 @@ BOOL LLDataPackerAsciiBuffer::packVector4(const LLVector4 &value, const char *na | |||
1309 | int numCopied = 0; | 1309 | int numCopied = 0; |
1310 | if (mWriteEnabled) | 1310 | if (mWriteEnabled) |
1311 | { | 1311 | { |
1312 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%f %f %f %f\n", value.mV[0], value.mV[1], value.mV[2], value.mV[3]); /* Flawfinder: ignore */ | 1312 | numCopied = ll_snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%f %f %f %f\n", value.mV[0], value.mV[1], value.mV[2], value.mV[3]); /* Flawfinder: ignore */ |
1313 | } | 1313 | } |
1314 | else | 1314 | else |
1315 | { | 1315 | { |
1316 | numCopied = snprintf(DUMMY_BUFFER,sizeof(DUMMY_BUFFER),"%f %f %f %f\n", value.mV[0], value.mV[1], value.mV[2], value.mV[3]); /* Flawfinder: ignore */ | 1316 | numCopied = ll_snprintf(DUMMY_BUFFER,sizeof(DUMMY_BUFFER),"%f %f %f %f\n", value.mV[0], value.mV[1], value.mV[2], value.mV[3]); /* Flawfinder: ignore */ |
1317 | } | 1317 | } |
1318 | // snprintf returns number of bytes that would have been written | 1318 | // ll_snprintf returns number of bytes that would have been written |
1319 | // had the output not being truncated. In that case, it will | 1319 | // had the output not being truncated. In that case, it will |
1320 | // return either -1 or value >= passed in size value . So a check needs to be added | 1320 | // return either -1 or value >= passed in size value . So a check needs to be added |
1321 | // to detect truncation, and if there is any, only account for the | 1321 | // to detect truncation, and if there is any, only account for the |
@@ -1356,13 +1356,13 @@ BOOL LLDataPackerAsciiBuffer::packUUID(const LLUUID &value, const char *name) | |||
1356 | { | 1356 | { |
1357 | std::string tmp_str; | 1357 | std::string tmp_str; |
1358 | value.toString(tmp_str); | 1358 | value.toString(tmp_str); |
1359 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%s\n", tmp_str.c_str()); /* Flawfinder: ignore */ | 1359 | numCopied = ll_snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%s\n", tmp_str.c_str()); /* Flawfinder: ignore */ |
1360 | } | 1360 | } |
1361 | else | 1361 | else |
1362 | { | 1362 | { |
1363 | numCopied = 64 + 1; // UUID + newline | 1363 | numCopied = 64 + 1; // UUID + newline |
1364 | } | 1364 | } |
1365 | // snprintf returns number of bytes that would have been written | 1365 | // ll_snprintf returns number of bytes that would have been written |
1366 | // had the output not being truncated. In that case, it will | 1366 | // had the output not being truncated. In that case, it will |
1367 | // return either -1 or value >= passed in size value . So a check needs to be added | 1367 | // return either -1 or value >= passed in size value . So a check needs to be added |
1368 | // to detect truncation, and if there is any, only account for the | 1368 | // to detect truncation, and if there is any, only account for the |
@@ -1407,14 +1407,14 @@ void LLDataPackerAsciiBuffer::writeIndentedName(const char *name) | |||
1407 | int numCopied = 0; | 1407 | int numCopied = 0; |
1408 | if (mWriteEnabled) | 1408 | if (mWriteEnabled) |
1409 | { | 1409 | { |
1410 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%s\t", name); /* Flawfinder: ignore */ | 1410 | numCopied = ll_snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%s\t", name); /* Flawfinder: ignore */ |
1411 | } | 1411 | } |
1412 | else | 1412 | else |
1413 | { | 1413 | { |
1414 | numCopied = (S32)strlen(name) + 1; /* Flawfinder: ignore */ //name + tab | 1414 | numCopied = (S32)strlen(name) + 1; /* Flawfinder: ignore */ //name + tab |
1415 | } | 1415 | } |
1416 | 1416 | ||
1417 | // snprintf returns number of bytes that would have been written | 1417 | // ll_snprintf returns number of bytes that would have been written |
1418 | // had the output not being truncated. In that case, it will | 1418 | // had the output not being truncated. In that case, it will |
1419 | // return either -1 or value >= passed in size value . So a check needs to be added | 1419 | // return either -1 or value >= passed in size value . So a check needs to be added |
1420 | // to detect truncation, and if there is any, only account for the | 1420 | // to detect truncation, and if there is any, only account for the |
@@ -1480,7 +1480,7 @@ std::string convertF32ToString(F32 val) | |||
1480 | { | 1480 | { |
1481 | std::string str; | 1481 | std::string str; |
1482 | char buf[20]; | 1482 | char buf[20]; |
1483 | snprintf(buf, 20, "%f", val); | 1483 | ll_snprintf(buf, 20, "%f", val); |
1484 | str = buf; | 1484 | str = buf; |
1485 | return str; | 1485 | return str; |
1486 | } | 1486 | } |
@@ -1535,13 +1535,13 @@ BOOL LLDataPackerAsciiFile::packBinaryData(const U8 *value, S32 size, const char | |||
1535 | else if (mOutputStream) | 1535 | else if (mOutputStream) |
1536 | { | 1536 | { |
1537 | char buffer[32]; /* Flawfinder: ignore */ | 1537 | char buffer[32]; /* Flawfinder: ignore */ |
1538 | snprintf(buffer,sizeof(buffer), "%010d ", size); /* Flawfinder: ignore */ | 1538 | ll_snprintf(buffer,sizeof(buffer), "%010d ", size); /* Flawfinder: ignore */ |
1539 | *mOutputStream << buffer; | 1539 | *mOutputStream << buffer; |
1540 | 1540 | ||
1541 | S32 i; | 1541 | S32 i; |
1542 | for (i = 0; i < size; i++) | 1542 | for (i = 0; i < size; i++) |
1543 | { | 1543 | { |
1544 | snprintf(buffer, sizeof(buffer), "%02x ", value[i]); /* Flawfinder: ignore */ | 1544 | ll_snprintf(buffer, sizeof(buffer), "%02x ", value[i]); /* Flawfinder: ignore */ |
1545 | *mOutputStream << buffer; | 1545 | *mOutputStream << buffer; |
1546 | } | 1546 | } |
1547 | *mOutputStream << "\n"; | 1547 | *mOutputStream << "\n"; |
@@ -1595,7 +1595,7 @@ BOOL LLDataPackerAsciiFile::packBinaryDataFixed(const U8 *value, S32 size, const | |||
1595 | S32 i; | 1595 | S32 i; |
1596 | for (i = 0; i < size; i++) | 1596 | for (i = 0; i < size; i++) |
1597 | { | 1597 | { |
1598 | snprintf(buffer, sizeof(buffer), "%02x ", value[i]); /* Flawfinder: ignore */ | 1598 | ll_snprintf(buffer, sizeof(buffer), "%02x ", value[i]); /* Flawfinder: ignore */ |
1599 | *mOutputStream << buffer; | 1599 | *mOutputStream << buffer; |
1600 | } | 1600 | } |
1601 | *mOutputStream << "\n"; | 1601 | *mOutputStream << "\n"; |
diff --git a/linden/indra/llmessage/llinstantmessage.cpp b/linden/indra/llmessage/llinstantmessage.cpp index 30205d8..63586a5 100644 --- a/linden/indra/llmessage/llinstantmessage.cpp +++ b/linden/indra/llmessage/llinstantmessage.cpp | |||
@@ -234,8 +234,8 @@ void pack_instant_message_block( | |||
234 | if(!message.empty()) | 234 | if(!message.empty()) |
235 | { | 235 | { |
236 | char buffer[MTUBYTES]; | 236 | char buffer[MTUBYTES]; |
237 | int num_written = snprintf(buffer, MTUBYTES, "%s", message.c_str()); /* Flawfinder: ignore */ | 237 | int num_written = ll_snprintf(buffer, MTUBYTES, "%s", message.c_str()); /* Flawfinder: ignore */ |
238 | // snprintf returns number of bytes that would have been written | 238 | // ll_snprintf returns number of bytes that would have been written |
239 | // had the output not being truncated. In that case, it will | 239 | // had the output not being truncated. In that case, it will |
240 | // return either -1 or value >= passed in size value . So a check needs to be added | 240 | // return either -1 or value >= passed in size value . So a check needs to be added |
241 | // to detect truncation, and if there is any, only account for the | 241 | // to detect truncation, and if there is any, only account for the |
diff --git a/linden/indra/llmessage/message.cpp b/linden/indra/llmessage/message.cpp index 9a80d7b..04665dc 100644 --- a/linden/indra/llmessage/message.cpp +++ b/linden/indra/llmessage/message.cpp | |||
@@ -3125,7 +3125,7 @@ bool LLMessageSystem::generateDigestForNumberAndUUIDs( | |||
3125 | 3125 | ||
3126 | d.update((const unsigned char *) colon, (U32)strlen(colon)); /* Flawfinder: ignore */ | 3126 | d.update((const unsigned char *) colon, (U32)strlen(colon)); /* Flawfinder: ignore */ |
3127 | 3127 | ||
3128 | snprintf(tbuf, sizeof(tbuf),"%i", number); /* Flawfinder: ignore */ | 3128 | ll_snprintf(tbuf, sizeof(tbuf),"%i", number); /* Flawfinder: ignore */ |
3129 | d.update((unsigned char *) tbuf, (U32)strlen(tbuf)); /* Flawfinder: ignore */ | 3129 | d.update((unsigned char *) tbuf, (U32)strlen(tbuf)); /* Flawfinder: ignore */ |
3130 | 3130 | ||
3131 | d.update((const unsigned char *) colon, (U32)strlen(colon)); /* Flawfinder: ignore */ | 3131 | d.update((const unsigned char *) colon, (U32)strlen(colon)); /* Flawfinder: ignore */ |
@@ -3385,7 +3385,7 @@ void LLMessageSystem::dumpPacketToLog() | |||
3385 | for (i = 0; i < mTrueReceiveSize; i++) | 3385 | for (i = 0; i < mTrueReceiveSize; i++) |
3386 | { | 3386 | { |
3387 | S32 offset = cur_line_pos * 3; | 3387 | S32 offset = cur_line_pos * 3; |
3388 | snprintf(line_buffer + offset, sizeof(line_buffer) - offset, | 3388 | ll_snprintf(line_buffer + offset, sizeof(line_buffer) - offset, |
3389 | "%02x ", mTrueReceiveBuffer[i]); /* Flawfinder: ignore */ | 3389 | "%02x ", mTrueReceiveBuffer[i]); /* Flawfinder: ignore */ |
3390 | cur_line_pos++; | 3390 | cur_line_pos++; |
3391 | if (cur_line_pos >= 16) | 3391 | if (cur_line_pos >= 16) |
diff --git a/linden/indra/llprimitive/lltextureentry.cpp b/linden/indra/llprimitive/lltextureentry.cpp index 11afdc0..f4880bb 100755 --- a/linden/indra/llprimitive/lltextureentry.cpp +++ b/linden/indra/llprimitive/lltextureentry.cpp | |||
@@ -606,7 +606,7 @@ std::string LLTextureEntry::touchMediaVersionString(const std::string &in_versio | |||
606 | U32 current_version = getVersionFromMediaVersionString(in_version) + 1; | 606 | U32 current_version = getVersionFromMediaVersionString(in_version) + 1; |
607 | const size_t MAX_VERSION_LEN = 10; // 2^32 fits in 10 decimal digits | 607 | const size_t MAX_VERSION_LEN = 10; // 2^32 fits in 10 decimal digits |
608 | char buf[MAX_VERSION_LEN+1]; | 608 | char buf[MAX_VERSION_LEN+1]; |
609 | snprintf(buf, (int)MAX_VERSION_LEN+1, "%0*u", (int)MAX_VERSION_LEN, current_version); // added int cast to fix warning/breakage on mac. | 609 | ll_snprintf(buf, (int)MAX_VERSION_LEN+1, "%0*u", (int)MAX_VERSION_LEN, current_version); // added int cast to fix warning/breakage on mac. |
610 | return MEDIA_VERSION_STRING_PREFIX + buf + "/" + agent_id.asString(); | 610 | return MEDIA_VERSION_STRING_PREFIX + buf + "/" + agent_id.asString(); |
611 | } | 611 | } |
612 | 612 | ||
diff --git a/linden/indra/llrender/llgldbg.cpp b/linden/indra/llrender/llgldbg.cpp index c54ab18..0642d3d 100644 --- a/linden/indra/llrender/llgldbg.cpp +++ b/linden/indra/llrender/llgldbg.cpp | |||
@@ -95,7 +95,7 @@ const char *fv4(F32 *f) | |||
95 | const char *fv3(F32 *f) | 95 | const char *fv3(F32 *f) |
96 | { | 96 | { |
97 | static char str[128]; /* Flawfinder: ignore */ | 97 | static char str[128]; /* Flawfinder: ignore */ |
98 | snprintf(str, sizeof(str), "%8.3f, %8.3f, %8.3f", f[0], f[1], f[2]); /* Flawfinder: ignore */ | 98 | ll_snprintf(str, sizeof(str), "%8.3f, %8.3f, %8.3f", f[0], f[1], f[2]); /* Flawfinder: ignore */ |
99 | return str; | 99 | return str; |
100 | } | 100 | } |
101 | 101 | ||
@@ -105,7 +105,7 @@ const char *fv3(F32 *f) | |||
105 | const char *fv1(F32 *f) | 105 | const char *fv1(F32 *f) |
106 | { | 106 | { |
107 | static char str[128]; /* Flawfinder: ignore */ | 107 | static char str[128]; /* Flawfinder: ignore */ |
108 | snprintf(str, sizeof(str), "%8.3f", f[0]); /* Flawfinder: ignore */ | 108 | ll_snprintf(str, sizeof(str), "%8.3f", f[0]); /* Flawfinder: ignore */ |
109 | return str; | 109 | return str; |
110 | } | 110 | } |
111 | 111 | ||
diff --git a/linden/indra/llwindow/glh/glh_linear.h b/linden/indra/llwindow/glh/glh_linear.h index 04ae1bd..bb59d7e 100755 --- a/linden/indra/llwindow/glh/glh_linear.h +++ b/linden/indra/llwindow/glh/glh_linear.h | |||
@@ -1,1621 +1,1621 @@ | |||
1 | /* | 1 | /* |
2 | glh - is a platform-indepenedent C++ OpenGL helper library | 2 | glh - is a platform-indepenedent C++ OpenGL helper library |
3 | 3 | ||
4 | 4 | ||
5 | Copyright (c) 2000 Cass Everitt | 5 | Copyright (c) 2000 Cass Everitt |
6 | Copyright (c) 2000 NVIDIA Corporation | 6 | Copyright (c) 2000 NVIDIA Corporation |
7 | All rights reserved. | 7 | All rights reserved. |
8 | 8 | ||
9 | Redistribution and use in source and binary forms, with or | 9 | Redistribution and use in source and binary forms, with or |
10 | without modification, are permitted provided that the following | 10 | without modification, are permitted provided that the following |
11 | conditions are met: | 11 | conditions are met: |
12 | 12 | ||
13 | * Redistributions of source code must retain the above | 13 | * Redistributions of source code must retain the above |
14 | copyright notice, this list of conditions and the following | 14 | copyright notice, this list of conditions and the following |
15 | disclaimer. | 15 | disclaimer. |
16 | 16 | ||
17 | * Redistributions in binary form must reproduce the above | 17 | * Redistributions in binary form must reproduce the above |
18 | copyright notice, this list of conditions and the following | 18 | copyright notice, this list of conditions and the following |
19 | disclaimer in the documentation and/or other materials | 19 | disclaimer in the documentation and/or other materials |
20 | provided with the distribution. | 20 | provided with the distribution. |
21 | 21 | ||
22 | * The names of contributors to this software may not be used | 22 | * The names of contributors to this software may not be used |
23 | to endorse or promote products derived from this software | 23 | to endorse or promote products derived from this software |
24 | without specific prior written permission. | 24 | without specific prior written permission. |
25 | 25 | ||
26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
27 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 27 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
28 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | 28 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
29 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | 29 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
30 | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | 30 | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
31 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | 31 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
32 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 32 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
33 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | 33 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
34 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 34 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
35 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | 35 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
36 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 36 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
37 | POSSIBILITY OF SUCH DAMAGE. | 37 | POSSIBILITY OF SUCH DAMAGE. |
38 | 38 | ||
39 | 39 | ||
40 | Cass Everitt - cass@r3.nu | 40 | Cass Everitt - cass@r3.nu |
41 | */ | 41 | */ |
42 | 42 | ||
43 | /* | 43 | /* |
44 | glh_linear.h | 44 | glh_linear.h |
45 | */ | 45 | */ |
46 | 46 | ||
47 | // Author: Cass W. Everitt | 47 | // Author: Cass W. Everitt |
48 | 48 | ||
49 | #ifndef GLH_LINEAR_H | 49 | #ifndef GLH_LINEAR_H |
50 | #define GLH_LINEAR_H | 50 | #define GLH_LINEAR_H |
51 | 51 | ||
52 | #include <memory.h> | 52 | #include <memory.h> |
53 | #include <math.h> | 53 | #include <math.h> |
54 | #include <assert.h> | 54 | #include <assert.h> |
55 | 55 | ||
56 | // only supports float for now... | 56 | // only supports float for now... |
57 | #define GLH_REAL_IS_FLOAT | 57 | #define GLH_REAL_IS_FLOAT |
58 | 58 | ||
59 | #ifdef GLH_REAL_IS_FLOAT | 59 | #ifdef GLH_REAL_IS_FLOAT |
60 | # define GLH_REAL float | 60 | # define GLH_REAL float |
61 | # define GLH_REAL_NAMESPACE ns_float | 61 | # define GLH_REAL_NAMESPACE ns_float |
62 | #endif | 62 | #endif |
63 | 63 | ||
64 | #define GLH_QUATERNION_NORMALIZATION_THRESHOLD 64 | 64 | #define GLH_QUATERNION_NORMALIZATION_THRESHOLD 64 |
65 | 65 | ||
66 | #define GLH_RAD_TO_DEG GLH_REAL(57.2957795130823208767981548141052) | 66 | #define GLH_RAD_TO_DEG GLH_REAL(57.2957795130823208767981548141052) |
67 | #define GLH_DEG_TO_RAD GLH_REAL(0.0174532925199432957692369076848861) | 67 | #define GLH_DEG_TO_RAD GLH_REAL(0.0174532925199432957692369076848861) |
68 | #define GLH_ZERO GLH_REAL(0.0) | 68 | #define GLH_ZERO GLH_REAL(0.0) |
69 | #define GLH_ONE GLH_REAL(1.0) | 69 | #define GLH_ONE GLH_REAL(1.0) |
70 | #define GLH_TWO GLH_REAL(2.0) | 70 | #define GLH_TWO GLH_REAL(2.0) |
71 | #define GLH_EPSILON GLH_REAL(10e-6) | 71 | #define GLH_EPSILON GLH_REAL(10e-6) |
72 | #define GLH_PI GLH_REAL(3.1415926535897932384626433832795) | 72 | #define GLH_PI GLH_REAL(3.1415926535897932384626433832795) |
73 | 73 | ||
74 | #define equivalent(a,b) (((a < b + GLH_EPSILON) && (a > b - GLH_EPSILON)) ? true : false) | 74 | #define equivalent(a,b) (((a < b + GLH_EPSILON) && (a > b - GLH_EPSILON)) ? true : false) |
75 | 75 | ||
76 | namespace glh | 76 | namespace glh |
77 | { | 77 | { |
78 | 78 | ||
79 | inline GLH_REAL to_degrees(GLH_REAL radians) { return radians*GLH_RAD_TO_DEG; } | 79 | inline GLH_REAL to_degrees(GLH_REAL radians) { return radians*GLH_RAD_TO_DEG; } |
80 | inline GLH_REAL to_radians(GLH_REAL degrees) { return degrees*GLH_DEG_TO_RAD; } | 80 | inline GLH_REAL to_radians(GLH_REAL degrees) { return degrees*GLH_DEG_TO_RAD; } |
81 | 81 | ||
82 | // forward declarations for friend template functions. | 82 | // forward declarations for friend template functions. |
83 | template <int N, class T> class vec; | 83 | template <int N, class T> class vec; |
84 | 84 | ||
85 | // forward declarations for friend template functions. | 85 | // forward declarations for friend template functions. |
86 | template <int N, class T> | 86 | template <int N, class T> |
87 | bool operator == ( const vec<N,T> & v1, const vec<N,T> & v2 ); | 87 | bool operator == ( const vec<N,T> & v1, const vec<N,T> & v2 ); |
88 | 88 | ||
89 | // forward declarations for friend template functions. | 89 | // forward declarations for friend template functions. |
90 | template <int N, class T> | 90 | template <int N, class T> |
91 | bool operator != ( const vec<N,T> & v1, const vec<N,T> & v2 ); | 91 | bool operator != ( const vec<N,T> & v1, const vec<N,T> & v2 ); |
92 | 92 | ||
93 | template <int N, class T> | 93 | template <int N, class T> |
94 | class vec | 94 | class vec |
95 | { | 95 | { |
96 | public: | 96 | public: |
97 | int size() const { return N; } | 97 | int size() const { return N; } |
98 | 98 | ||
99 | vec(const T & t = T()) | 99 | vec(const T & t = T()) |
100 | { for(int i = 0; i < N; i++) v[i] = t; } | 100 | { for(int i = 0; i < N; i++) v[i] = t; } |
101 | vec(const T * tp) | 101 | vec(const T * tp) |
102 | { for(int i = 0; i < N; i++) v[i] = tp[i]; } | 102 | { for(int i = 0; i < N; i++) v[i] = tp[i]; } |
103 | 103 | ||
104 | const T * get_value() const | 104 | const T * get_value() const |
105 | { return v; } | 105 | { return v; } |
106 | 106 | ||
107 | 107 | ||
108 | T dot( const vec<N,T> & rhs ) const | 108 | T dot( const vec<N,T> & rhs ) const |
109 | { | 109 | { |
110 | T r = 0; | 110 | T r = 0; |
111 | for(int i = 0; i < N; i++) r += v[i]*rhs.v[i]; | 111 | for(int i = 0; i < N; i++) r += v[i]*rhs.v[i]; |
112 | return r; | 112 | return r; |
113 | } | 113 | } |
114 | 114 | ||
115 | T length() const | 115 | T length() const |
116 | { | 116 | { |
117 | T r = 0; | 117 | T r = 0; |
118 | for(int i = 0; i < N; i++) r += v[i]*v[i]; | 118 | for(int i = 0; i < N; i++) r += v[i]*v[i]; |
119 | return T(sqrt(r)); | 119 | return T(sqrt(r)); |
120 | } | 120 | } |
121 | 121 | ||
122 | T square_norm() const | 122 | T square_norm() const |
123 | { | 123 | { |
124 | T r = 0; | 124 | T r = 0; |
125 | for(int i = 0; i < N; i++) r += v[i]*v[i]; | 125 | for(int i = 0; i < N; i++) r += v[i]*v[i]; |
126 | return r; | 126 | return r; |
127 | } | 127 | } |
128 | 128 | ||
129 | void negate() | 129 | void negate() |
130 | { for(int i = 0; i < N; i++) v[i] = -v[i]; } | 130 | { for(int i = 0; i < N; i++) v[i] = -v[i]; } |
131 | 131 | ||
132 | 132 | ||
133 | T normalize() | 133 | T normalize() |
134 | { | 134 | { |
135 | T sum(0); | 135 | T sum(0); |
136 | for(int i = 0; i < N; i++) | 136 | for(int i = 0; i < N; i++) |
137 | sum += v[i]*v[i]; | 137 | sum += v[i]*v[i]; |
138 | sum = T(sqrt(sum)); | 138 | sum = T(sqrt(sum)); |
139 | if (sum > GLH_EPSILON) | 139 | if (sum > GLH_EPSILON) |
140 | for(int i = 0; i < N; i++) | 140 | for(int i = 0; i < N; i++) |
141 | v[i] /= sum; | 141 | v[i] /= sum; |
142 | return sum; | 142 | return sum; |
143 | } | 143 | } |
144 | 144 | ||
145 | 145 | ||
146 | vec<N,T> & set_value( const T * rhs ) | 146 | vec<N,T> & set_value( const T * rhs ) |
147 | { for(int i = 0; i < N; i++) v[i] = rhs[i]; return *this; } | 147 | { for(int i = 0; i < N; i++) v[i] = rhs[i]; return *this; } |
148 | 148 | ||
149 | T & operator [] ( int i ) | 149 | T & operator [] ( int i ) |
150 | { return v[i]; } | 150 | { return v[i]; } |
151 | 151 | ||
152 | const T & operator [] ( int i ) const | 152 | const T & operator [] ( int i ) const |
153 | { return v[i]; } | 153 | { return v[i]; } |
154 | 154 | ||
155 | vec<N,T> & operator *= ( T d ) | 155 | vec<N,T> & operator *= ( T d ) |
156 | { for(int i = 0; i < N; i++) v[i] *= d; return *this;} | 156 | { for(int i = 0; i < N; i++) v[i] *= d; return *this;} |
157 | 157 | ||
158 | vec<N,T> & operator *= ( const vec<N,T> & u ) | 158 | vec<N,T> & operator *= ( const vec<N,T> & u ) |
159 | { for(int i = 0; i < N; i++) v[i] *= u[i]; return *this;} | 159 | { for(int i = 0; i < N; i++) v[i] *= u[i]; return *this;} |
160 | 160 | ||
161 | vec<N,T> & operator /= ( T d ) | 161 | vec<N,T> & operator /= ( T d ) |
162 | { if(d == 0) return *this; for(int i = 0; i < N; i++) v[i] /= d; return *this;} | 162 | { if(d == 0) return *this; for(int i = 0; i < N; i++) v[i] /= d; return *this;} |
163 | 163 | ||
164 | vec<N,T> & operator += ( const vec<N,T> & u ) | 164 | vec<N,T> & operator += ( const vec<N,T> & u ) |
165 | { for(int i = 0; i < N; i++) v[i] += u.v[i]; return *this;} | 165 | { for(int i = 0; i < N; i++) v[i] += u.v[i]; return *this;} |
166 | 166 | ||
167 | vec<N,T> & operator -= ( const vec<N,T> & u ) | 167 | vec<N,T> & operator -= ( const vec<N,T> & u ) |
168 | { for(int i = 0; i < N; i++) v[i] -= u.v[i]; return *this;} | 168 | { for(int i = 0; i < N; i++) v[i] -= u.v[i]; return *this;} |
169 | 169 | ||
170 | 170 | ||
171 | vec<N,T> operator - () const | 171 | vec<N,T> operator - () const |
172 | { vec<N,T> rv = v; rv.negate(); return rv; } | 172 | { vec<N,T> rv = v; rv.negate(); return rv; } |
173 | 173 | ||
174 | vec<N,T> operator + ( const vec<N,T> &v) const | 174 | vec<N,T> operator + ( const vec<N,T> &v) const |
175 | { vec<N,T> rt(*this); return rt += v; } | 175 | { vec<N,T> rt(*this); return rt += v; } |
176 | 176 | ||
177 | vec<N,T> operator - ( const vec<N,T> &v) const | 177 | vec<N,T> operator - ( const vec<N,T> &v) const |
178 | { vec<N,T> rt(*this); return rt -= v; } | 178 | { vec<N,T> rt(*this); return rt -= v; } |
179 | 179 | ||
180 | vec<N,T> operator * ( T d) const | 180 | vec<N,T> operator * ( T d) const |
181 | { vec<N,T> rt(*this); return rt *= d; } | 181 | { vec<N,T> rt(*this); return rt *= d; } |
182 | 182 | ||
183 | friend bool operator == <> ( const vec<N,T> &v1, const vec<N,T> &v2 ); | 183 | friend bool operator == <> ( const vec<N,T> &v1, const vec<N,T> &v2 ); |
184 | friend bool operator != <> ( const vec<N,T> &v1, const vec<N,T> &v2 ); | 184 | friend bool operator != <> ( const vec<N,T> &v1, const vec<N,T> &v2 ); |
185 | 185 | ||
186 | 186 | ||
187 | //protected: | 187 | //protected: |
188 | T v[N]; | 188 | T v[N]; |
189 | }; | 189 | }; |
190 | 190 | ||
191 | 191 | ||
192 | 192 | ||
193 | // vector friend operators | 193 | // vector friend operators |
194 | 194 | ||
195 | template <int N, class T> inline | 195 | template <int N, class T> inline |
196 | vec<N,T> operator * ( const vec<N,T> & b, T d ) | 196 | vec<N,T> operator * ( const vec<N,T> & b, T d ) |
197 | { | 197 | { |
198 | vec<N,T> rt(b); | 198 | vec<N,T> rt(b); |
199 | return rt *= d; | 199 | return rt *= d; |
200 | } | 200 | } |
201 | 201 | ||
202 | template <int N, class T> inline | 202 | template <int N, class T> inline |
203 | vec<N,T> operator * ( T d, const vec<N,T> & b ) | 203 | vec<N,T> operator * ( T d, const vec<N,T> & b ) |
204 | { return b*d; } | 204 | { return b*d; } |
205 | 205 | ||
206 | template <int N, class T> inline | 206 | template <int N, class T> inline |
207 | vec<N,T> operator * ( const vec<N,T> & b, const vec<N,T> & d ) | 207 | vec<N,T> operator * ( const vec<N,T> & b, const vec<N,T> & d ) |
208 | { | 208 | { |
209 | vec<N,T> rt(b); | 209 | vec<N,T> rt(b); |
210 | return rt *= d; | 210 | return rt *= d; |
211 | } | 211 | } |
212 | 212 | ||
213 | template <int N, class T> inline | 213 | template <int N, class T> inline |
214 | vec<N,T> operator / ( const vec<N,T> & b, T d ) | 214 | vec<N,T> operator / ( const vec<N,T> & b, T d ) |
215 | { vec<N,T> rt(b); return rt /= d; } | 215 | { vec<N,T> rt(b); return rt /= d; } |
216 | 216 | ||
217 | template <int N, class T> inline | 217 | template <int N, class T> inline |
218 | vec<N,T> operator + ( const vec<N,T> & v1, const vec<N,T> & v2 ) | 218 | vec<N,T> operator + ( const vec<N,T> & v1, const vec<N,T> & v2 ) |
219 | { vec<N,T> rt(v1); return rt += v2; } | 219 | { vec<N,T> rt(v1); return rt += v2; } |
220 | 220 | ||
221 | template <int N, class T> inline | 221 | template <int N, class T> inline |
222 | vec<N,T> operator - ( const vec<N,T> & v1, const vec<N,T> & v2 ) | 222 | vec<N,T> operator - ( const vec<N,T> & v1, const vec<N,T> & v2 ) |
223 | { vec<N,T> rt(v1); return rt -= v2; } | 223 | { vec<N,T> rt(v1); return rt -= v2; } |
224 | 224 | ||
225 | 225 | ||
226 | template <int N, class T> inline | 226 | template <int N, class T> inline |
227 | bool operator == ( const vec<N,T> & v1, const vec<N,T> & v2 ) | 227 | bool operator == ( const vec<N,T> & v1, const vec<N,T> & v2 ) |
228 | { | 228 | { |
229 | for(int i = 0; i < N; i++) | 229 | for(int i = 0; i < N; i++) |
230 | if(v1.v[i] != v2.v[i]) | 230 | if(v1.v[i] != v2.v[i]) |
231 | return false; | 231 | return false; |
232 | return true; | 232 | return true; |
233 | } | 233 | } |
234 | 234 | ||
235 | template <int N, class T> inline | 235 | template <int N, class T> inline |
236 | bool operator != ( const vec<N,T> & v1, const vec<N,T> & v2 ) | 236 | bool operator != ( const vec<N,T> & v1, const vec<N,T> & v2 ) |
237 | { return !(v1 == v2); } | 237 | { return !(v1 == v2); } |
238 | 238 | ||
239 | 239 | ||
240 | typedef vec<3,unsigned char> vec3ub; | 240 | typedef vec<3,unsigned char> vec3ub; |
241 | typedef vec<4,unsigned char> vec4ub; | 241 | typedef vec<4,unsigned char> vec4ub; |
242 | 242 | ||
243 | 243 | ||
244 | 244 | ||
245 | 245 | ||
246 | 246 | ||
247 | namespace GLH_REAL_NAMESPACE | 247 | namespace GLH_REAL_NAMESPACE |
248 | { | 248 | { |
249 | typedef GLH_REAL real; | 249 | typedef GLH_REAL real; |
250 | 250 | ||
251 | class line; | 251 | class line; |
252 | class plane; | 252 | class plane; |
253 | class matrix4; | 253 | class matrix4; |
254 | class quaternion; | 254 | class quaternion; |
255 | typedef quaternion rotation; | 255 | typedef quaternion rotation; |
256 | 256 | ||
257 | class vec2 : public vec<2,real> | 257 | class vec2 : public vec<2,real> |
258 | { | 258 | { |
259 | public: | 259 | public: |
260 | vec2(const real & t = real()) : vec<2,real>(t) | 260 | vec2(const real & t = real()) : vec<2,real>(t) |
261 | {} | 261 | {} |
262 | vec2(const vec<2,real> & t) : vec<2,real>(t) | 262 | vec2(const vec<2,real> & t) : vec<2,real>(t) |
263 | {} | 263 | {} |
264 | vec2(const real * tp) : vec<2,real>(tp) | 264 | vec2(const real * tp) : vec<2,real>(tp) |
265 | {} | 265 | {} |
266 | 266 | ||
267 | vec2(real x, real y ) | 267 | vec2(real x, real y ) |
268 | { v[0] = x; v[1] = y; } | 268 | { v[0] = x; v[1] = y; } |
269 | 269 | ||
270 | void get_value(real & x, real & y) const | 270 | void get_value(real & x, real & y) const |
271 | { x = v[0]; y = v[1]; } | 271 | { x = v[0]; y = v[1]; } |
272 | 272 | ||
273 | vec2 & set_value( const real & x, const real & y) | 273 | vec2 & set_value( const real & x, const real & y) |
274 | { v[0] = x; v[1] = y; return *this; } | 274 | { v[0] = x; v[1] = y; return *this; } |
275 | 275 | ||
276 | }; | 276 | }; |
277 | 277 | ||
278 | 278 | ||
279 | class vec3 : public vec<3,real> | 279 | class vec3 : public vec<3,real> |
280 | { | 280 | { |
281 | public: | 281 | public: |
282 | vec3(const real & t = real()) : vec<3,real>(t) | 282 | vec3(const real & t = real()) : vec<3,real>(t) |
283 | {} | 283 | {} |
284 | vec3(const vec<3,real> & t) : vec<3,real>(t) | 284 | vec3(const vec<3,real> & t) : vec<3,real>(t) |
285 | {} | 285 | {} |
286 | vec3(const real * tp) : vec<3,real>(tp) | 286 | vec3(const real * tp) : vec<3,real>(tp) |
287 | {} | 287 | {} |
288 | 288 | ||
289 | vec3(real x, real y, real z) | 289 | vec3(real x, real y, real z) |
290 | { v[0] = x; v[1] = y; v[2] = z; } | 290 | { v[0] = x; v[1] = y; v[2] = z; } |
291 | 291 | ||
292 | void get_value(real & x, real & y, real & z) const | 292 | void get_value(real & x, real & y, real & z) const |
293 | { x = v[0]; y = v[1]; z = v[2]; } | 293 | { x = v[0]; y = v[1]; z = v[2]; } |
294 | 294 | ||
295 | vec3 cross( const vec3 &rhs ) const | 295 | vec3 cross( const vec3 &rhs ) const |
296 | { | 296 | { |
297 | vec3 rt; | 297 | vec3 rt; |
298 | rt.v[0] = v[1]*rhs.v[2]-v[2]*rhs.v[1]; | 298 | rt.v[0] = v[1]*rhs.v[2]-v[2]*rhs.v[1]; |
299 | rt.v[1] = v[2]*rhs.v[0]-v[0]*rhs.v[2]; | 299 | rt.v[1] = v[2]*rhs.v[0]-v[0]*rhs.v[2]; |
300 | rt.v[2] = v[0]*rhs.v[1]-v[1]*rhs.v[0]; | 300 | rt.v[2] = v[0]*rhs.v[1]-v[1]*rhs.v[0]; |
301 | return rt; | 301 | return rt; |
302 | } | 302 | } |
303 | 303 | ||
304 | vec3 & set_value( const real & x, const real & y, const real & z) | 304 | vec3 & set_value( const real & x, const real & y, const real & z) |
305 | { v[0] = x; v[1] = y; v[2] = z; return *this; } | 305 | { v[0] = x; v[1] = y; v[2] = z; return *this; } |
306 | 306 | ||
307 | }; | 307 | }; |
308 | 308 | ||
309 | 309 | ||
310 | class vec4 : public vec<4,real> | 310 | class vec4 : public vec<4,real> |
311 | { | 311 | { |
312 | public: | 312 | public: |
313 | vec4(const real & t = real()) : vec<4,real>(t) | 313 | vec4(const real & t = real()) : vec<4,real>(t) |
314 | {} | 314 | {} |
315 | vec4(const vec<4,real> & t) : vec<4,real>(t) | 315 | vec4(const vec<4,real> & t) : vec<4,real>(t) |
316 | {} | 316 | {} |
317 | 317 | ||
318 | vec4(const vec<3,real> & t, real fourth) | 318 | vec4(const vec<3,real> & t, real fourth) |
319 | 319 | ||
320 | { v[0] = t.v[0]; v[1] = t.v[1]; v[2] = t.v[2]; v[3] = fourth; } | 320 | { v[0] = t.v[0]; v[1] = t.v[1]; v[2] = t.v[2]; v[3] = fourth; } |
321 | vec4(const real * tp) : vec<4,real>(tp) | 321 | vec4(const real * tp) : vec<4,real>(tp) |
322 | {} | 322 | {} |
323 | vec4(real x, real y, real z, real w) | 323 | vec4(real x, real y, real z, real w) |
324 | { v[0] = x; v[1] = y; v[2] = z; v[3] = w; } | 324 | { v[0] = x; v[1] = y; v[2] = z; v[3] = w; } |
325 | 325 | ||
326 | void get_value(real & x, real & y, real & z, real & w) const | 326 | void get_value(real & x, real & y, real & z, real & w) const |
327 | { x = v[0]; y = v[1]; z = v[2]; w = v[3]; } | 327 | { x = v[0]; y = v[1]; z = v[2]; w = v[3]; } |
328 | 328 | ||
329 | vec4 & set_value( const real & x, const real & y, const real & z, const real & w) | 329 | vec4 & set_value( const real & x, const real & y, const real & z, const real & w) |
330 | { v[0] = x; v[1] = y; v[2] = z; v[3] = w; return *this; } | 330 | { v[0] = x; v[1] = y; v[2] = z; v[3] = w; return *this; } |
331 | }; | 331 | }; |
332 | 332 | ||
333 | inline | 333 | inline |
334 | vec3 homogenize(const vec4 & v) | 334 | vec3 homogenize(const vec4 & v) |
335 | { | 335 | { |
336 | vec3 rt; | 336 | vec3 rt; |
337 | assert(v.v[3] != GLH_ZERO); | 337 | assert(v.v[3] != GLH_ZERO); |
338 | rt.v[0] = v.v[0]/v.v[3]; | 338 | rt.v[0] = v.v[0]/v.v[3]; |
339 | rt.v[1] = v.v[1]/v.v[3]; | 339 | rt.v[1] = v.v[1]/v.v[3]; |
340 | rt.v[2] = v.v[2]/v.v[3]; | 340 | rt.v[2] = v.v[2]/v.v[3]; |
341 | return rt; | 341 | return rt; |
342 | } | 342 | } |
343 | 343 | ||
344 | 344 | ||
345 | 345 | ||
346 | class line | 346 | class line |
347 | { | 347 | { |
348 | public: | 348 | public: |
349 | 349 | ||
350 | line() | 350 | line() |
351 | { set_value(vec3(0,0,0),vec3(0,0,1)); } | 351 | { set_value(vec3(0,0,0),vec3(0,0,1)); } |
352 | 352 | ||
353 | line( const vec3 & p0, const vec3 &p1) | 353 | line( const vec3 & p0, const vec3 &p1) |
354 | { set_value(p0,p1); } | 354 | { set_value(p0,p1); } |
355 | 355 | ||
356 | void set_value( const vec3 &p0, const vec3 &p1) | 356 | void set_value( const vec3 &p0, const vec3 &p1) |
357 | { | 357 | { |
358 | position = p0; | 358 | position = p0; |
359 | direction = p1-p0; | 359 | direction = p1-p0; |
360 | direction.normalize(); | 360 | direction.normalize(); |
361 | } | 361 | } |
362 | 362 | ||
363 | bool get_closest_points(const line &line2, | 363 | bool get_closest_points(const line &line2, |
364 | vec3 &pointOnThis, | 364 | vec3 &pointOnThis, |
365 | vec3 &pointOnThat) | 365 | vec3 &pointOnThat) |
366 | { | 366 | { |
367 | 367 | ||
368 | // quick check to see if parallel -- if so, quit. | 368 | // quick check to see if parallel -- if so, quit. |
369 | if(fabs(direction.dot(line2.direction)) == 1.0) | 369 | if(fabs(direction.dot(line2.direction)) == 1.0) |
370 | return 0; | 370 | return 0; |
371 | line l2 = line2; | 371 | line l2 = line2; |
372 | 372 | ||
373 | // Algorithm: Brian Jean | 373 | // Algorithm: Brian Jean |
374 | // | 374 | // |
375 | register real u; | 375 | register real u; |
376 | register real v; | 376 | register real v; |
377 | vec3 Vr = direction; | 377 | vec3 Vr = direction; |
378 | vec3 Vs = l2.direction; | 378 | vec3 Vs = l2.direction; |
379 | register real Vr_Dot_Vs = Vr.dot(Vs); | 379 | register real Vr_Dot_Vs = Vr.dot(Vs); |
380 | register real detA = real(1.0 - (Vr_Dot_Vs * Vr_Dot_Vs)); | 380 | register real detA = real(1.0 - (Vr_Dot_Vs * Vr_Dot_Vs)); |
381 | vec3 C = l2.position - position; | 381 | vec3 C = l2.position - position; |
382 | register real C_Dot_Vr = C.dot(Vr); | 382 | register real C_Dot_Vr = C.dot(Vr); |
383 | register real C_Dot_Vs = C.dot(Vs); | 383 | register real C_Dot_Vs = C.dot(Vs); |
384 | 384 | ||
385 | u = (C_Dot_Vr - Vr_Dot_Vs * C_Dot_Vs)/detA; | 385 | u = (C_Dot_Vr - Vr_Dot_Vs * C_Dot_Vs)/detA; |
386 | v = (C_Dot_Vr * Vr_Dot_Vs - C_Dot_Vs)/detA; | 386 | v = (C_Dot_Vr * Vr_Dot_Vs - C_Dot_Vs)/detA; |
387 | 387 | ||
388 | pointOnThis = position; | 388 | pointOnThis = position; |
389 | pointOnThis += direction * u; | 389 | pointOnThis += direction * u; |
390 | pointOnThat = l2.position; | 390 | pointOnThat = l2.position; |
391 | pointOnThat += l2.direction * v; | 391 | pointOnThat += l2.direction * v; |
392 | 392 | ||
393 | return 1; | 393 | return 1; |
394 | } | 394 | } |
395 | 395 | ||
396 | vec3 get_closest_point(const vec3 &point) | 396 | vec3 get_closest_point(const vec3 &point) |
397 | { | 397 | { |
398 | vec3 np = point - position; | 398 | vec3 np = point - position; |
399 | vec3 rp = direction*direction.dot(np)+position; | 399 | vec3 rp = direction*direction.dot(np)+position; |
400 | return rp; | 400 | return rp; |
401 | } | 401 | } |
402 | 402 | ||
403 | const vec3 & get_position() const {return position;} | 403 | const vec3 & get_position() const {return position;} |
404 | 404 | ||
405 | const vec3 & get_direction() const {return direction;} | 405 | const vec3 & get_direction() const {return direction;} |
406 | 406 | ||
407 | //protected: | 407 | //protected: |
408 | vec3 position; | 408 | vec3 position; |
409 | vec3 direction; | 409 | vec3 direction; |
410 | }; | 410 | }; |
411 | 411 | ||
412 | 412 | ||
413 | 413 | ||
414 | 414 | ||
415 | 415 | ||
416 | 416 | ||
417 | 417 | ||
418 | 418 | ||
419 | 419 | ||
420 | 420 | ||
421 | 421 | ||
422 | 422 | ||
423 | 423 | ||
424 | 424 | ||
425 | 425 | ||
426 | 426 | ||
427 | 427 | ||
428 | 428 | ||
429 | 429 | ||
430 | 430 | ||
431 | 431 | ||
432 | 432 | ||
433 | 433 | ||
434 | 434 | ||
435 | 435 | ||
436 | 436 | ||
437 | 437 | ||
438 | 438 | ||
439 | 439 | ||
440 | // matrix | 440 | // matrix |
441 | 441 | ||
442 | 442 | ||
443 | class matrix4 | 443 | class matrix4 |
444 | { | 444 | { |
445 | 445 | ||
446 | public: | 446 | public: |
447 | 447 | ||
448 | matrix4() { make_identity(); } | 448 | matrix4() { make_identity(); } |
449 | 449 | ||
450 | matrix4( real r ) | 450 | matrix4( real r ) |
451 | { set_value(r); } | 451 | { set_value(r); } |
452 | 452 | ||
453 | matrix4( real * m ) | 453 | matrix4( real * m ) |
454 | { set_value(m); } | 454 | { set_value(m); } |
455 | 455 | ||
456 | matrix4( real a00, real a01, real a02, real a03, | 456 | matrix4( real a00, real a01, real a02, real a03, |
457 | real a10, real a11, real a12, real a13, | 457 | real a10, real a11, real a12, real a13, |
458 | real a20, real a21, real a22, real a23, | 458 | real a20, real a21, real a22, real a23, |
459 | real a30, real a31, real a32, real a33 ) | 459 | real a30, real a31, real a32, real a33 ) |
460 | { | 460 | { |
461 | element(0,0) = a00; | 461 | element(0,0) = a00; |
462 | element(0,1) = a01; | 462 | element(0,1) = a01; |
463 | element(0,2) = a02; | 463 | element(0,2) = a02; |
464 | element(0,3) = a03; | 464 | element(0,3) = a03; |
465 | 465 | ||
466 | element(1,0) = a10; | 466 | element(1,0) = a10; |
467 | element(1,1) = a11; | 467 | element(1,1) = a11; |
468 | element(1,2) = a12; | 468 | element(1,2) = a12; |
469 | element(1,3) = a13; | 469 | element(1,3) = a13; |
470 | 470 | ||
471 | element(2,0) = a20; | 471 | element(2,0) = a20; |
472 | element(2,1) = a21; | 472 | element(2,1) = a21; |
473 | element(2,2) = a22; | 473 | element(2,2) = a22; |
474 | element(2,3) = a23; | 474 | element(2,3) = a23; |
475 | 475 | ||
476 | element(3,0) = a30; | 476 | element(3,0) = a30; |
477 | element(3,1) = a31; | 477 | element(3,1) = a31; |
478 | element(3,2) = a32; | 478 | element(3,2) = a32; |
479 | element(3,3) = a33; | 479 | element(3,3) = a33; |
480 | } | 480 | } |
481 | 481 | ||
482 | 482 | ||
483 | void get_value( real * mp ) const | 483 | void get_value( real * mp ) const |
484 | { | 484 | { |
485 | int c = 0; | 485 | int c = 0; |
486 | for(int j=0; j < 4; j++) | 486 | for(int j=0; j < 4; j++) |
487 | for(int i=0; i < 4; i++) | 487 | for(int i=0; i < 4; i++) |
488 | mp[c++] = element(i,j); | 488 | mp[c++] = element(i,j); |
489 | } | 489 | } |
490 | 490 | ||
491 | 491 | ||
492 | const real * get_value() const | 492 | const real * get_value() const |
493 | { return m; } | 493 | { return m; } |
494 | 494 | ||
495 | void set_value( real * mp) | 495 | void set_value( real * mp) |
496 | { | 496 | { |
497 | int c = 0; | 497 | int c = 0; |
498 | for(int j=0; j < 4; j++) | 498 | for(int j=0; j < 4; j++) |
499 | for(int i=0; i < 4; i++) | 499 | for(int i=0; i < 4; i++) |
500 | element(i,j) = mp[c++]; | 500 | element(i,j) = mp[c++]; |
501 | } | 501 | } |
502 | 502 | ||
503 | void set_value( real r ) | 503 | void set_value( real r ) |
504 | { | 504 | { |
505 | for(int i=0; i < 4; i++) | 505 | for(int i=0; i < 4; i++) |
506 | for(int j=0; j < 4; j++) | 506 | for(int j=0; j < 4; j++) |
507 | element(i,j) = r; | 507 | element(i,j) = r; |
508 | } | 508 | } |
509 | 509 | ||
510 | void make_identity() | 510 | void make_identity() |
511 | { | 511 | { |
512 | element(0,0) = 1.0; | 512 | element(0,0) = 1.0; |
513 | element(0,1) = 0.0; | 513 | element(0,1) = 0.0; |
514 | element(0,2) = 0.0; | 514 | element(0,2) = 0.0; |
515 | element(0,3) = 0.0; | 515 | element(0,3) = 0.0; |
516 | 516 | ||
517 | element(1,0) = 0.0; | 517 | element(1,0) = 0.0; |
518 | element(1,1) = 1.0; | 518 | element(1,1) = 1.0; |
519 | element(1,2) = 0.0; | 519 | element(1,2) = 0.0; |
520 | element(1,3) = 0.0; | 520 | element(1,3) = 0.0; |
521 | 521 | ||
522 | element(2,0) = 0.0; | 522 | element(2,0) = 0.0; |
523 | element(2,1) = 0.0; | 523 | element(2,1) = 0.0; |
524 | element(2,2) = 1.0; | 524 | element(2,2) = 1.0; |
525 | element(2,3) = 0.0; | 525 | element(2,3) = 0.0; |
526 | 526 | ||
527 | element(3,0) = 0.0; | 527 | element(3,0) = 0.0; |
528 | element(3,1) = 0.0; | 528 | element(3,1) = 0.0; |
529 | element(3,2) = 0.0; | 529 | element(3,2) = 0.0; |
530 | element(3,3) = 1.0; | 530 | element(3,3) = 1.0; |
531 | } | 531 | } |
532 | 532 | ||
533 | 533 | ||
534 | static matrix4 identity() | 534 | static matrix4 identity() |
535 | { | 535 | { |
536 | static matrix4 mident ( | 536 | static matrix4 mident ( |
537 | 1.0, 0.0, 0.0, 0.0, | 537 | 1.0, 0.0, 0.0, 0.0, |
538 | 0.0, 1.0, 0.0, 0.0, | 538 | 0.0, 1.0, 0.0, 0.0, |
539 | 0.0, 0.0, 1.0, 0.0, | 539 | 0.0, 0.0, 1.0, 0.0, |
540 | 0.0, 0.0, 0.0, 1.0 ); | 540 | 0.0, 0.0, 0.0, 1.0 ); |
541 | return mident; | 541 | return mident; |
542 | } | 542 | } |
543 | 543 | ||
544 | 544 | ||
545 | void set_scale( real s ) | 545 | void set_scale( real s ) |
546 | { | 546 | { |
547 | element(0,0) = s; | 547 | element(0,0) = s; |
548 | element(1,1) = s; | 548 | element(1,1) = s; |
549 | element(2,2) = s; | 549 | element(2,2) = s; |
550 | } | 550 | } |
551 | 551 | ||
552 | void set_scale( const vec3 & s ) | 552 | void set_scale( const vec3 & s ) |
553 | { | 553 | { |
554 | element(0,0) = s.v[0]; | 554 | element(0,0) = s.v[0]; |
555 | element(1,1) = s.v[1]; | 555 | element(1,1) = s.v[1]; |
556 | element(2,2) = s.v[2]; | 556 | element(2,2) = s.v[2]; |
557 | } | 557 | } |
558 | 558 | ||
559 | 559 | ||
560 | void set_translate( const vec3 & t ) | 560 | void set_translate( const vec3 & t ) |
561 | { | 561 | { |
562 | element(0,3) = t.v[0]; | 562 | element(0,3) = t.v[0]; |
563 | element(1,3) = t.v[1]; | 563 | element(1,3) = t.v[1]; |
564 | element(2,3) = t.v[2]; | 564 | element(2,3) = t.v[2]; |
565 | } | 565 | } |
566 | 566 | ||
567 | void set_row(int r, const vec4 & t) | 567 | void set_row(int r, const vec4 & t) |
568 | { | 568 | { |
569 | element(r,0) = t.v[0]; | 569 | element(r,0) = t.v[0]; |
570 | element(r,1) = t.v[1]; | 570 | element(r,1) = t.v[1]; |
571 | element(r,2) = t.v[2]; | 571 | element(r,2) = t.v[2]; |
572 | element(r,3) = t.v[3]; | 572 | element(r,3) = t.v[3]; |
573 | } | 573 | } |
574 | 574 | ||
575 | void set_column(int c, const vec4 & t) | 575 | void set_column(int c, const vec4 & t) |
576 | { | 576 | { |
577 | element(0,c) = t.v[0]; | 577 | element(0,c) = t.v[0]; |
578 | element(1,c) = t.v[1]; | 578 | element(1,c) = t.v[1]; |
579 | element(2,c) = t.v[2]; | 579 | element(2,c) = t.v[2]; |
580 | element(3,c) = t.v[3]; | 580 | element(3,c) = t.v[3]; |
581 | } | 581 | } |
582 | 582 | ||
583 | 583 | ||
584 | void get_row(int r, vec4 & t) const | 584 | void get_row(int r, vec4 & t) const |
585 | { | 585 | { |
586 | t.v[0] = element(r,0); | 586 | t.v[0] = element(r,0); |
587 | t.v[1] = element(r,1); | 587 | t.v[1] = element(r,1); |
588 | t.v[2] = element(r,2); | 588 | t.v[2] = element(r,2); |
589 | t.v[3] = element(r,3); | 589 | t.v[3] = element(r,3); |
590 | } | 590 | } |
591 | 591 | ||
592 | vec4 get_row(int r) const | 592 | vec4 get_row(int r) const |
593 | { | 593 | { |
594 | vec4 v; get_row(r, v); | 594 | vec4 v; get_row(r, v); |
595 | return v; | 595 | return v; |
596 | } | 596 | } |
597 | 597 | ||
598 | void get_column(int c, vec4 & t) const | 598 | void get_column(int c, vec4 & t) const |
599 | { | 599 | { |
600 | t.v[0] = element(0,c); | 600 | t.v[0] = element(0,c); |
601 | t.v[1] = element(1,c); | 601 | t.v[1] = element(1,c); |
602 | t.v[2] = element(2,c); | 602 | t.v[2] = element(2,c); |
603 | t.v[3] = element(3,c); | 603 | t.v[3] = element(3,c); |
604 | } | 604 | } |
605 | 605 | ||
606 | vec4 get_column(int c) const | 606 | vec4 get_column(int c) const |
607 | { | 607 | { |
608 | vec4 v; get_column(c, v); | 608 | vec4 v; get_column(c, v); |
609 | return v; | 609 | return v; |
610 | } | 610 | } |
611 | 611 | ||
612 | matrix4 inverse() const | 612 | matrix4 inverse() const |
613 | { | 613 | { |
614 | matrix4 minv; | 614 | matrix4 minv; |
615 | 615 | ||
616 | real r1[8], r2[8], r3[8], r4[8]; | 616 | real r1[8], r2[8], r3[8], r4[8]; |
617 | real *s[4], *tmprow; | 617 | real *s[4], *tmprow; |
618 | 618 | ||
619 | s[0] = &r1[0]; | 619 | s[0] = &r1[0]; |
620 | s[1] = &r2[0]; | 620 | s[1] = &r2[0]; |
621 | s[2] = &r3[0]; | 621 | s[2] = &r3[0]; |
622 | s[3] = &r4[0]; | 622 | s[3] = &r4[0]; |
623 | 623 | ||
624 | register int i,j,p,jj; | 624 | register int i,j,p,jj; |
625 | for(i=0;i<4;i++) | 625 | for(i=0;i<4;i++) |
626 | { | 626 | { |
627 | for(j=0;j<4;j++) | 627 | for(j=0;j<4;j++) |
628 | { | 628 | { |
629 | s[i][j] = element(i,j); | 629 | s[i][j] = element(i,j); |
630 | if(i==j) s[i][j+4] = 1.0; | 630 | if(i==j) s[i][j+4] = 1.0; |
631 | else s[i][j+4] = 0.0; | 631 | else s[i][j+4] = 0.0; |
632 | } | 632 | } |
633 | } | 633 | } |
634 | real scp[4]; | 634 | real scp[4]; |
635 | for(i=0;i<4;i++) | 635 | for(i=0;i<4;i++) |
636 | { | 636 | { |
637 | scp[i] = real(fabs(s[i][0])); | 637 | scp[i] = real(fabs(s[i][0])); |
638 | for(j=1;j<4;j++) | 638 | for(j=1;j<4;j++) |
639 | if(real(fabs(s[i][j])) > scp[i]) scp[i] = real(fabs(s[i][j])); | 639 | if(real(fabs(s[i][j])) > scp[i]) scp[i] = real(fabs(s[i][j])); |
640 | if(scp[i] == 0.0) return minv; // singular matrix! | 640 | if(scp[i] == 0.0) return minv; // singular matrix! |
641 | } | 641 | } |
642 | 642 | ||
643 | int pivot_to; | 643 | int pivot_to; |
644 | real scp_max; | 644 | real scp_max; |
645 | for(i=0;i<4;i++) | 645 | for(i=0;i<4;i++) |
646 | { | 646 | { |
647 | // select pivot row | 647 | // select pivot row |
648 | pivot_to = i; | 648 | pivot_to = i; |
649 | scp_max = real(fabs(s[i][i]/scp[i])); | 649 | scp_max = real(fabs(s[i][i]/scp[i])); |
650 | // find out which row should be on top | 650 | // find out which row should be on top |
651 | for(p=i+1;p<4;p++) | 651 | for(p=i+1;p<4;p++) |
652 | if(real(fabs(s[p][i]/scp[p])) > scp_max) | 652 | if(real(fabs(s[p][i]/scp[p])) > scp_max) |
653 | { scp_max = real(fabs(s[p][i]/scp[p])); pivot_to = p; } | 653 | { scp_max = real(fabs(s[p][i]/scp[p])); pivot_to = p; } |
654 | // Pivot if necessary | 654 | // Pivot if necessary |
655 | if(pivot_to != i) | 655 | if(pivot_to != i) |
656 | { | 656 | { |
657 | tmprow = s[i]; | 657 | tmprow = s[i]; |
658 | s[i] = s[pivot_to]; | 658 | s[i] = s[pivot_to]; |
659 | s[pivot_to] = tmprow; | 659 | s[pivot_to] = tmprow; |
660 | real tmpscp; | 660 | real tmpscp; |
661 | tmpscp = scp[i]; | 661 | tmpscp = scp[i]; |
662 | scp[i] = scp[pivot_to]; | 662 | scp[i] = scp[pivot_to]; |
663 | scp[pivot_to] = tmpscp; | 663 | scp[pivot_to] = tmpscp; |
664 | } | 664 | } |
665 | 665 | ||
666 | real mji; | 666 | real mji; |
667 | // perform gaussian elimination | 667 | // perform gaussian elimination |
668 | for(j=i+1;j<4;j++) | 668 | for(j=i+1;j<4;j++) |
669 | { | 669 | { |
670 | mji = s[j][i]/s[i][i]; | 670 | mji = s[j][i]/s[i][i]; |
671 | s[j][i] = 0.0; | 671 | s[j][i] = 0.0; |
672 | for(jj=i+1;jj<8;jj++) | 672 | for(jj=i+1;jj<8;jj++) |
673 | s[j][jj] -= mji*s[i][jj]; | 673 | s[j][jj] -= mji*s[i][jj]; |
674 | } | 674 | } |
675 | } | 675 | } |
676 | if(s[3][3] == 0.0) return minv; // singular matrix! | 676 | if(s[3][3] == 0.0) return minv; // singular matrix! |
677 | 677 | ||
678 | // | 678 | // |
679 | // Now we have an upper triangular matrix. | 679 | // Now we have an upper triangular matrix. |
680 | // | 680 | // |
681 | // x x x x | y y y y | 681 | // x x x x | y y y y |
682 | // 0 x x x | y y y y | 682 | // 0 x x x | y y y y |
683 | // 0 0 x x | y y y y | 683 | // 0 0 x x | y y y y |
684 | // 0 0 0 x | y y y y | 684 | // 0 0 0 x | y y y y |
685 | // | 685 | // |
686 | // we'll back substitute to get the inverse | 686 | // we'll back substitute to get the inverse |
687 | // | 687 | // |
688 | // 1 0 0 0 | z z z z | 688 | // 1 0 0 0 | z z z z |
689 | // 0 1 0 0 | z z z z | 689 | // 0 1 0 0 | z z z z |
690 | // 0 0 1 0 | z z z z | 690 | // 0 0 1 0 | z z z z |
691 | // 0 0 0 1 | z z z z | 691 | // 0 0 0 1 | z z z z |
692 | // | 692 | // |
693 | 693 | ||
694 | real mij; | 694 | real mij; |
695 | for(i=3;i>0;i--) | 695 | for(i=3;i>0;i--) |
696 | { | 696 | { |
697 | for(j=i-1;j > -1; j--) | 697 | for(j=i-1;j > -1; j--) |
698 | { | 698 | { |
699 | mij = s[j][i]/s[i][i]; | 699 | mij = s[j][i]/s[i][i]; |
700 | for(jj=j+1;jj<8;jj++) | 700 | for(jj=j+1;jj<8;jj++) |
701 | s[j][jj] -= mij*s[i][jj]; | 701 | s[j][jj] -= mij*s[i][jj]; |
702 | } | 702 | } |
703 | } | 703 | } |
704 | 704 | ||
705 | for(i=0;i<4;i++) | 705 | for(i=0;i<4;i++) |
706 | for(j=0;j<4;j++) | 706 | for(j=0;j<4;j++) |
707 | minv(i,j) = s[i][j+4] / s[i][i]; | 707 | minv(i,j) = s[i][j+4] / s[i][i]; |
708 | 708 | ||
709 | return minv; | 709 | return minv; |
710 | } | 710 | } |
711 | 711 | ||
712 | 712 | ||
713 | matrix4 transpose() const | 713 | matrix4 transpose() const |
714 | { | 714 | { |
715 | matrix4 mtrans; | 715 | matrix4 mtrans; |
716 | 716 | ||
717 | for(int i=0;i<4;i++) | 717 | for(int i=0;i<4;i++) |
718 | for(int j=0;j<4;j++) | 718 | for(int j=0;j<4;j++) |
719 | mtrans(i,j) = element(j,i); | 719 | mtrans(i,j) = element(j,i); |
720 | return mtrans; | 720 | return mtrans; |
721 | } | 721 | } |
722 | 722 | ||
723 | matrix4 & mult_right( const matrix4 & b ) | 723 | matrix4 & mult_right( const matrix4 & b ) |
724 | { | 724 | { |
725 | matrix4 mt(*this); | 725 | matrix4 mt(*this); |
726 | set_value(real(0)); | 726 | set_value(real(0)); |
727 | 727 | ||
728 | for(int i=0; i < 4; i++) | 728 | for(int i=0; i < 4; i++) |
729 | for(int j=0; j < 4; j++) | 729 | for(int j=0; j < 4; j++) |
730 | for(int c=0; c < 4; c++) | 730 | for(int c=0; c < 4; c++) |
731 | element(i,j) += mt(i,c) * b(c,j); | 731 | element(i,j) += mt(i,c) * b(c,j); |
732 | return *this; | 732 | return *this; |
733 | } | 733 | } |
734 | 734 | ||
735 | matrix4 & mult_left( const matrix4 & b ) | 735 | matrix4 & mult_left( const matrix4 & b ) |
736 | { | 736 | { |
737 | matrix4 mt(*this); | 737 | matrix4 mt(*this); |
738 | set_value(real(0)); | 738 | set_value(real(0)); |
739 | 739 | ||
740 | for(int i=0; i < 4; i++) | 740 | for(int i=0; i < 4; i++) |
741 | for(int j=0; j < 4; j++) | 741 | for(int j=0; j < 4; j++) |
742 | for(int c=0; c < 4; c++) | 742 | for(int c=0; c < 4; c++) |
743 | element(i,j) += b(i,c) * mt(c,j); | 743 | element(i,j) += b(i,c) * mt(c,j); |
744 | return *this; | 744 | return *this; |
745 | } | 745 | } |
746 | 746 | ||
747 | // dst = M * src | 747 | // dst = M * src |
748 | void mult_matrix_vec( const vec3 &src, vec3 &dst ) const | 748 | void mult_matrix_vec( const vec3 &src, vec3 &dst ) const |
749 | { | 749 | { |
750 | real w = ( | 750 | real w = ( |
751 | src.v[0] * element(3,0) + | 751 | src.v[0] * element(3,0) + |
752 | src.v[1] * element(3,1) + | 752 | src.v[1] * element(3,1) + |
753 | src.v[2] * element(3,2) + | 753 | src.v[2] * element(3,2) + |
754 | element(3,3) ); | 754 | element(3,3) ); |
755 | 755 | ||
756 | assert(w != GLH_ZERO); | 756 | assert(w != GLH_ZERO); |
757 | 757 | ||
758 | dst.v[0] = ( | 758 | dst.v[0] = ( |
759 | src.v[0] * element(0,0) + | 759 | src.v[0] * element(0,0) + |
760 | src.v[1] * element(0,1) + | 760 | src.v[1] * element(0,1) + |
761 | src.v[2] * element(0,2) + | 761 | src.v[2] * element(0,2) + |
762 | element(0,3) ) / w; | 762 | element(0,3) ) / w; |
763 | dst.v[1] = ( | 763 | dst.v[1] = ( |
764 | src.v[0] * element(1,0) + | 764 | src.v[0] * element(1,0) + |
765 | src.v[1] * element(1,1) + | 765 | src.v[1] * element(1,1) + |
766 | src.v[2] * element(1,2) + | 766 | src.v[2] * element(1,2) + |
767 | element(1,3) ) / w; | 767 | element(1,3) ) / w; |
768 | dst.v[2] = ( | 768 | dst.v[2] = ( |
769 | src.v[0] * element(2,0) + | 769 | src.v[0] * element(2,0) + |
770 | src.v[1] * element(2,1) + | 770 | src.v[1] * element(2,1) + |
771 | src.v[2] * element(2,2) + | 771 | src.v[2] * element(2,2) + |
772 | element(2,3) ) / w; | 772 | element(2,3) ) / w; |
773 | } | 773 | } |
774 | 774 | ||
775 | void mult_matrix_vec( vec3 & src_and_dst) const | 775 | void mult_matrix_vec( vec3 & src_and_dst) const |
776 | { mult_matrix_vec(vec3(src_and_dst), src_and_dst); } | 776 | { mult_matrix_vec(vec3(src_and_dst), src_and_dst); } |
777 | 777 | ||
778 | 778 | ||
779 | // dst = src * M | 779 | // dst = src * M |
780 | void mult_vec_matrix( const vec3 &src, vec3 &dst ) const | 780 | void mult_vec_matrix( const vec3 &src, vec3 &dst ) const |
781 | { | 781 | { |
782 | real w = ( | 782 | real w = ( |
783 | src.v[0] * element(0,3) + | 783 | src.v[0] * element(0,3) + |
784 | src.v[1] * element(1,3) + | 784 | src.v[1] * element(1,3) + |
785 | src.v[2] * element(2,3) + | 785 | src.v[2] * element(2,3) + |
786 | element(3,3) ); | 786 | element(3,3) ); |
787 | 787 | ||
788 | assert(w != GLH_ZERO); | 788 | assert(w != GLH_ZERO); |
789 | 789 | ||
790 | dst.v[0] = ( | 790 | dst.v[0] = ( |
791 | src.v[0] * element(0,0) + | 791 | src.v[0] * element(0,0) + |
792 | src.v[1] * element(1,0) + | 792 | src.v[1] * element(1,0) + |
793 | src.v[2] * element(2,0) + | 793 | src.v[2] * element(2,0) + |
794 | element(3,0) ) / w; | 794 | element(3,0) ) / w; |
795 | dst.v[1] = ( | 795 | dst.v[1] = ( |
796 | src.v[0] * element(0,1) + | 796 | src.v[0] * element(0,1) + |
797 | src.v[1] * element(1,1) + | 797 | src.v[1] * element(1,1) + |
798 | src.v[2] * element(2,1) + | 798 | src.v[2] * element(2,1) + |
799 | element(3,1) ) / w; | 799 | element(3,1) ) / w; |
800 | dst.v[2] = ( | 800 | dst.v[2] = ( |
801 | src.v[0] * element(0,2) + | 801 | src.v[0] * element(0,2) + |
802 | src.v[1] * element(1,2) + | 802 | src.v[1] * element(1,2) + |
803 | src.v[2] * element(2,2) + | 803 | src.v[2] * element(2,2) + |
804 | element(3,2) ) / w; | 804 | element(3,2) ) / w; |
805 | } | 805 | } |
806 | 806 | ||
807 | 807 | ||
808 | void mult_vec_matrix( vec3 & src_and_dst) const | 808 | void mult_vec_matrix( vec3 & src_and_dst) const |
809 | { mult_vec_matrix(vec3(src_and_dst), src_and_dst); } | 809 | { mult_vec_matrix(vec3(src_and_dst), src_and_dst); } |
810 | 810 | ||
811 | // dst = M * src | 811 | // dst = M * src |
812 | void mult_matrix_vec( const vec4 &src, vec4 &dst ) const | 812 | void mult_matrix_vec( const vec4 &src, vec4 &dst ) const |
813 | { | 813 | { |
814 | dst.v[0] = ( | 814 | dst.v[0] = ( |
815 | src.v[0] * element(0,0) + | 815 | src.v[0] * element(0,0) + |
816 | src.v[1] * element(0,1) + | 816 | src.v[1] * element(0,1) + |
817 | src.v[2] * element(0,2) + | 817 | src.v[2] * element(0,2) + |
818 | src.v[3] * element(0,3)); | 818 | src.v[3] * element(0,3)); |
819 | dst.v[1] = ( | 819 | dst.v[1] = ( |
820 | src.v[0] * element(1,0) + | 820 | src.v[0] * element(1,0) + |
821 | src.v[1] * element(1,1) + | 821 | src.v[1] * element(1,1) + |
822 | src.v[2] * element(1,2) + | 822 | src.v[2] * element(1,2) + |
823 | src.v[3] * element(1,3)); | 823 | src.v[3] * element(1,3)); |
824 | dst.v[2] = ( | 824 | dst.v[2] = ( |
825 | src.v[0] * element(2,0) + | 825 | src.v[0] * element(2,0) + |
826 | src.v[1] * element(2,1) + | 826 | src.v[1] * element(2,1) + |
827 | src.v[2] * element(2,2) + | 827 | src.v[2] * element(2,2) + |
828 | src.v[3] * element(2,3)); | 828 | src.v[3] * element(2,3)); |
829 | dst.v[3] = ( | 829 | dst.v[3] = ( |
830 | src.v[0] * element(3,0) + | 830 | src.v[0] * element(3,0) + |
831 | src.v[1] * element(3,1) + | 831 | src.v[1] * element(3,1) + |
832 | src.v[2] * element(3,2) + | 832 | src.v[2] * element(3,2) + |
833 | src.v[3] * element(3,3)); | 833 | src.v[3] * element(3,3)); |
834 | } | 834 | } |
835 | 835 | ||
836 | void mult_matrix_vec( vec4 & src_and_dst) const | 836 | void mult_matrix_vec( vec4 & src_and_dst) const |
837 | { mult_matrix_vec(vec4(src_and_dst), src_and_dst); } | 837 | { mult_matrix_vec(vec4(src_and_dst), src_and_dst); } |
838 | 838 | ||
839 | 839 | ||
840 | // dst = src * M | 840 | // dst = src * M |
841 | void mult_vec_matrix( const vec4 &src, vec4 &dst ) const | 841 | void mult_vec_matrix( const vec4 &src, vec4 &dst ) const |
842 | { | 842 | { |
843 | dst.v[0] = ( | 843 | dst.v[0] = ( |
844 | src.v[0] * element(0,0) + | 844 | src.v[0] * element(0,0) + |
845 | src.v[1] * element(1,0) + | 845 | src.v[1] * element(1,0) + |
846 | src.v[2] * element(2,0) + | 846 | src.v[2] * element(2,0) + |
847 | src.v[3] * element(3,0)); | 847 | src.v[3] * element(3,0)); |
848 | dst.v[1] = ( | 848 | dst.v[1] = ( |
849 | src.v[0] * element(0,1) + | 849 | src.v[0] * element(0,1) + |
850 | src.v[1] * element(1,1) + | 850 | src.v[1] * element(1,1) + |
851 | src.v[2] * element(2,1) + | 851 | src.v[2] * element(2,1) + |
852 | src.v[3] * element(3,1)); | 852 | src.v[3] * element(3,1)); |
853 | dst.v[2] = ( | 853 | dst.v[2] = ( |
854 | src.v[0] * element(0,2) + | 854 | src.v[0] * element(0,2) + |
855 | src.v[1] * element(1,2) + | 855 | src.v[1] * element(1,2) + |
856 | src.v[2] * element(2,2) + | 856 | src.v[2] * element(2,2) + |
857 | src.v[3] * element(3,2)); | 857 | src.v[3] * element(3,2)); |
858 | dst.v[3] = ( | 858 | dst.v[3] = ( |
859 | src.v[0] * element(0,3) + | 859 | src.v[0] * element(0,3) + |
860 | src.v[1] * element(1,3) + | 860 | src.v[1] * element(1,3) + |
861 | src.v[2] * element(2,3) + | 861 | src.v[2] * element(2,3) + |
862 | src.v[3] * element(3,3)); | 862 | src.v[3] * element(3,3)); |
863 | } | 863 | } |
864 | 864 | ||
865 | 865 | ||
866 | void mult_vec_matrix( vec4 & src_and_dst) const | 866 | void mult_vec_matrix( vec4 & src_and_dst) const |
867 | { mult_vec_matrix(vec4(src_and_dst), src_and_dst); } | 867 | { mult_vec_matrix(vec4(src_and_dst), src_and_dst); } |
868 | 868 | ||
869 | 869 | ||
870 | // dst = M * src | 870 | // dst = M * src |
871 | void mult_matrix_dir( const vec3 &src, vec3 &dst ) const | 871 | void mult_matrix_dir( const vec3 &src, vec3 &dst ) const |
872 | { | 872 | { |
873 | dst.v[0] = ( | 873 | dst.v[0] = ( |
874 | src.v[0] * element(0,0) + | 874 | src.v[0] * element(0,0) + |
875 | src.v[1] * element(0,1) + | 875 | src.v[1] * element(0,1) + |
876 | src.v[2] * element(0,2) ) ; | 876 | src.v[2] * element(0,2) ) ; |
877 | dst.v[1] = ( | 877 | dst.v[1] = ( |
878 | src.v[0] * element(1,0) + | 878 | src.v[0] * element(1,0) + |
879 | src.v[1] * element(1,1) + | 879 | src.v[1] * element(1,1) + |
880 | src.v[2] * element(1,2) ) ; | 880 | src.v[2] * element(1,2) ) ; |
881 | dst.v[2] = ( | 881 | dst.v[2] = ( |
882 | src.v[0] * element(2,0) + | 882 | src.v[0] * element(2,0) + |
883 | src.v[1] * element(2,1) + | 883 | src.v[1] * element(2,1) + |
884 | src.v[2] * element(2,2) ) ; | 884 | src.v[2] * element(2,2) ) ; |
885 | } | 885 | } |
886 | 886 | ||
887 | 887 | ||
888 | void mult_matrix_dir( vec3 & src_and_dst) const | 888 | void mult_matrix_dir( vec3 & src_and_dst) const |
889 | { mult_matrix_dir(vec3(src_and_dst), src_and_dst); } | 889 | { mult_matrix_dir(vec3(src_and_dst), src_and_dst); } |
890 | 890 | ||
891 | 891 | ||
892 | // dst = src * M | 892 | // dst = src * M |
893 | void mult_dir_matrix( const vec3 &src, vec3 &dst ) const | 893 | void mult_dir_matrix( const vec3 &src, vec3 &dst ) const |
894 | { | 894 | { |
895 | dst.v[0] = ( | 895 | dst.v[0] = ( |
896 | src.v[0] * element(0,0) + | 896 | src.v[0] * element(0,0) + |
897 | src.v[1] * element(1,0) + | 897 | src.v[1] * element(1,0) + |
898 | src.v[2] * element(2,0) ) ; | 898 | src.v[2] * element(2,0) ) ; |
899 | dst.v[1] = ( | 899 | dst.v[1] = ( |
900 | src.v[0] * element(0,1) + | 900 | src.v[0] * element(0,1) + |
901 | src.v[1] * element(1,1) + | 901 | src.v[1] * element(1,1) + |
902 | src.v[2] * element(2,1) ) ; | 902 | src.v[2] * element(2,1) ) ; |
903 | dst.v[2] = ( | 903 | dst.v[2] = ( |
904 | src.v[0] * element(0,2) + | 904 | src.v[0] * element(0,2) + |
905 | src.v[1] * element(1,2) + | 905 | src.v[1] * element(1,2) + |
906 | src.v[2] * element(2,2) ) ; | 906 | src.v[2] * element(2,2) ) ; |
907 | } | 907 | } |
908 | 908 | ||
909 | 909 | ||
910 | void mult_dir_matrix( vec3 & src_and_dst) const | 910 | void mult_dir_matrix( vec3 & src_and_dst) const |
911 | { mult_dir_matrix(vec3(src_and_dst), src_and_dst); } | 911 | { mult_dir_matrix(vec3(src_and_dst), src_and_dst); } |
912 | 912 | ||
913 | 913 | ||
914 | real & operator () (int row, int col) | 914 | real & operator () (int row, int col) |
915 | { return element(row,col); } | 915 | { return element(row,col); } |
916 | 916 | ||
917 | const real & operator () (int row, int col) const | 917 | const real & operator () (int row, int col) const |
918 | { return element(row,col); } | 918 | { return element(row,col); } |
919 | 919 | ||
920 | real & element (int row, int col) | 920 | real & element (int row, int col) |
921 | { return m[row | (col<<2)]; } | 921 | { return m[row | (col<<2)]; } |
922 | 922 | ||
923 | const real & element (int row, int col) const | 923 | const real & element (int row, int col) const |
924 | { return m[row | (col<<2)]; } | 924 | { return m[row | (col<<2)]; } |
925 | 925 | ||
926 | matrix4 & operator *= ( const matrix4 & mat ) | 926 | matrix4 & operator *= ( const matrix4 & mat ) |
927 | { | 927 | { |
928 | mult_right( mat ); | 928 | mult_right( mat ); |
929 | return *this; | 929 | return *this; |
930 | } | 930 | } |
931 | 931 | ||
932 | matrix4 & operator *= ( const real & r ) | 932 | matrix4 & operator *= ( const real & r ) |
933 | { | 933 | { |
934 | for (int i = 0; i < 4; ++i) | 934 | for (int i = 0; i < 4; ++i) |
935 | { | 935 | { |
936 | element(0,i) *= r; | 936 | element(0,i) *= r; |
937 | element(1,i) *= r; | 937 | element(1,i) *= r; |
938 | element(2,i) *= r; | 938 | element(2,i) *= r; |
939 | element(3,i) *= r; | 939 | element(3,i) *= r; |
940 | } | 940 | } |
941 | return *this; | 941 | return *this; |
942 | } | 942 | } |
943 | 943 | ||
944 | matrix4 & operator += ( const matrix4 & mat ) | 944 | matrix4 & operator += ( const matrix4 & mat ) |
945 | { | 945 | { |
946 | for (int i = 0; i < 4; ++i) | 946 | for (int i = 0; i < 4; ++i) |
947 | { | 947 | { |
948 | element(0,i) += mat.element(0,i); | 948 | element(0,i) += mat.element(0,i); |
949 | element(1,i) += mat.element(1,i); | 949 | element(1,i) += mat.element(1,i); |
950 | element(2,i) += mat.element(2,i); | 950 | element(2,i) += mat.element(2,i); |
951 | element(3,i) += mat.element(3,i); | 951 | element(3,i) += mat.element(3,i); |
952 | } | 952 | } |
953 | return *this; | 953 | return *this; |
954 | } | 954 | } |
955 | 955 | ||
956 | friend matrix4 operator * ( const matrix4 & m1, const matrix4 & m2 ); | 956 | friend matrix4 operator * ( const matrix4 & m1, const matrix4 & m2 ); |
957 | friend bool operator == ( const matrix4 & m1, const matrix4 & m2 ); | 957 | friend bool operator == ( const matrix4 & m1, const matrix4 & m2 ); |
958 | friend bool operator != ( const matrix4 & m1, const matrix4 & m2 ); | 958 | friend bool operator != ( const matrix4 & m1, const matrix4 & m2 ); |
959 | 959 | ||
960 | //protected: | 960 | //protected: |
961 | real m[16]; | 961 | real m[16]; |
962 | }; | 962 | }; |
963 | 963 | ||
964 | inline | 964 | inline |
965 | matrix4 operator * ( const matrix4 & m1, const matrix4 & m2 ) | 965 | matrix4 operator * ( const matrix4 & m1, const matrix4 & m2 ) |
966 | { | 966 | { |
967 | matrix4 product; | 967 | matrix4 product; |
968 | 968 | ||
969 | product = m1; | 969 | product = m1; |
970 | product.mult_right(m2); | 970 | product.mult_right(m2); |
971 | 971 | ||
972 | return product; | 972 | return product; |
973 | } | 973 | } |
974 | 974 | ||
975 | inline | 975 | inline |
976 | bool operator ==( const matrix4 &m1, const matrix4 &m2 ) | 976 | bool operator ==( const matrix4 &m1, const matrix4 &m2 ) |
977 | { | 977 | { |
978 | return ( | 978 | return ( |
979 | m1(0,0) == m2(0,0) && | 979 | m1(0,0) == m2(0,0) && |
980 | m1(0,1) == m2(0,1) && | 980 | m1(0,1) == m2(0,1) && |
981 | m1(0,2) == m2(0,2) && | 981 | m1(0,2) == m2(0,2) && |
982 | m1(0,3) == m2(0,3) && | 982 | m1(0,3) == m2(0,3) && |
983 | m1(1,0) == m2(1,0) && | 983 | m1(1,0) == m2(1,0) && |
984 | m1(1,1) == m2(1,1) && | 984 | m1(1,1) == m2(1,1) && |
985 | m1(1,2) == m2(1,2) && | 985 | m1(1,2) == m2(1,2) && |
986 | m1(1,3) == m2(1,3) && | 986 | m1(1,3) == m2(1,3) && |
987 | m1(2,0) == m2(2,0) && | 987 | m1(2,0) == m2(2,0) && |
988 | m1(2,1) == m2(2,1) && | 988 | m1(2,1) == m2(2,1) && |
989 | m1(2,2) == m2(2,2) && | 989 | m1(2,2) == m2(2,2) && |
990 | m1(2,3) == m2(2,3) && | 990 | m1(2,3) == m2(2,3) && |
991 | m1(3,0) == m2(3,0) && | 991 | m1(3,0) == m2(3,0) && |
992 | m1(3,1) == m2(3,1) && | 992 | m1(3,1) == m2(3,1) && |
993 | m1(3,2) == m2(3,2) && | 993 | m1(3,2) == m2(3,2) && |
994 | m1(3,3) == m2(3,3) ); | 994 | m1(3,3) == m2(3,3) ); |
995 | } | 995 | } |
996 | 996 | ||
997 | inline | 997 | inline |
998 | bool operator != ( const matrix4 & m1, const matrix4 & m2 ) | 998 | bool operator != ( const matrix4 & m1, const matrix4 & m2 ) |
999 | { return !( m1 == m2 ); } | 999 | { return !( m1 == m2 ); } |
1000 | 1000 | ||
1001 | 1001 | ||
1002 | 1002 | ||
1003 | 1003 | ||
1004 | 1004 | ||
1005 | 1005 | ||
1006 | 1006 | ||
1007 | 1007 | ||
1008 | 1008 | ||
1009 | 1009 | ||
1010 | 1010 | ||
1011 | 1011 | ||
1012 | 1012 | ||
1013 | class quaternion | 1013 | class quaternion |
1014 | { | 1014 | { |
1015 | public: | 1015 | public: |
1016 | 1016 | ||
1017 | quaternion() | 1017 | quaternion() |
1018 | { | 1018 | { |
1019 | *this = identity(); | 1019 | *this = identity(); |
1020 | } | 1020 | } |
1021 | 1021 | ||
1022 | quaternion( const real v[4] ) | 1022 | quaternion( const real v[4] ) |
1023 | { | 1023 | { |
1024 | set_value( v ); | 1024 | set_value( v ); |
1025 | } | 1025 | } |
1026 | 1026 | ||
1027 | 1027 | ||
1028 | quaternion( real q0, real q1, real q2, real q3 ) | 1028 | quaternion( real q0, real q1, real q2, real q3 ) |
1029 | { | 1029 | { |
1030 | set_value( q0, q1, q2, q3 ); | 1030 | set_value( q0, q1, q2, q3 ); |
1031 | } | 1031 | } |
1032 | 1032 | ||
1033 | 1033 | ||
1034 | quaternion( const matrix4 & m ) | 1034 | quaternion( const matrix4 & m ) |
1035 | { | 1035 | { |
1036 | set_value( m ); | 1036 | set_value( m ); |
1037 | } | 1037 | } |
1038 | 1038 | ||
1039 | 1039 | ||
1040 | quaternion( const vec3 &axis, real radians ) | 1040 | quaternion( const vec3 &axis, real radians ) |
1041 | { | 1041 | { |
1042 | set_value( axis, radians ); | 1042 | set_value( axis, radians ); |
1043 | } | 1043 | } |
1044 | 1044 | ||
1045 | 1045 | ||
1046 | quaternion( const vec3 &rotateFrom, const vec3 &rotateTo ) | 1046 | quaternion( const vec3 &rotateFrom, const vec3 &rotateTo ) |
1047 | { | 1047 | { |
1048 | set_value( rotateFrom, rotateTo ); | 1048 | set_value( rotateFrom, rotateTo ); |
1049 | } | 1049 | } |
1050 | 1050 | ||
1051 | quaternion( const vec3 & from_look, const vec3 & from_up, | 1051 | quaternion( const vec3 & from_look, const vec3 & from_up, |
1052 | const vec3 & to_look, const vec3& to_up) | 1052 | const vec3 & to_look, const vec3& to_up) |
1053 | { | 1053 | { |
1054 | set_value(from_look, from_up, to_look, to_up); | 1054 | set_value(from_look, from_up, to_look, to_up); |
1055 | } | 1055 | } |
1056 | 1056 | ||
1057 | const real * get_value() const | 1057 | const real * get_value() const |
1058 | { | 1058 | { |
1059 | return &q[0]; | 1059 | return &q[0]; |
1060 | } | 1060 | } |
1061 | 1061 | ||
1062 | void get_value( real &q0, real &q1, real &q2, real &q3 ) const | 1062 | void get_value( real &q0, real &q1, real &q2, real &q3 ) const |
1063 | { | 1063 | { |
1064 | q0 = q[0]; | 1064 | q0 = q[0]; |
1065 | q1 = q[1]; | 1065 | q1 = q[1]; |
1066 | q2 = q[2]; | 1066 | q2 = q[2]; |
1067 | q3 = q[3]; | 1067 | q3 = q[3]; |
1068 | } | 1068 | } |
1069 | 1069 | ||
1070 | quaternion & set_value( real q0, real q1, real q2, real q3 ) | 1070 | quaternion & set_value( real q0, real q1, real q2, real q3 ) |
1071 | { | 1071 | { |
1072 | q[0] = q0; | 1072 | q[0] = q0; |
1073 | q[1] = q1; | 1073 | q[1] = q1; |
1074 | q[2] = q2; | 1074 | q[2] = q2; |
1075 | q[3] = q3; | 1075 | q[3] = q3; |
1076 | counter = 0; | 1076 | counter = 0; |
1077 | return *this; | 1077 | return *this; |
1078 | } | 1078 | } |
1079 | 1079 | ||
1080 | void get_value( vec3 &axis, real &radians ) const | 1080 | void get_value( vec3 &axis, real &radians ) const |
1081 | { | 1081 | { |
1082 | radians = real(acos( q[3] ) * GLH_TWO); | 1082 | radians = real(acos( q[3] ) * GLH_TWO); |
1083 | if ( radians == GLH_ZERO ) | 1083 | if ( radians == GLH_ZERO ) |
1084 | axis = vec3( 0.0, 0.0, 1.0 ); | 1084 | axis = vec3( 0.0, 0.0, 1.0 ); |
1085 | else | 1085 | else |
1086 | { | 1086 | { |
1087 | axis.v[0] = q[0]; | 1087 | axis.v[0] = q[0]; |
1088 | axis.v[1] = q[1]; | 1088 | axis.v[1] = q[1]; |
1089 | axis.v[2] = q[2]; | 1089 | axis.v[2] = q[2]; |
1090 | axis.normalize(); | 1090 | axis.normalize(); |
1091 | } | 1091 | } |
1092 | } | 1092 | } |
1093 | 1093 | ||
1094 | void get_value( matrix4 & m ) const | 1094 | void get_value( matrix4 & m ) const |
1095 | { | 1095 | { |
1096 | real s, xs, ys, zs, wx, wy, wz, xx, xy, xz, yy, yz, zz; | 1096 | real s, xs, ys, zs, wx, wy, wz, xx, xy, xz, yy, yz, zz; |
1097 | 1097 | ||
1098 | real norm = q[0] * q[0] + q[1] * q[1] + q[2] * q[2] + q[3] * q[3]; | 1098 | real norm = q[0] * q[0] + q[1] * q[1] + q[2] * q[2] + q[3] * q[3]; |
1099 | 1099 | ||
1100 | s = (equivalent(norm,GLH_ZERO)) ? GLH_ZERO : ( GLH_TWO / norm ); | 1100 | s = (equivalent(norm,GLH_ZERO)) ? GLH_ZERO : ( GLH_TWO / norm ); |
1101 | 1101 | ||
1102 | xs = q[0] * s; | 1102 | xs = q[0] * s; |
1103 | ys = q[1] * s; | 1103 | ys = q[1] * s; |
1104 | zs = q[2] * s; | 1104 | zs = q[2] * s; |
1105 | 1105 | ||
1106 | wx = q[3] * xs; | 1106 | wx = q[3] * xs; |
1107 | wy = q[3] * ys; | 1107 | wy = q[3] * ys; |
1108 | wz = q[3] * zs; | 1108 | wz = q[3] * zs; |
1109 | 1109 | ||
1110 | xx = q[0] * xs; | 1110 | xx = q[0] * xs; |
1111 | xy = q[0] * ys; | 1111 | xy = q[0] * ys; |
1112 | xz = q[0] * zs; | 1112 | xz = q[0] * zs; |
1113 | 1113 | ||
1114 | yy = q[1] * ys; | 1114 | yy = q[1] * ys; |
1115 | yz = q[1] * zs; | 1115 | yz = q[1] * zs; |
1116 | zz = q[2] * zs; | 1116 | zz = q[2] * zs; |
1117 | 1117 | ||
1118 | m(0,0) = real( GLH_ONE - ( yy + zz )); | 1118 | m(0,0) = real( GLH_ONE - ( yy + zz )); |
1119 | m(1,0) = real ( xy + wz ); | 1119 | m(1,0) = real ( xy + wz ); |
1120 | m(2,0) = real ( xz - wy ); | 1120 | m(2,0) = real ( xz - wy ); |
1121 | 1121 | ||
1122 | m(0,1) = real ( xy - wz ); | 1122 | m(0,1) = real ( xy - wz ); |
1123 | m(1,1) = real ( GLH_ONE - ( xx + zz )); | 1123 | m(1,1) = real ( GLH_ONE - ( xx + zz )); |
1124 | m(2,1) = real ( yz + wx ); | 1124 | m(2,1) = real ( yz + wx ); |
1125 | 1125 | ||
1126 | m(0,2) = real ( xz + wy ); | 1126 | m(0,2) = real ( xz + wy ); |
1127 | m(1,2) = real ( yz - wx ); | 1127 | m(1,2) = real ( yz - wx ); |
1128 | m(2,2) = real ( GLH_ONE - ( xx + yy )); | 1128 | m(2,2) = real ( GLH_ONE - ( xx + yy )); |
1129 | 1129 | ||
1130 | m(3,0) = m(3,1) = m(3,2) = m(0,3) = m(1,3) = m(2,3) = GLH_ZERO; | 1130 | m(3,0) = m(3,1) = m(3,2) = m(0,3) = m(1,3) = m(2,3) = GLH_ZERO; |
1131 | m(3,3) = GLH_ONE; | 1131 | m(3,3) = GLH_ONE; |
1132 | } | 1132 | } |
1133 | 1133 | ||
1134 | quaternion & set_value( const real * qp ) | 1134 | quaternion & set_value( const real * qp ) |
1135 | { | 1135 | { |
1136 | memcpy(q,qp,sizeof(real) * 4); | 1136 | memcpy(q,qp,sizeof(real) * 4); |
1137 | 1137 | ||
1138 | counter = 0; | 1138 | counter = 0; |
1139 | return *this; | 1139 | return *this; |
1140 | } | 1140 | } |
1141 | 1141 | ||
1142 | quaternion & set_value( const matrix4 & m ) | 1142 | quaternion & set_value( const matrix4 & m ) |
1143 | { | 1143 | { |
1144 | real tr, s; | 1144 | real tr, s; |
1145 | int i, j, k; | 1145 | int i, j, k; |
1146 | const int nxt[3] = { 1, 2, 0 }; | 1146 | const int nxt[3] = { 1, 2, 0 }; |
1147 | 1147 | ||
1148 | tr = m(0,0) + m(1,1) + m(2,2); | 1148 | tr = m(0,0) + m(1,1) + m(2,2); |
1149 | 1149 | ||
1150 | if ( tr > GLH_ZERO ) | 1150 | if ( tr > GLH_ZERO ) |
1151 | { | 1151 | { |
1152 | s = real(sqrt( tr + m(3,3) )); | 1152 | s = real(sqrt( tr + m(3,3) )); |
1153 | q[3] = real ( s * 0.5 ); | 1153 | q[3] = real ( s * 0.5 ); |
1154 | s = real(0.5) / s; | 1154 | s = real(0.5) / s; |
1155 | 1155 | ||
1156 | q[0] = real ( ( m(1,2) - m(2,1) ) * s ); | 1156 | q[0] = real ( ( m(1,2) - m(2,1) ) * s ); |
1157 | q[1] = real ( ( m(2,0) - m(0,2) ) * s ); | 1157 | q[1] = real ( ( m(2,0) - m(0,2) ) * s ); |
1158 | q[2] = real ( ( m(0,1) - m(1,0) ) * s ); | 1158 | q[2] = real ( ( m(0,1) - m(1,0) ) * s ); |
1159 | } | 1159 | } |
1160 | else | 1160 | else |
1161 | { | 1161 | { |
1162 | i = 0; | 1162 | i = 0; |
1163 | if ( m(1,1) > m(0,0) ) | 1163 | if ( m(1,1) > m(0,0) ) |
1164 | i = 1; | 1164 | i = 1; |
1165 | 1165 | ||
1166 | if ( m(2,2) > m(i,i) ) | 1166 | if ( m(2,2) > m(i,i) ) |
1167 | i = 2; | 1167 | i = 2; |
1168 | 1168 | ||
1169 | j = nxt[i]; | 1169 | j = nxt[i]; |
1170 | k = nxt[j]; | 1170 | k = nxt[j]; |
1171 | 1171 | ||
1172 | s = real(sqrt( ( m(i,j) - ( m(j,j) + m(k,k) )) + GLH_ONE )); | 1172 | s = real(sqrt( ( m(i,j) - ( m(j,j) + m(k,k) )) + GLH_ONE )); |
1173 | 1173 | ||
1174 | q[i] = real ( s * 0.5 ); | 1174 | q[i] = real ( s * 0.5 ); |
1175 | s = real(0.5 / s); | 1175 | s = real(0.5 / s); |
1176 | 1176 | ||
1177 | q[3] = real ( ( m(j,k) - m(k,j) ) * s ); | 1177 | q[3] = real ( ( m(j,k) - m(k,j) ) * s ); |
1178 | q[j] = real ( ( m(i,j) + m(j,i) ) * s ); | 1178 | q[j] = real ( ( m(i,j) + m(j,i) ) * s ); |
1179 | q[k] = real ( ( m(i,k) + m(k,i) ) * s ); | 1179 | q[k] = real ( ( m(i,k) + m(k,i) ) * s ); |
1180 | } | 1180 | } |
1181 | 1181 | ||
1182 | counter = 0; | 1182 | counter = 0; |
1183 | return *this; | 1183 | return *this; |
1184 | } | 1184 | } |
1185 | 1185 | ||
1186 | quaternion & set_value( const vec3 &axis, real theta ) | 1186 | quaternion & set_value( const vec3 &axis, real theta ) |
1187 | { | 1187 | { |
1188 | real sqnorm = axis.square_norm(); | 1188 | real sqnorm = axis.square_norm(); |
1189 | 1189 | ||
1190 | if (sqnorm <= GLH_EPSILON) | 1190 | if (sqnorm <= GLH_EPSILON) |
1191 | { | 1191 | { |
1192 | // axis too small. | 1192 | // axis too small. |
1193 | x = y = z = 0.0; | 1193 | x = y = z = 0.0; |
1194 | w = 1.0; | 1194 | w = 1.0; |
1195 | } | 1195 | } |
1196 | else | 1196 | else |
1197 | { | 1197 | { |
1198 | theta *= real(0.5); | 1198 | theta *= real(0.5); |
1199 | real sin_theta = real(sin(theta)); | 1199 | real sin_theta = real(sin(theta)); |
1200 | 1200 | ||
1201 | if (!equivalent(sqnorm,GLH_ONE)) | 1201 | if (!equivalent(sqnorm,GLH_ONE)) |
1202 | sin_theta /= real(sqrt(sqnorm)); | 1202 | sin_theta /= real(sqrt(sqnorm)); |
1203 | x = sin_theta * axis.v[0]; | 1203 | x = sin_theta * axis.v[0]; |
1204 | y = sin_theta * axis.v[1]; | 1204 | y = sin_theta * axis.v[1]; |
1205 | z = sin_theta * axis.v[2]; | 1205 | z = sin_theta * axis.v[2]; |
1206 | w = real(cos(theta)); | 1206 | w = real(cos(theta)); |
1207 | } | 1207 | } |
1208 | return *this; | 1208 | return *this; |
1209 | } | 1209 | } |
1210 | 1210 | ||
1211 | quaternion & set_value( const vec3 & rotateFrom, const vec3 & rotateTo ) | 1211 | quaternion & set_value( const vec3 & rotateFrom, const vec3 & rotateTo ) |
1212 | { | 1212 | { |
1213 | vec3 p1, p2; | 1213 | vec3 p1, p2; |
1214 | real alpha; | 1214 | real alpha; |
1215 | 1215 | ||
1216 | p1 = rotateFrom; | 1216 | p1 = rotateFrom; |
1217 | p1.normalize(); | 1217 | p1.normalize(); |
1218 | p2 = rotateTo; | 1218 | p2 = rotateTo; |
1219 | p2.normalize(); | 1219 | p2.normalize(); |
1220 | 1220 | ||
1221 | alpha = p1.dot(p2); | 1221 | alpha = p1.dot(p2); |
1222 | 1222 | ||
1223 | if(equivalent(alpha,GLH_ONE)) | 1223 | if(equivalent(alpha,GLH_ONE)) |
1224 | { | 1224 | { |
1225 | *this = identity(); | 1225 | *this = identity(); |
1226 | return *this; | 1226 | return *this; |
1227 | } | 1227 | } |
1228 | 1228 | ||
1229 | // ensures that the anti-parallel case leads to a positive dot | 1229 | // ensures that the anti-parallel case leads to a positive dot |
1230 | if(equivalent(alpha,-GLH_ONE)) | 1230 | if(equivalent(alpha,-GLH_ONE)) |
1231 | { | 1231 | { |
1232 | vec3 v; | 1232 | vec3 v; |
1233 | 1233 | ||
1234 | if(p1.v[0] != p1.v[1] || p1.v[0] != p1.v[2]) | 1234 | if(p1.v[0] != p1.v[1] || p1.v[0] != p1.v[2]) |
1235 | v = vec3(p1.v[1], p1.v[2], p1.v[0]); | 1235 | v = vec3(p1.v[1], p1.v[2], p1.v[0]); |
1236 | else | 1236 | else |
1237 | v = vec3(-p1.v[0], p1.v[1], p1.v[2]); | 1237 | v = vec3(-p1.v[0], p1.v[1], p1.v[2]); |
1238 | 1238 | ||
1239 | v -= p1 * p1.dot(v); | 1239 | v -= p1 * p1.dot(v); |
1240 | v.normalize(); | 1240 | v.normalize(); |
1241 | 1241 | ||
1242 | set_value(v, GLH_PI); | 1242 | set_value(v, GLH_PI); |
1243 | return *this; | 1243 | return *this; |
1244 | } | 1244 | } |
1245 | 1245 | ||
1246 | p1 = p1.cross(p2); | 1246 | p1 = p1.cross(p2); |
1247 | p1.normalize(); | 1247 | p1.normalize(); |
1248 | set_value(p1,real(acos(alpha))); | 1248 | set_value(p1,real(acos(alpha))); |
1249 | 1249 | ||
1250 | counter = 0; | 1250 | counter = 0; |
1251 | return *this; | 1251 | return *this; |
1252 | } | 1252 | } |
1253 | 1253 | ||
1254 | quaternion & set_value( const vec3 & from_look, const vec3 & from_up, | 1254 | quaternion & set_value( const vec3 & from_look, const vec3 & from_up, |
1255 | const vec3 & to_look, const vec3 & to_up) | 1255 | const vec3 & to_look, const vec3 & to_up) |
1256 | { | 1256 | { |
1257 | quaternion r_look = quaternion(from_look, to_look); | 1257 | quaternion r_look = quaternion(from_look, to_look); |
1258 | 1258 | ||
1259 | vec3 rotated_from_up(from_up); | 1259 | vec3 rotated_from_up(from_up); |
1260 | r_look.mult_vec(rotated_from_up); | 1260 | r_look.mult_vec(rotated_from_up); |
1261 | 1261 | ||
1262 | quaternion r_twist = quaternion(rotated_from_up, to_up); | 1262 | quaternion r_twist = quaternion(rotated_from_up, to_up); |
1263 | 1263 | ||
1264 | *this = r_twist; | 1264 | *this = r_twist; |
1265 | *this *= r_look; | 1265 | *this *= r_look; |
1266 | return *this; | 1266 | return *this; |
1267 | } | 1267 | } |
1268 | 1268 | ||
1269 | quaternion & operator *= ( const quaternion & qr ) | 1269 | quaternion & operator *= ( const quaternion & qr ) |
1270 | { | 1270 | { |
1271 | quaternion ql(*this); | 1271 | quaternion ql(*this); |
1272 | 1272 | ||
1273 | w = ql.w * qr.w - ql.x * qr.x - ql.y * qr.y - ql.z * qr.z; | 1273 | w = ql.w * qr.w - ql.x * qr.x - ql.y * qr.y - ql.z * qr.z; |
1274 | x = ql.w * qr.x + ql.x * qr.w + ql.y * qr.z - ql.z * qr.y; | 1274 | x = ql.w * qr.x + ql.x * qr.w + ql.y * qr.z - ql.z * qr.y; |
1275 | y = ql.w * qr.y + ql.y * qr.w + ql.z * qr.x - ql.x * qr.z; | 1275 | y = ql.w * qr.y + ql.y * qr.w + ql.z * qr.x - ql.x * qr.z; |
1276 | z = ql.w * qr.z + ql.z * qr.w + ql.x * qr.y - ql.y * qr.x; | 1276 | z = ql.w * qr.z + ql.z * qr.w + ql.x * qr.y - ql.y * qr.x; |
1277 | 1277 | ||
1278 | counter += qr.counter; | 1278 | counter += qr.counter; |
1279 | counter++; | 1279 | counter++; |
1280 | counter_normalize(); | 1280 | counter_normalize(); |
1281 | return *this; | 1281 | return *this; |
1282 | } | 1282 | } |
1283 | 1283 | ||
1284 | void normalize() | 1284 | void normalize() |
1285 | { | 1285 | { |
1286 | real rnorm = GLH_ONE / real(sqrt(w * w + x * x + y * y + z * z)); | 1286 | real rnorm = GLH_ONE / real(sqrt(w * w + x * x + y * y + z * z)); |
1287 | if (equivalent(rnorm, GLH_ZERO)) | 1287 | if (equivalent(rnorm, GLH_ZERO)) |
1288 | return; | 1288 | return; |
1289 | x *= rnorm; | 1289 | x *= rnorm; |
1290 | y *= rnorm; | 1290 | y *= rnorm; |
1291 | z *= rnorm; | 1291 | z *= rnorm; |
1292 | w *= rnorm; | 1292 | w *= rnorm; |
1293 | counter = 0; | 1293 | counter = 0; |
1294 | } | 1294 | } |
1295 | 1295 | ||
1296 | friend bool operator == ( const quaternion & q1, const quaternion & q2 ); | 1296 | friend bool operator == ( const quaternion & q1, const quaternion & q2 ); |
1297 | 1297 | ||
1298 | friend bool operator != ( const quaternion & q1, const quaternion & q2 ); | 1298 | friend bool operator != ( const quaternion & q1, const quaternion & q2 ); |
1299 | 1299 | ||
1300 | friend quaternion operator * ( const quaternion & q1, const quaternion & q2 ); | 1300 | friend quaternion operator * ( const quaternion & q1, const quaternion & q2 ); |
1301 | 1301 | ||
1302 | bool equals( const quaternion & r, real tolerance ) const | 1302 | bool equals( const quaternion & r, real tolerance ) const |
1303 | { | 1303 | { |
1304 | real t; | 1304 | real t; |
1305 | 1305 | ||
1306 | t = ( | 1306 | t = ( |
1307 | (q[0]-r.q[0])*(q[0]-r.q[0]) + | 1307 | (q[0]-r.q[0])*(q[0]-r.q[0]) + |
1308 | (q[1]-r.q[1])*(q[1]-r.q[1]) + | 1308 | (q[1]-r.q[1])*(q[1]-r.q[1]) + |
1309 | (q[2]-r.q[2])*(q[2]-r.q[2]) + | 1309 | (q[2]-r.q[2])*(q[2]-r.q[2]) + |
1310 | (q[3]-r.q[3])*(q[3]-r.q[3]) ); | 1310 | (q[3]-r.q[3])*(q[3]-r.q[3]) ); |
1311 | if(t > GLH_EPSILON) | 1311 | if(t > GLH_EPSILON) |
1312 | return false; | 1312 | return false; |
1313 | return 1; | 1313 | return 1; |
1314 | } | 1314 | } |
1315 | 1315 | ||
1316 | quaternion & conjugate() | 1316 | quaternion & conjugate() |
1317 | { | 1317 | { |
1318 | q[0] *= -GLH_ONE; | 1318 | q[0] *= -GLH_ONE; |
1319 | q[1] *= -GLH_ONE; | 1319 | q[1] *= -GLH_ONE; |
1320 | q[2] *= -GLH_ONE; | 1320 | q[2] *= -GLH_ONE; |
1321 | return *this; | 1321 | return *this; |
1322 | } | 1322 | } |
1323 | 1323 | ||
1324 | quaternion & invert() | 1324 | quaternion & invert() |
1325 | { | 1325 | { |
1326 | return conjugate(); | 1326 | return conjugate(); |
1327 | } | 1327 | } |
1328 | 1328 | ||
1329 | quaternion inverse() const | 1329 | quaternion inverse() const |
1330 | { | 1330 | { |
1331 | quaternion r = *this; | 1331 | quaternion r = *this; |
1332 | return r.invert(); | 1332 | return r.invert(); |
1333 | } | 1333 | } |
1334 | 1334 | ||
1335 | // | 1335 | // |
1336 | // Quaternion multiplication with cartesian vector | 1336 | // Quaternion multiplication with cartesian vector |
1337 | // v' = q*v*q(star) | 1337 | // v' = q*v*q(star) |
1338 | // | 1338 | // |
1339 | void mult_vec( const vec3 &src, vec3 &dst ) const | 1339 | void mult_vec( const vec3 &src, vec3 &dst ) const |
1340 | { | 1340 | { |
1341 | real v_coef = w * w - x * x - y * y - z * z; | 1341 | real v_coef = w * w - x * x - y * y - z * z; |
1342 | real u_coef = GLH_TWO * (src.v[0] * x + src.v[1] * y + src.v[2] * z); | 1342 | real u_coef = GLH_TWO * (src.v[0] * x + src.v[1] * y + src.v[2] * z); |
1343 | real c_coef = GLH_TWO * w; | 1343 | real c_coef = GLH_TWO * w; |
1344 | 1344 | ||
1345 | dst.v[0] = v_coef * src.v[0] + u_coef * x + c_coef * (y * src.v[2] - z * src.v[1]); | 1345 | dst.v[0] = v_coef * src.v[0] + u_coef * x + c_coef * (y * src.v[2] - z * src.v[1]); |
1346 | dst.v[1] = v_coef * src.v[1] + u_coef * y + c_coef * (z * src.v[0] - x * src.v[2]); | 1346 | dst.v[1] = v_coef * src.v[1] + u_coef * y + c_coef * (z * src.v[0] - x * src.v[2]); |
1347 | dst.v[2] = v_coef * src.v[2] + u_coef * z + c_coef * (x * src.v[1] - y * src.v[0]); | 1347 | dst.v[2] = v_coef * src.v[2] + u_coef * z + c_coef * (x * src.v[1] - y * src.v[0]); |
1348 | } | 1348 | } |
1349 | 1349 | ||
1350 | void mult_vec( vec3 & src_and_dst) const | 1350 | void mult_vec( vec3 & src_and_dst) const |
1351 | { | 1351 | { |
1352 | mult_vec(vec3(src_and_dst), src_and_dst); | 1352 | mult_vec(vec3(src_and_dst), src_and_dst); |
1353 | } | 1353 | } |
1354 | 1354 | ||
1355 | void scale_angle( real scaleFactor ) | 1355 | void scale_angle( real scaleFactor ) |
1356 | { | 1356 | { |
1357 | vec3 axis; | 1357 | vec3 axis; |
1358 | real radians; | 1358 | real radians; |
1359 | 1359 | ||
1360 | get_value(axis, radians); | 1360 | get_value(axis, radians); |
1361 | radians *= scaleFactor; | 1361 | radians *= scaleFactor; |
1362 | set_value(axis, radians); | 1362 | set_value(axis, radians); |
1363 | } | 1363 | } |
1364 | 1364 | ||
1365 | static quaternion slerp( const quaternion & p, const quaternion & q, real alpha ) | 1365 | static quaternion slerp( const quaternion & p, const quaternion & q, real alpha ) |
1366 | { | 1366 | { |
1367 | quaternion r; | 1367 | quaternion r; |
1368 | 1368 | ||
1369 | real cos_omega = p.x * q.x + p.y * q.y + p.z * q.z + p.w * q.w; | 1369 | real cos_omega = p.x * q.x + p.y * q.y + p.z * q.z + p.w * q.w; |
1370 | // if B is on opposite hemisphere from A, use -B instead | 1370 | // if B is on opposite hemisphere from A, use -B instead |
1371 | 1371 | ||
1372 | int bflip; | 1372 | int bflip; |
1373 | if ( ( bflip = (cos_omega < GLH_ZERO)) ) | 1373 | if ( ( bflip = (cos_omega < GLH_ZERO)) ) |
1374 | cos_omega = -cos_omega; | 1374 | cos_omega = -cos_omega; |
1375 | 1375 | ||
1376 | // complementary interpolation parameter | 1376 | // complementary interpolation parameter |
1377 | real beta = GLH_ONE - alpha; | 1377 | real beta = GLH_ONE - alpha; |
1378 | 1378 | ||
1379 | if(cos_omega <= GLH_ONE - GLH_EPSILON) | 1379 | if(cos_omega <= GLH_ONE - GLH_EPSILON) |
1380 | return p; | 1380 | return p; |
1381 | 1381 | ||
1382 | real omega = real(acos(cos_omega)); | 1382 | real omega = real(acos(cos_omega)); |
1383 | real one_over_sin_omega = GLH_ONE / real(sin(omega)); | 1383 | real one_over_sin_omega = GLH_ONE / real(sin(omega)); |
1384 | 1384 | ||
1385 | beta = real(sin(omega*beta) * one_over_sin_omega); | 1385 | beta = real(sin(omega*beta) * one_over_sin_omega); |
1386 | alpha = real(sin(omega*alpha) * one_over_sin_omega); | 1386 | alpha = real(sin(omega*alpha) * one_over_sin_omega); |
1387 | 1387 | ||
1388 | if (bflip) | 1388 | if (bflip) |
1389 | alpha = -alpha; | 1389 | alpha = -alpha; |
1390 | 1390 | ||
1391 | r.x = beta * p.q[0]+ alpha * q.q[0]; | 1391 | r.x = beta * p.q[0]+ alpha * q.q[0]; |
1392 | r.y = beta * p.q[1]+ alpha * q.q[1]; | 1392 | r.y = beta * p.q[1]+ alpha * q.q[1]; |
1393 | r.z = beta * p.q[2]+ alpha * q.q[2]; | 1393 | r.z = beta * p.q[2]+ alpha * q.q[2]; |
1394 | r.w = beta * p.q[3]+ alpha * q.q[3]; | 1394 | r.w = beta * p.q[3]+ alpha * q.q[3]; |
1395 | return r; | 1395 | return r; |
1396 | } | 1396 | } |
1397 | 1397 | ||
1398 | static quaternion identity() | 1398 | static quaternion identity() |
1399 | { | 1399 | { |
1400 | static quaternion ident( vec3( 0.0, 0.0, 0.0 ), GLH_ONE ); | 1400 | static quaternion ident( vec3( 0.0, 0.0, 0.0 ), GLH_ONE ); |
1401 | return ident; | 1401 | return ident; |
1402 | } | 1402 | } |
1403 | 1403 | ||
1404 | real & operator []( int i ) | 1404 | real & operator []( int i ) |
1405 | { | 1405 | { |
1406 | assert(i < 4); | 1406 | assert(i < 4); |
1407 | return q[i]; | 1407 | return q[i]; |
1408 | } | 1408 | } |
1409 | 1409 | ||
1410 | const real & operator []( int i ) const | 1410 | const real & operator []( int i ) const |
1411 | { | 1411 | { |
1412 | assert(i < 4); | 1412 | assert(i < 4); |
1413 | return q[i]; | 1413 | return q[i]; |
1414 | } | 1414 | } |
1415 | 1415 | ||
1416 | protected: | 1416 | protected: |
1417 | 1417 | ||
1418 | void counter_normalize() | 1418 | void counter_normalize() |
1419 | { | 1419 | { |
1420 | if (counter > GLH_QUATERNION_NORMALIZATION_THRESHOLD) | 1420 | if (counter > GLH_QUATERNION_NORMALIZATION_THRESHOLD) |
1421 | normalize(); | 1421 | normalize(); |
1422 | } | 1422 | } |
1423 | 1423 | ||
1424 | union | 1424 | union |
1425 | { | 1425 | { |
1426 | struct | 1426 | struct |
1427 | { | 1427 | { |
1428 | real q[4]; | 1428 | real q[4]; |
1429 | }; | 1429 | }; |
1430 | struct | 1430 | struct |
1431 | { | 1431 | { |
1432 | real x; | 1432 | real x; |
1433 | real y; | 1433 | real y; |
1434 | real z; | 1434 | real z; |
1435 | real w; | 1435 | real w; |
1436 | }; | 1436 | }; |
1437 | }; | 1437 | }; |
1438 | 1438 | ||
1439 | // renormalization counter | 1439 | // renormalization counter |
1440 | unsigned char counter; | 1440 | unsigned char counter; |
1441 | }; | 1441 | }; |
1442 | 1442 | ||
1443 | inline | 1443 | inline |
1444 | bool operator == ( const quaternion & q1, const quaternion & q2 ) | 1444 | bool operator == ( const quaternion & q1, const quaternion & q2 ) |
1445 | { | 1445 | { |
1446 | return (equivalent(q1.x, q2.x) && | 1446 | return (equivalent(q1.x, q2.x) && |
1447 | equivalent(q1.y, q2.y) && | 1447 | equivalent(q1.y, q2.y) && |
1448 | equivalent(q1.z, q2.z) && | 1448 | equivalent(q1.z, q2.z) && |
1449 | equivalent(q1.w, q2.w) ); | 1449 | equivalent(q1.w, q2.w) ); |
1450 | } | 1450 | } |
1451 | 1451 | ||
1452 | inline | 1452 | inline |
1453 | bool operator != ( const quaternion & q1, const quaternion & q2 ) | 1453 | bool operator != ( const quaternion & q1, const quaternion & q2 ) |
1454 | { | 1454 | { |
1455 | return ! ( q1 == q2 ); | 1455 | return ! ( q1 == q2 ); |
1456 | } | 1456 | } |
1457 | 1457 | ||
1458 | inline | 1458 | inline |
1459 | quaternion operator * ( const quaternion & q1, const quaternion & q2 ) | 1459 | quaternion operator * ( const quaternion & q1, const quaternion & q2 ) |
1460 | { | 1460 | { |
1461 | quaternion r(q1); | 1461 | quaternion r(q1); |
1462 | r *= q2; | 1462 | r *= q2; |
1463 | return r; | 1463 | return r; |
1464 | } | 1464 | } |
1465 | 1465 | ||
1466 | 1466 | ||
1467 | 1467 | ||
1468 | 1468 | ||
1469 | 1469 | ||
1470 | 1470 | ||
1471 | 1471 | ||
1472 | 1472 | ||
1473 | 1473 | ||
1474 | 1474 | ||
1475 | class plane | 1475 | class plane |
1476 | { | 1476 | { |
1477 | public: | 1477 | public: |
1478 | 1478 | ||
1479 | plane() | 1479 | plane() |
1480 | { | 1480 | { |
1481 | planedistance = 0.0; | 1481 | planedistance = 0.0; |
1482 | planenormal.set_value( 0.0, 0.0, 1.0 ); | 1482 | planenormal.set_value( 0.0, 0.0, 1.0 ); |
1483 | } | 1483 | } |
1484 | 1484 | ||
1485 | 1485 | ||
1486 | plane( const vec3 &p0, const vec3 &p1, const vec3 &p2 ) | 1486 | plane( const vec3 &p0, const vec3 &p1, const vec3 &p2 ) |
1487 | { | 1487 | { |
1488 | vec3 v0 = p1 - p0; | 1488 | vec3 v0 = p1 - p0; |
1489 | vec3 v1 = p2 - p0; | 1489 | vec3 v1 = p2 - p0; |
1490 | planenormal = v0.cross(v1); | 1490 | planenormal = v0.cross(v1); |
1491 | planenormal.normalize(); | 1491 | planenormal.normalize(); |
1492 | planedistance = p0.dot(planenormal); | 1492 | planedistance = p0.dot(planenormal); |
1493 | } | 1493 | } |
1494 | 1494 | ||
1495 | plane( const vec3 &normal, real distance ) | 1495 | plane( const vec3 &normal, real distance ) |
1496 | { | 1496 | { |
1497 | planedistance = distance; | 1497 | planedistance = distance; |
1498 | planenormal = normal; | 1498 | planenormal = normal; |
1499 | planenormal.normalize(); | 1499 | planenormal.normalize(); |
1500 | } | 1500 | } |
1501 | 1501 | ||
1502 | plane( const vec3 &normal, const vec3 &point ) | 1502 | plane( const vec3 &normal, const vec3 &point ) |
1503 | { | 1503 | { |
1504 | planenormal = normal; | 1504 | planenormal = normal; |
1505 | planenormal.normalize(); | 1505 | planenormal.normalize(); |
1506 | planedistance = point.dot(planenormal); | 1506 | planedistance = point.dot(planenormal); |
1507 | } | 1507 | } |
1508 | 1508 | ||
1509 | void offset( real d ) | 1509 | void offset( real d ) |
1510 | { | 1510 | { |
1511 | planedistance += d; | 1511 | planedistance += d; |
1512 | } | 1512 | } |
1513 | 1513 | ||
1514 | bool intersect( const line &l, vec3 &intersection ) const | 1514 | bool intersect( const line &l, vec3 &intersection ) const |
1515 | { | 1515 | { |
1516 | vec3 pos, dir; | 1516 | vec3 pos, dir; |
1517 | vec3 pn = planenormal; | 1517 | vec3 pn = planenormal; |
1518 | real pd = planedistance; | 1518 | real pd = planedistance; |
1519 | 1519 | ||
1520 | pos = l.get_position(); | 1520 | pos = l.get_position(); |
1521 | dir = l.get_direction(); | 1521 | dir = l.get_direction(); |
1522 | 1522 | ||
1523 | if(dir.dot(pn) == 0.0) return 0; | 1523 | if(dir.dot(pn) == 0.0) return 0; |
1524 | pos -= pn*pd; | 1524 | pos -= pn*pd; |
1525 | // now we're talking about a plane passing through the origin | 1525 | // now we're talking about a plane passing through the origin |
1526 | if(pos.dot(pn) < 0.0) pn.negate(); | 1526 | if(pos.dot(pn) < 0.0) pn.negate(); |
1527 | if(dir.dot(pn) > 0.0) dir.negate(); | 1527 | if(dir.dot(pn) > 0.0) dir.negate(); |
1528 | vec3 ppos = pn * pos.dot(pn); | 1528 | vec3 ppos = pn * pos.dot(pn); |
1529 | pos = (ppos.length()/dir.dot(-pn))*dir; | 1529 | pos = (ppos.length()/dir.dot(-pn))*dir; |
1530 | intersection = l.get_position(); | 1530 | intersection = l.get_position(); |
1531 | intersection += pos; | 1531 | intersection += pos; |
1532 | return 1; | 1532 | return 1; |
1533 | } | 1533 | } |
1534 | void transform( const matrix4 &matrix ) | 1534 | void transform( const matrix4 &matrix ) |
1535 | { | 1535 | { |
1536 | matrix4 invtr = matrix.inverse(); | 1536 | matrix4 invtr = matrix.inverse(); |
1537 | invtr = invtr.transpose(); | 1537 | invtr = invtr.transpose(); |
1538 | 1538 | ||
1539 | vec3 pntOnplane = planenormal * planedistance; | 1539 | vec3 pntOnplane = planenormal * planedistance; |
1540 | vec3 newPntOnplane; | 1540 | vec3 newPntOnplane; |
1541 | vec3 newnormal; | 1541 | vec3 newnormal; |
1542 | 1542 | ||
1543 | invtr.mult_dir_matrix(planenormal, newnormal); | 1543 | invtr.mult_dir_matrix(planenormal, newnormal); |
1544 | matrix.mult_vec_matrix(pntOnplane, newPntOnplane); | 1544 | matrix.mult_vec_matrix(pntOnplane, newPntOnplane); |
1545 | 1545 | ||
1546 | newnormal.normalize(); | 1546 | newnormal.normalize(); |
1547 | planenormal = newnormal; | 1547 | planenormal = newnormal; |
1548 | planedistance = newPntOnplane.dot(planenormal); | 1548 | planedistance = newPntOnplane.dot(planenormal); |
1549 | } | 1549 | } |
1550 | 1550 | ||
1551 | bool is_in_half_space( const vec3 &point ) const | 1551 | bool is_in_half_space( const vec3 &point ) const |
1552 | { | 1552 | { |
1553 | 1553 | ||
1554 | if(( point.dot(planenormal) - planedistance) < 0.0) | 1554 | if(( point.dot(planenormal) - planedistance) < 0.0) |
1555 | return 0; | 1555 | return 0; |
1556 | return 1; | 1556 | return 1; |
1557 | } | 1557 | } |
1558 | 1558 | ||
1559 | 1559 | ||
1560 | real distance( const vec3 & point ) const | 1560 | real distance( const vec3 & point ) const |
1561 | { | 1561 | { |
1562 | return planenormal.dot(point - planenormal*planedistance); | 1562 | return planenormal.dot(point - planenormal*planedistance); |
1563 | } | 1563 | } |
1564 | 1564 | ||
1565 | const vec3 &get_normal() const | 1565 | const vec3 &get_normal() const |
1566 | { | 1566 | { |
1567 | return planenormal; | 1567 | return planenormal; |
1568 | } | 1568 | } |
1569 | 1569 | ||
1570 | 1570 | ||
1571 | real get_distance_from_origin() const | 1571 | real get_distance_from_origin() const |
1572 | { | 1572 | { |
1573 | return planedistance; | 1573 | return planedistance; |
1574 | } | 1574 | } |
1575 | 1575 | ||
1576 | 1576 | ||
1577 | friend bool operator == ( const plane & p1, const plane & p2 ); | 1577 | friend bool operator == ( const plane & p1, const plane & p2 ); |
1578 | 1578 | ||
1579 | 1579 | ||
1580 | friend bool operator != ( const plane & p1, const plane & p2 ); | 1580 | friend bool operator != ( const plane & p1, const plane & p2 ); |
1581 | 1581 | ||
1582 | //protected: | 1582 | //protected: |
1583 | vec3 planenormal; | 1583 | vec3 planenormal; |
1584 | real planedistance; | 1584 | real planedistance; |
1585 | }; | 1585 | }; |
1586 | 1586 | ||
1587 | inline | 1587 | inline |
1588 | bool operator == (const plane & p1, const plane & p2 ) | 1588 | bool operator == (const plane & p1, const plane & p2 ) |
1589 | { | 1589 | { |
1590 | return ( p1.planedistance == p2.planedistance && p1.planenormal == p2.planenormal); | 1590 | return ( p1.planedistance == p2.planedistance && p1.planenormal == p2.planenormal); |
1591 | } | 1591 | } |
1592 | 1592 | ||
1593 | inline | 1593 | inline |
1594 | bool operator != ( const plane & p1, const plane & p2 ) | 1594 | bool operator != ( const plane & p1, const plane & p2 ) |
1595 | { return ! (p1 == p2); } | 1595 | { return ! (p1 == p2); } |
1596 | 1596 | ||
1597 | 1597 | ||
1598 | 1598 | ||
1599 | } // "ns_##GLH_REAL" | 1599 | } // "ns_##GLH_REAL" |
1600 | 1600 | ||
1601 | // make common typedefs... | 1601 | // make common typedefs... |
1602 | #ifdef GLH_REAL_IS_FLOAT | 1602 | #ifdef GLH_REAL_IS_FLOAT |
1603 | typedef GLH_REAL_NAMESPACE::vec2 vec2f; | 1603 | typedef GLH_REAL_NAMESPACE::vec2 vec2f; |
1604 | typedef GLH_REAL_NAMESPACE::vec3 vec3f; | 1604 | typedef GLH_REAL_NAMESPACE::vec3 vec3f; |
1605 | typedef GLH_REAL_NAMESPACE::vec4 vec4f; | 1605 | typedef GLH_REAL_NAMESPACE::vec4 vec4f; |
1606 | typedef GLH_REAL_NAMESPACE::quaternion quaternionf; | 1606 | typedef GLH_REAL_NAMESPACE::quaternion quaternionf; |
1607 | typedef GLH_REAL_NAMESPACE::quaternion rotationf; | 1607 | typedef GLH_REAL_NAMESPACE::quaternion rotationf; |
1608 | typedef GLH_REAL_NAMESPACE::line linef; | 1608 | typedef GLH_REAL_NAMESPACE::line linef; |
1609 | typedef GLH_REAL_NAMESPACE::plane planef; | 1609 | typedef GLH_REAL_NAMESPACE::plane planef; |
1610 | typedef GLH_REAL_NAMESPACE::matrix4 matrix4f; | 1610 | typedef GLH_REAL_NAMESPACE::matrix4 matrix4f; |
1611 | #endif | 1611 | #endif |
1612 | 1612 | ||
1613 | 1613 | ||
1614 | 1614 | ||
1615 | 1615 | ||
1616 | } // namespace glh | 1616 | } // namespace glh |
1617 | 1617 | ||
1618 | 1618 | ||
1619 | 1619 | ||
1620 | #endif | 1620 | #endif |
1621 | 1621 | ||
diff --git a/linden/indra/lscript/lscript_compile/lscript_tree.cpp b/linden/indra/lscript/lscript_compile/lscript_tree.cpp index 984e7b0..2a927a4 100644 --- a/linden/indra/lscript/lscript_compile/lscript_tree.cpp +++ b/linden/indra/lscript/lscript_compile/lscript_tree.cpp | |||
@@ -8805,7 +8805,7 @@ void LLScriptIf::recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass p | |||
8805 | case LSCP_EMIT_BYTE_CODE: | 8805 | case LSCP_EMIT_BYTE_CODE: |
8806 | { | 8806 | { |
8807 | char jumpname[32]; /*Flawfinder: ignore*/ | 8807 | char jumpname[32]; /*Flawfinder: ignore*/ |
8808 | snprintf(jumpname, sizeof(jumpname),"##Temp Jump %d##", gTempJumpCount++); /* Flawfinder: ignore */ | 8808 | ll_snprintf(jumpname, sizeof(jumpname),"##Temp Jump %d##", gTempJumpCount++); /* Flawfinder: ignore */ |
8809 | 8809 | ||
8810 | mExpression->recurse(fp, tabs, tabsize, LSCP_TO_STACK, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | 8810 | mExpression->recurse(fp, tabs, tabsize, LSCP_TO_STACK, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); |
8811 | chunk->addByte(LSCRIPTOpCodes[LOPC_JUMPNIF]); | 8811 | chunk->addByte(LSCRIPTOpCodes[LOPC_JUMPNIF]); |
@@ -8891,9 +8891,9 @@ void LLScriptIfElse::recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePa | |||
8891 | case LSCP_EMIT_BYTE_CODE: | 8891 | case LSCP_EMIT_BYTE_CODE: |
8892 | { | 8892 | { |
8893 | char jumpname1[32]; /*Flawfinder: ignore*/ | 8893 | char jumpname1[32]; /*Flawfinder: ignore*/ |
8894 | snprintf(jumpname1, sizeof(jumpname1), "##Temp Jump %d##", gTempJumpCount++); /* Flawfinder: ignore */ | 8894 | ll_snprintf(jumpname1, sizeof(jumpname1), "##Temp Jump %d##", gTempJumpCount++); /* Flawfinder: ignore */ |
8895 | char jumpname2[32]; /*Flawfinder: ignore*/ | 8895 | char jumpname2[32]; /*Flawfinder: ignore*/ |
8896 | snprintf(jumpname2, sizeof(jumpname2), "##Temp Jump %d##", gTempJumpCount++); /* Flawfinder: ignore */ | 8896 | ll_snprintf(jumpname2, sizeof(jumpname2), "##Temp Jump %d##", gTempJumpCount++); /* Flawfinder: ignore */ |
8897 | 8897 | ||
8898 | mExpression->recurse(fp, tabs, tabsize, LSCP_TO_STACK, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | 8898 | mExpression->recurse(fp, tabs, tabsize, LSCP_TO_STACK, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); |
8899 | chunk->addByte(LSCRIPTOpCodes[LOPC_JUMPNIF]); | 8899 | chunk->addByte(LSCRIPTOpCodes[LOPC_JUMPNIF]); |
@@ -8996,9 +8996,9 @@ void LLScriptFor::recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass | |||
8996 | case LSCP_EMIT_BYTE_CODE: | 8996 | case LSCP_EMIT_BYTE_CODE: |
8997 | { | 8997 | { |
8998 | char jumpname1[32]; /*Flawfinder: ignore*/ | 8998 | char jumpname1[32]; /*Flawfinder: ignore*/ |
8999 | snprintf(jumpname1, sizeof(jumpname1), "##Temp Jump %d##", gTempJumpCount++); /* Flawfinder: ignore */ | 8999 | ll_snprintf(jumpname1, sizeof(jumpname1), "##Temp Jump %d##", gTempJumpCount++); /* Flawfinder: ignore */ |
9000 | char jumpname2[32]; /*Flawfinder: ignore*/ | 9000 | char jumpname2[32]; /*Flawfinder: ignore*/ |
9001 | snprintf(jumpname2, sizeof(jumpname2), "##Temp Jump %d##", gTempJumpCount++); /* Flawfinder: ignore */ | 9001 | ll_snprintf(jumpname2, sizeof(jumpname2), "##Temp Jump %d##", gTempJumpCount++); /* Flawfinder: ignore */ |
9002 | 9002 | ||
9003 | if(mSequence) | 9003 | if(mSequence) |
9004 | mSequence->recurse(fp, tabs, tabsize, LSCP_TO_STACK, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | 9004 | mSequence->recurse(fp, tabs, tabsize, LSCP_TO_STACK, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); |
@@ -9095,7 +9095,7 @@ void LLScriptDoWhile::recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompileP | |||
9095 | case LSCP_EMIT_BYTE_CODE: | 9095 | case LSCP_EMIT_BYTE_CODE: |
9096 | { | 9096 | { |
9097 | char jumpname1[32]; /*Flawfinder: ignore*/ | 9097 | char jumpname1[32]; /*Flawfinder: ignore*/ |
9098 | snprintf(jumpname1, sizeof(jumpname1), "##Temp Jump %d##", gTempJumpCount++); /* Flawfinder: ignore */ | 9098 | ll_snprintf(jumpname1, sizeof(jumpname1), "##Temp Jump %d##", gTempJumpCount++); /* Flawfinder: ignore */ |
9099 | 9099 | ||
9100 | chunk->addLabel(jumpname1); | 9100 | chunk->addLabel(jumpname1); |
9101 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | 9101 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); |
@@ -9171,9 +9171,9 @@ void LLScriptWhile::recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePas | |||
9171 | case LSCP_EMIT_BYTE_CODE: | 9171 | case LSCP_EMIT_BYTE_CODE: |
9172 | { | 9172 | { |
9173 | char jumpname1[32]; /*Flawfinder: ignore*/ | 9173 | char jumpname1[32]; /*Flawfinder: ignore*/ |
9174 | snprintf(jumpname1, sizeof(jumpname1), "##Temp Jump %d##", gTempJumpCount++); /* Flawfinder: ignore */ | 9174 | ll_snprintf(jumpname1, sizeof(jumpname1), "##Temp Jump %d##", gTempJumpCount++); /* Flawfinder: ignore */ |
9175 | char jumpname2[32]; /*Flawfinder: ignore*/ | 9175 | char jumpname2[32]; /*Flawfinder: ignore*/ |
9176 | snprintf(jumpname2, sizeof(jumpname2), "##Temp Jump %d##", gTempJumpCount++); /* Flawfinder: ignore */ | 9176 | ll_snprintf(jumpname2, sizeof(jumpname2), "##Temp Jump %d##", gTempJumpCount++); /* Flawfinder: ignore */ |
9177 | 9177 | ||
9178 | chunk->addLabel(jumpname1); | 9178 | chunk->addLabel(jumpname1); |
9179 | mExpression->recurse(fp, tabs, tabsize, LSCP_TO_STACK, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | 9179 | mExpression->recurse(fp, tabs, tabsize, LSCP_TO_STACK, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); |
diff --git a/linden/indra/lscript/lscript_execute/lscript_execute.cpp b/linden/indra/lscript/lscript_execute/lscript_execute.cpp index b2b54cd..cb9a78e 100644 --- a/linden/indra/lscript/lscript_execute/lscript_execute.cpp +++ b/linden/indra/lscript/lscript_execute/lscript_execute.cpp | |||
@@ -3426,7 +3426,7 @@ BOOL run_cast(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id) | |||
3426 | case LST_STRING: | 3426 | case LST_STRING: |
3427 | { | 3427 | { |
3428 | S32 address, source = lscript_pop_int(buffer); | 3428 | S32 address, source = lscript_pop_int(buffer); |
3429 | snprintf(caststr, sizeof(caststr), "%d", source); /* Flawfinder: ignore */ | 3429 | ll_snprintf(caststr, sizeof(caststr), "%d", source); /* Flawfinder: ignore */ |
3430 | address = lsa_heap_add_data(buffer, new LLScriptLibData(caststr), get_max_heap_size(buffer), TRUE); | 3430 | address = lsa_heap_add_data(buffer, new LLScriptLibData(caststr), get_max_heap_size(buffer), TRUE); |
3431 | lscript_push(buffer, address); | 3431 | lscript_push(buffer, address); |
3432 | } | 3432 | } |
@@ -3463,7 +3463,7 @@ BOOL run_cast(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id) | |||
3463 | { | 3463 | { |
3464 | S32 address; | 3464 | S32 address; |
3465 | F32 source = lscript_pop_float(buffer); | 3465 | F32 source = lscript_pop_float(buffer); |
3466 | snprintf(caststr, sizeof(caststr), "%f", source); /* Flawfinder: ignore */ | 3466 | ll_snprintf(caststr, sizeof(caststr), "%f", source); /* Flawfinder: ignore */ |
3467 | address = lsa_heap_add_data(buffer, new LLScriptLibData(caststr), get_max_heap_size(buffer), TRUE); | 3467 | address = lsa_heap_add_data(buffer, new LLScriptLibData(caststr), get_max_heap_size(buffer), TRUE); |
3468 | lscript_push(buffer, address); | 3468 | lscript_push(buffer, address); |
3469 | } | 3469 | } |
@@ -3672,7 +3672,7 @@ BOOL run_cast(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id) | |||
3672 | S32 address; | 3672 | S32 address; |
3673 | LLVector3 source; | 3673 | LLVector3 source; |
3674 | lscript_pop_vector(buffer, source); | 3674 | lscript_pop_vector(buffer, source); |
3675 | snprintf(caststr, sizeof(caststr), "<%5.5f, %5.5f, %5.5f>", source.mV[VX], source.mV[VY], source.mV[VZ]); /* Flawfinder: ignore */ | 3675 | ll_snprintf(caststr, sizeof(caststr), "<%5.5f, %5.5f, %5.5f>", source.mV[VX], source.mV[VY], source.mV[VZ]); /* Flawfinder: ignore */ |
3676 | address = lsa_heap_add_data(buffer, new LLScriptLibData(caststr), get_max_heap_size(buffer), TRUE); | 3676 | address = lsa_heap_add_data(buffer, new LLScriptLibData(caststr), get_max_heap_size(buffer), TRUE); |
3677 | lscript_push(buffer, address); | 3677 | lscript_push(buffer, address); |
3678 | } | 3678 | } |
@@ -3705,7 +3705,7 @@ BOOL run_cast(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id) | |||
3705 | S32 address; | 3705 | S32 address; |
3706 | LLQuaternion source; | 3706 | LLQuaternion source; |
3707 | lscript_pop_quaternion(buffer, source); | 3707 | lscript_pop_quaternion(buffer, source); |
3708 | snprintf(caststr, sizeof(caststr), "<%5.5f, %5.5f, %5.5f, %5.5f>", source.mQ[VX], source.mQ[VY], source.mQ[VZ], source.mQ[VS]); /* Flawfinder: ignore */ | 3708 | ll_snprintf(caststr, sizeof(caststr), "<%5.5f, %5.5f, %5.5f, %5.5f>", source.mQ[VX], source.mQ[VY], source.mQ[VZ], source.mQ[VS]); /* Flawfinder: ignore */ |
3709 | address = lsa_heap_add_data(buffer, new LLScriptLibData(caststr), get_max_heap_size(buffer), TRUE); | 3709 | address = lsa_heap_add_data(buffer, new LLScriptLibData(caststr), get_max_heap_size(buffer), TRUE); |
3710 | lscript_push(buffer, address); | 3710 | lscript_push(buffer, address); |
3711 | } | 3711 | } |
diff --git a/linden/indra/lscript/lscript_library/lscript_library.cpp b/linden/indra/lscript/lscript_library/lscript_library.cpp index 6e170b9..a623a9a 100644 --- a/linden/indra/lscript/lscript_library/lscript_library.cpp +++ b/linden/indra/lscript/lscript_library/lscript_library.cpp | |||
@@ -591,7 +591,7 @@ LLScriptLibraryFunction::LLScriptLibraryFunction(F32 eu, F32 st, void (*exec_fun | |||
591 | char *mDesc_ = new char[512]; | 591 | char *mDesc_ = new char[512]; |
592 | if (mSleepTime) | 592 | if (mSleepTime) |
593 | { | 593 | { |
594 | snprintf( /* Flawfinder: ignore */ | 594 | ll_snprintf( /* Flawfinder: ignore */ |
595 | mDesc_, | 595 | mDesc_, |
596 | 512, | 596 | 512, |
597 | "%s\nSleeps script for %.1f seconds.", | 597 | "%s\nSleeps script for %.1f seconds.", |
@@ -652,7 +652,7 @@ void LLScriptLibData::print(std::ostream &s, BOOL b_prepend_comma) | |||
652 | s << mInteger; | 652 | s << mInteger; |
653 | break; | 653 | break; |
654 | case LST_FLOATINGPOINT: | 654 | case LST_FLOATINGPOINT: |
655 | snprintf(tmp, 1024, "%f", mFP); /* Flawfinder: ignore */ | 655 | ll_snprintf(tmp, 1024, "%f", mFP); /* Flawfinder: ignore */ |
656 | s << tmp; | 656 | s << tmp; |
657 | break; | 657 | break; |
658 | case LST_KEY: | 658 | case LST_KEY: |
@@ -662,12 +662,12 @@ void LLScriptLibData::print(std::ostream &s, BOOL b_prepend_comma) | |||
662 | s << mString; | 662 | s << mString; |
663 | break; | 663 | break; |
664 | case LST_VECTOR: | 664 | case LST_VECTOR: |
665 | snprintf(tmp, 1024, "<%f, %f, %f>", mVec.mV[VX], /* Flawfinder: ignore */ | 665 | ll_snprintf(tmp, 1024, "<%f, %f, %f>", mVec.mV[VX], /* Flawfinder: ignore */ |
666 | mVec.mV[VY], mVec.mV[VZ]); | 666 | mVec.mV[VY], mVec.mV[VZ]); |
667 | s << tmp; | 667 | s << tmp; |
668 | break; | 668 | break; |
669 | case LST_QUATERNION: | 669 | case LST_QUATERNION: |
670 | snprintf(tmp, 1024, "<%f, %f, %f, %f>", mQuat.mQ[VX], mQuat.mQ[VY], /* Flawfinder: ignore */ | 670 | ll_snprintf(tmp, 1024, "<%f, %f, %f, %f>", mQuat.mQ[VX], mQuat.mQ[VY], /* Flawfinder: ignore */ |
671 | mQuat.mQ[VZ], mQuat.mQ[VS]); | 671 | mQuat.mQ[VZ], mQuat.mQ[VS]); |
672 | s << tmp; | 672 | s << tmp; |
673 | break; | 673 | break; |
@@ -691,7 +691,7 @@ void LLScriptLibData::print_separator(std::ostream& ostr, BOOL b_prepend_sep, ch | |||
691 | ostr << mInteger; | 691 | ostr << mInteger; |
692 | break; | 692 | break; |
693 | case LST_FLOATINGPOINT: | 693 | case LST_FLOATINGPOINT: |
694 | snprintf(tmp, 1024, "%f", mFP); /* Flawfinder: ignore */ | 694 | ll_snprintf(tmp, 1024, "%f", mFP); /* Flawfinder: ignore */ |
695 | ostr << tmp; | 695 | ostr << tmp; |
696 | break; | 696 | break; |
697 | case LST_KEY: | 697 | case LST_KEY: |
@@ -701,12 +701,12 @@ void LLScriptLibData::print_separator(std::ostream& ostr, BOOL b_prepend_sep, ch | |||
701 | ostr << mString; | 701 | ostr << mString; |
702 | break; | 702 | break; |
703 | case LST_VECTOR: | 703 | case LST_VECTOR: |
704 | snprintf(tmp, 1024, "<%f, %f, %f>", mVec.mV[VX], /* Flawfinder: ignore */ | 704 | ll_snprintf(tmp, 1024, "<%f, %f, %f>", mVec.mV[VX], /* Flawfinder: ignore */ |
705 | mVec.mV[VY], mVec.mV[VZ]); | 705 | mVec.mV[VY], mVec.mV[VZ]); |
706 | ostr << tmp; | 706 | ostr << tmp; |
707 | break; | 707 | break; |
708 | case LST_QUATERNION: | 708 | case LST_QUATERNION: |
709 | snprintf(tmp, 1024, "<%f, %f, %f, %f>", mQuat.mQ[VX], mQuat.mQ[VY], /* Flawfinder: ignore */ | 709 | ll_snprintf(tmp, 1024, "<%f, %f, %f, %f>", mQuat.mQ[VX], mQuat.mQ[VY], /* Flawfinder: ignore */ |
710 | mQuat.mQ[VZ], mQuat.mQ[VS]); | 710 | mQuat.mQ[VZ], mQuat.mQ[VS]); |
711 | ostr << tmp; | 711 | ostr << tmp; |
712 | break; | 712 | break; |