⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sphere.asm

📁 游戏编程精粹2第四章源码
💻 ASM
📖 第 1 页 / 共 5 页
字号:
_DATA	ENDS
;	COMDAT __CT??_R0?AVinvalid_argument@std@@@8??0invalid_argument@std@@QAE@ABV01@@Z28
xdata$x	SEGMENT DWORD USE32 PUBLIC 'CONST'
xdata$x	ENDS
;	COMDAT __CT??_R0?AVbad_exception@std@@@8??0bad_exception@std@@QAE@ABV01@@Z12
xdata$x	SEGMENT DWORD USE32 PUBLIC 'CONST'
xdata$x	ENDS
;	COMDAT ??_R0?AVfailure@ios_base@std@@@8
_DATA	SEGMENT DWORD USE32 PUBLIC 'DATA'
_DATA	ENDS
;	COMDAT __TI2?AVlogic_error@std@@
xdata$x	SEGMENT DWORD USE32 PUBLIC 'CONST'
xdata$x	ENDS
;	COMDAT __TI3?AVoverflow_error@std@@
xdata$x	SEGMENT DWORD USE32 PUBLIC 'CONST'
xdata$x	ENDS
;	COMDAT __CT??_R0?AVdomain_error@std@@@8??0domain_error@std@@QAE@ABV01@@Z28
xdata$x	SEGMENT DWORD USE32 PUBLIC 'CONST'
xdata$x	ENDS
;	COMDAT __CT??_R0?AVruntime_error@std@@@8??0runtime_error@std@@QAE@ABV01@@Z28
xdata$x	SEGMENT DWORD USE32 PUBLIC 'CONST'
xdata$x	ENDS
;	COMDAT __CTA2?AVbad_typeid@std@@
xdata$x	SEGMENT DWORD USE32 PUBLIC 'CONST'
xdata$x	ENDS
;	COMDAT ??_R0?AVinvalid_argument@std@@@8
_DATA	SEGMENT DWORD USE32 PUBLIC 'DATA'
_DATA	ENDS
;	COMDAT ??_R0?AVrange_error@std@@@8
_DATA	SEGMENT DWORD USE32 PUBLIC 'DATA'
_DATA	ENDS
;	COMDAT __TI2?AVbad_exception@std@@
xdata$x	SEGMENT DWORD USE32 PUBLIC 'CONST'
xdata$x	ENDS
;	COMDAT ?_C@?1??_Nullstr@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@CAPBDXZ@4DB
CONST	SEGMENT DWORD USE32 PUBLIC 'CONST'
CONST	ENDS
;	COMDAT __CT??_R0?AVlogic_error@std@@@8??0logic_error@std@@QAE@ABV01@@Z28
xdata$x	SEGMENT DWORD USE32 PUBLIC 'CONST'
xdata$x	ENDS
;	COMDAT __TI2?AVbad_alloc@std@@
xdata$x	SEGMENT DWORD USE32 PUBLIC 'CONST'
xdata$x	ENDS
;	COMDAT ??_R0?AVbad_exception@std@@@8
_DATA	SEGMENT DWORD USE32 PUBLIC 'DATA'
_DATA	ENDS
;	COMDAT __CTA3?AVout_of_range@std@@
xdata$x	SEGMENT DWORD USE32 PUBLIC 'CONST'
xdata$x	ENDS
FLAT	GROUP _DATA, CONST, _BSS, CRT$XCA, CRT$XCU, CRT$XCL, CRT$XCC, CRT$XCZ, xdata$x
	ASSUME	CS: FLAT, DS: FLAT, SS: FLAT
endif
CRT$XCU	SEGMENT
_$S18	DD	FLAT:_$E17
_$S24	DD	FLAT:_$E23
_$S31	DD	FLAT:_$E30
CRT$XCU	ENDS
PUBLIC	?Set@Sphere@@QAEHABV?$Vector3d@M@@M@Z		; Sphere::Set
EXTRN	__fltused:NEAR
_TEXT	SEGMENT
_center$ = 8
_radius$ = 12
?Set@Sphere@@QAEHABV?$Vector3d@M@@M@Z PROC NEAR		; Sphere::Set

