我正在编写一个着色器,通过绘制阴影圆圈在点精灵上渲染球体,并且需要编写深度分量和颜色,以便彼此相邻的球体正确相交.
我使用的代码类似于Johna Holwerda编写的代码:
void PS_ShowDepth(VS_OUTPUT input, out float4 color: COLOR0,out float depth : DEPTH)
{
float dist = length (input.uv - float2 (0.5f, 0.5f)); //get the distance form the center of the point-sprite
float alpha = saturate(sign (0.5f - dist));
sphereDepth = cos (dist * 3.14159) * sphereThickness * particleSize; //calculate how thick the sphere should be; sphereThickness is a variable.
depth = saturate (sphereDepth + input.color.w); //input.color.w represents the depth value of the pixel on …Run Code Online (Sandbox Code Playgroud) 我正在使用Julian Bucknall在其着名的书" The Tomes Of Delphi"中编写的红黑树实现.源代码可以在这里下载,我在Delphi 2010中使用代码,并进行修改TdBasics.pas,让它在Delphi的现代版本中进行编译(主要是对大部分内容进行注释 - 树只需要一些定义)码.)
这是着名作家在一本经常推荐的书中的一个众所周知的实现.我觉得我应该坚持使用它.但我正在遇到使用Delete()和崩溃的崩溃Promote().回过头来用DUnit编写单元测试,这些问题很容易重现.一些示例代码是(来自我的DUnit测试的片段):
// Tests that require an initialised tree start with one with seven items
const
NumInitialItems : Integer = 7;
...
// Data is an int, not a pointer
function Compare(aData1, aData2: Pointer): Integer;
begin
if NativeInt(aData1) < NativeInt(aData2) then Exit(-1);
if NativeInt(aData1) > NativeInt(aData2) then Exit(1);
Exit(0);
end;
// Add seven items (0..6) to the tree. Node.Data is a pointer field, …Run Code Online (Sandbox Code Playgroud) 我正在添加对鼠标滚轮移动的支持到TScrollBox(使用FormMouseWheel过程),我需要确定鼠标是否在组件内.
基本上我需要确定鼠标是否在TScrollBox中,以便我随后处理滚动代码.
有关如何做到这一点的任何想法?
编辑:这是代码(包括这个问题的答案),因为它可能会帮助其他人:
procedure TForm1.FormMouseWheel(Sender: TObject;
Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint;
var Handled: Boolean);
var
Msg: Cardinal;
Code: Cardinal;
I, ScrollLines: Integer;
ScrollBoxCursosPos: TPoint;
begin
//position of the mouse cursor related to TScrollBox
ScrollBoxCursosPos := ScrollBox1.ScreenToClient(Mouse.CursorPos);
if (PtInRect(ScrollBox1.ClientRect, ScrollBoxCursosPos)) then
begin
Handled := True;
If ssShift In Shift Then
msg := WM_HSCROLL
Else
msg := WM_VSCROLL;
If WheelDelta < 0 Then
code := SB_LINEDOWN
Else
code := SB_LINEUP;
ScrollLines:= Mouse.WheelScrollLines * 3;
for I:= 1 to ScrollLines do …Run Code Online (Sandbox Code Playgroud)