; 21   : {

	push	ebp
	mov	ebp, esp

; 22   : 	mCenter = center;

	mov	eax, DWORD PTR _center$[ebp]

; 23   : 	mRadius = radius;
; 24   : 	mRadius2 = radius*radius;

	fld	DWORD PTR _radius$[ebp]
	mov	edx, DWORD PTR [eax]
	fmul	DWORD PTR _radius$[ebp]
	mov	DWORD PTR [ecx], edx
	mov	edx, DWORD PTR [eax+4]
	mov	DWORD PTR [ecx+4], edx
	mov	eax, DWORD PTR [eax+8]
	mov	edx, DWORD PTR _radius$[ebp]
	mov	DWORD PTR [ecx+8], eax
	fstp	DWORD PTR [ecx+16]
	mov	DWORD PTR [ecx+12], edx

; 25   : }

	pop	ebp
	ret	8
?Set@Sphere@@QAEHABV?$Vector3d@M@@M@Z ENDP		; Sphere::Set
_TEXT	ENDS
PUBLIC	__real@4@bfff8000000000000000
PUBLIC	__real@4@00000000000000000000
PUBLIC	?RayIntersection@Sphere@@QAE_NABV?$Vector3d@M@@0PAV2@@Z ; Sphere::RayIntersection
PUBLIC	??0?$Vector3d@M@@QAE@ABV0@@Z			; Vector3d<float>::Vector3d<float>
;	COMDAT __real@4@bfff8000000000000000
; File C:\WINDOWS\Desktop\Gems2 CD\SourceCode\04 Geometry Management\03 Ratcliff\vector.h
CONST	SEGMENT
__real@4@bfff8000000000000000 DD 0bf800000r	; -1
CONST	ENDS
;	COMDAT __real@4@00000000000000000000
CONST	SEGMENT
__real@4@00000000000000000000 DD 000000000r	; 0
CONST	ENDS
_TEXT	SEGMENT
$T13831 = -12
_Diff$13842 = -24
_Scaled$13882 = -12
_Sum$13900 = -24
_rayOrigin$ = 8
_dir$ = 12
_intersect$ = 16
_V$ = -24
_v$ = 8
_disc$ = 12
?RayIntersection@Sphere@@QAE_NABV?$Vector3d@M@@0PAV2@@Z PROC NEAR ; Sphere::RayIntersection

; 35   : {

	push	ebp
	mov	ebp, esp
	sub	esp, 24					; 00000018H
	push	esi
	mov	esi, ecx
	push	edi

; 36   : 	//notation:
; 37   : 	//point E  = rayOrigin
; 38   : 	//point O  = sphere center
; 39   : 
; 40   : 	Vector3d<float> EO = mCenter - rayOrigin;

	mov	edi, DWORD PTR _rayOrigin$[ebp]
	fld	DWORD PTR [esi]
	fsub	DWORD PTR [edi]
	lea	eax, DWORD PTR _Diff$13842[ebp]
	lea	ecx, DWORD PTR $T13831[ebp]
	push	eax
	fstp	DWORD PTR _Diff$13842[ebp]
	fld	DWORD PTR [esi+4]
	fsub	DWORD PTR [edi+4]
	fstp	DWORD PTR _Diff$13842[ebp+4]
	fld	DWORD PTR [esi+8]
	fsub	DWORD PTR [edi+8]
	fstp	DWORD PTR _Diff$13842[ebp+8]
	call	??0?$Vector3d@M@@QAE@ABV0@@Z		; Vector3d<float>::Vector3d<float>

; 41   :   Vector3d<float> V = dir;

	mov	eax, DWORD PTR _dir$[ebp]
	fld	DWORD PTR [eax]
	fld	DWORD PTR [eax+8]

; 42   :   float dist2 = EO.x*EO.x + EO.y*EO.y + EO.z * EO.z;

	fld	DWORD PTR $T13831[ebp+8]
	fmul	DWORD PTR $T13831[ebp+8]
	fld	DWORD PTR $T13831[ebp+4]
	fmul	DWORD PTR $T13831[ebp+4]
	mov	ecx, DWORD PTR [eax+4]
	mov	DWORD PTR _V$[ebp+4], ecx

; 66   : 	}
; 67   : 	return false;

	faddp	ST(1), ST(0)
	fld	DWORD PTR $T13831[ebp]
	fmul	DWORD PTR $T13831[ebp]
	faddp	ST(1), ST(0)
	fcom	DWORD PTR [esi+16]
	fnstsw	ax
	test	ah, 1
	je	SHORT $L13853
	fxch	ST(2)
	fmul	DWORD PTR __real@4@bfff8000000000000000
	fxch	ST(2)
	fld	DWORD PTR _V$[ebp+4]
	fmul	DWORD PTR __real@4@bfff8000000000000000
	fstp	DWORD PTR _V$[ebp+4]
	fxch	ST(1)
	fmul	DWORD PTR __real@4@bfff8000000000000000
	fxch	ST(1)
$L13853:
	fld	ST(1)
	fmul	DWORD PTR $T13831[ebp+8]
	fld	DWORD PTR _V$[ebp+4]
	fmul	DWORD PTR $T13831[ebp+4]
	faddp	ST(1), ST(0)
	fld	ST(3)
	fmul	DWORD PTR $T13831[ebp]
	faddp	ST(1), ST(0)
	fst	DWORD PTR _v$[ebp]
	fmul	DWORD PTR _v$[ebp]
	fsubr	ST(0), ST(1)
	fsubr	DWORD PTR [esi+16]
	fstp	DWORD PTR _disc$[ebp]
	fstp	ST(0)
	fld	DWORD PTR _disc$[ebp]
	fcomp	DWORD PTR __real@4@00000000000000000000
	fnstsw	ax
	test	ah, 65					; 00000041H
	jne	SHORT $L12166
	mov	eax, DWORD PTR _intersect$[ebp]
	test	eax, eax
	je	SHORT $L13913
	fld	DWORD PTR _disc$[ebp]
	fsqrt
	fsubr	DWORD PTR _v$[ebp]
	fxch	ST(2)
	fmul	ST(0), ST(2)
	fstp	DWORD PTR _Scaled$13882[ebp]
	fld	DWORD PTR _V$[ebp+4]
	fmul	ST(0), ST(2)
	fstp	DWORD PTR _Scaled$13882[ebp+4]
	fmul	ST(0), ST(1)
	fxch	ST(1)
	fstp	ST(0)
	fld	DWORD PTR _Scaled$13882[ebp]
	fadd	DWORD PTR [edi]
	fld	DWORD PTR _Scaled$13882[ebp+4]
	fadd	DWORD PTR [edi+4]
	fstp	DWORD PTR _Sum$13900[ebp+4]
	fxch	ST(1)
	fadd	DWORD PTR [edi+8]
	mov	edx, DWORD PTR _Sum$13900[ebp+4]
	pop	edi
	mov	DWORD PTR [eax+4], edx
	pop	esi
	fstp	DWORD PTR _Sum$13900[ebp+8]
	mov	ecx, DWORD PTR _Sum$13900[ebp+8]
	fstp	DWORD PTR [eax]
	mov	DWORD PTR [eax+8], ecx
	mov	al, 1

; 68   : }

	mov	esp, ebp
	pop	ebp
	ret	12					; 0000000cH
$L13913:

; 43   :   // Bug Fix For Gem, if origin is *inside* the sphere, invert the
; 44   :   // direction vector so that we get a valid intersection location.
; 45   :   if ( dist2 < mRadius2 ) V*=-1;
; 46   : 
; 47   : 	float v = EO.Dot(V);
; 48   : 
; 49   : 	float disc = mRadius2 - (EO.Length2() - v*v);
; 50   : 
; 51   : 	if (disc > 0.0f)

	fstp	ST(0)
	pop	edi

; 52   : 	{
; 53   : 
; 54   : 		if ( intersect )
; 55   : 		{
; 56   : 
; 57   : 		  float d = sqrtf(disc);
; 58   : 
; 59   :       float dist2 = rayOrigin.Distance2(mCenter);
; 60   : 
; 61   :       *intersect = rayOrigin + V*(v-d);
; 62   : 
; 63   :     }
; 64   : 
; 65   : 		return true;

	mov	al, 1
	fstp	ST(0)
	pop	esi

; 68   : }

	mov	esp, ebp
	pop	ebp
	ret	12					; 0000000cH
$L12166:

; 43   :   // Bug Fix For Gem, if origin is *inside* the sphere, invert the
; 44   :   // direction vector so that we get a valid intersection location.
; 45   :   if ( dist2 < mRadius2 ) V*=-1;
; 46   : 
; 47   : 	float v = EO.Dot(V);
; 48   : 
; 49   : 	float disc = mRadius2 - (EO.Length2() - v*v);
; 50   : 
; 51   : 	if (disc > 0.0f)

	fstp	ST(0)
	pop	edi

; 66   : 	}
; 67   : 	return false;

	xor	al, al
	fstp	ST(0)
	pop	esi

; 68   : }

	mov	esp, ebp
	pop	ebp
	ret	12					; 0000000cH
?RayIntersection@Sphere@@QAE_NABV?$Vector3d@M@@0PAV2@@Z ENDP ; Sphere::RayIntersection
_TEXT	ENDS
PUBLIC	?RayIntersection@Sphere@@QAE_NABV?$Vector3d@M@@0MPAV2@@Z ; Sphere::RayIntersection
PUBLIC	??4?$Vector3d@M@@QAEAAV0@ABV0@@Z		; Vector3d<float>::operator=
_TEXT	SEGMENT
$T13942 = -48
_Diff$13946 = -36
_sect$13955 = -24
_rayOrigin$ = 8
_V$ = 12
_distance$ = 16
_intersect$ = 20
_sect$ = -12
?RayIntersection@Sphere@@QAE_NABV?$Vector3d@M@@0MPAV2@@Z PROC NEAR ; Sphere::RayIntersection

; 75   : {

	push	ebp
	mov	ebp, esp
	sub	esp, 48					; 00000030H
	push	esi

; 76   :   Vector3d<float> sect;
; 77   :   bool hit = RayIntersectionInFront(rayOrigin,V,&sect);

	mov	esi, DWORD PTR _rayOrigin$[ebp]
	push	edi
	mov	edi, DWORD PTR _V$[ebp]
	lea	eax, DWORD PTR _sect$13955[ebp]
	push	eax
	push	edi
	push	esi
	call	?RayIntersection@Sphere@@QAE_NABV?$Vector3d@M@@0PAV2@@Z ; Sphere::RayIntersection
	test	al, al
	je	$L12181
	fld	DWORD PTR _sect$13955[ebp]
	fsub	DWORD PTR [esi]
	lea	ecx, DWORD PTR _Diff$13946[ebp]
	push	ecx
	lea	ecx, DWORD PTR $T13942[ebp]
	fstp	DWORD PTR _Diff$13946[ebp]
	fld	DWORD PTR _sect$13955[ebp+4]
	fsub	DWORD PTR [esi+4]
	fstp	DWORD PTR _Diff$13946[ebp+4]
	fld	DWORD PTR _sect$13955[ebp+8]
	fsub	DWORD PTR [esi+8]
	fstp	DWORD PTR _Diff$13946[ebp+8]
	call	??0?$Vector3d@M@@QAE@ABV0@@Z		; Vector3d<float>::Vector3d<float>
	fld	DWORD PTR $T13942[ebp+8]
	fmul	DWORD PTR [edi+8]
	fld	DWORD PTR $T13942[ebp+4]
	fmul	DWORD PTR [edi+4]

; 78   : 
; 79   :   if ( hit )
; 80   :   {
; 81   :     float d = rayOrigin.Distance2(sect);
; 82   :     if ( d > (distance*distance) ) return false;
; 83   :     if ( intersect ) *intersect = sect;
; 84   :     return true;
; 85   :   }
; 86   :   return false;

	faddp	ST(1), ST(0)
	fld	DWORD PTR $T13942[ebp]
	fmul	DWORD PTR [edi]
	faddp	ST(1), ST(0)
	fcomp	DWORD PTR __real@4@00000000000000000000
	fnstsw	ax
	test	ah, 1
	jne	SHORT $L12181
	lea	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -