首页 \ 问答 \ 观察者设计模式的更新方法(Update method of Observer Design Pattern)

观察者设计模式的更新方法(Update method of Observer Design Pattern)

我见过几个Observer模式的例子。

为什么Observer接口中的update方法在某些情况下包含对被观察对象的引用? 观察者不知道它观察的是什么物体吗?

请举例说明。


I have seen few examples of Observer pattern.

Why does the update method in the Observer interface in some cases include a reference to the object being observed? Doesn't the observer know what object it is observing?

Please explain with example.


原文:https://stackoverflow.com/questions/12076660
更新时间:2020-01-21 16:56

最满意答案

我觉得你有错误:

vec3 NormalPosition_cameraspace = ( V * M * vec4(vertexNormal,1)).xyz;
Normal_cameraspace = -NormalPosition_cameraspace;

您应该使用0作为第四个组件(而不是1)从vertexNormal构造一个vec4。 这实际上意味着在乘以模型/视图矩阵时忽略任何转换。 这是你想要的,因为法线代表一个方向,而不是一个位置。

另外,我不明白这个计算:

LightDirection_cameraspace = LightPosition_cameraspace + EyeDirection_cameraspace;

不应该是这样的:

LightDirection_cameraspace = LightPosition_cameraspace - vertexPosition_cameraspace;

I think you have an error here:

vec3 NormalPosition_cameraspace = ( V * M * vec4(vertexNormal,1)).xyz;
Normal_cameraspace = -NormalPosition_cameraspace;

You should construct a vec4 from vertexNormal using 0 as the fourth component (not 1). This effectively means that any translation is ignored when multiplying by your model/view matrices. This is what you want because the normal represents a direction, not a position.

Also, I don't understand this calculation:

LightDirection_cameraspace = LightPosition_cameraspace + EyeDirection_cameraspace;

Shouldn't this be something like:

LightDirection_cameraspace = LightPosition_cameraspace - vertexPosition_cameraspace;

相关问答

更多
  • gl_TexCoord[0].x给你s的纹理坐标,而gl_TexCoord[0].y给你s的纹理坐标。 如果您正在编写片段着色器,则像素位置应该不重要。 我没有尝试,但也许你可以使用gl_in来获取它, gl_in定义如下: in gl_PerVertex { vec4 gl_Position; float gl_PointSize; float gl_ClipDistance[]; } gl_in[]; 但我不确定它是否适用于像素着色器。 gl_TexCoord[0].x gives you the s ...
  • 我认为有几件事可能是问题。 除非我弄错了,否则你正在使用normalize(gl_LightSource[0].position.xyz); 计算光矢量,但这仅仅基于光的位置,而不是基于您正在操作的顶点。 这意味着每个顶点的值都相同,并且只会根据当前的模型视图矩阵和灯光位置进行更改。 我认为通过执行像normalize(glLightSource[0].position.xyz - (gl_ModelViewMatrix * gl_Vertex).xyz)这样的计算光矢量会更接近你想要的。 其次,您应该在片 ...
  • 您的代码中缺少一些重要的东西。 首先,你应该将顶点位置和法线转换为眼睛空间。 照明计算最简单。 顶点位置使用模型视图矩阵进行变换,法线变换使用模型视图的转置反转。 通常光位置在世界坐标中,因此从世界到眼睛坐标提供额外的矩阵是有意义的。 There are few important things missing from your code. First you should transform vertex position and normal into eye space. Lighting calc ...
  • 我觉得你有错误: vec3 NormalPosition_cameraspace = ( V * M * vec4(vertexNormal,1)).xyz; Normal_cameraspace = -NormalPosition_cameraspace; 您应该使用0作为第四个组件(而不是1)从vertexNormal构造一个vec4。 这实际上意味着在乘以模型/视图矩阵时忽略任何转换。 这是你想要的,因为法线代表一个方向,而不是一个位置。 另外,我不明白这个计算: LightDirection_ca ...
  • HLSL矩阵是行主要的,GLSL是列主要的。 因此,如果您使用与传递到HLSL相同的内存布局将矩阵传递到GLSL着色器,那么您的HLSL行将成为GLSL列。 并且您应该在GLSL着色器中使用列主要乘法来获得与HLSL中相同的效果。 只是用 vec3 n = m * v; HLSL matrices are row-major, GLSL are column-major. So if you pass your matrix into GLSL shader using the same memory l ...
  • 纹理的颜色仍然在这里。 看起来在纹理中对单个像素进行采样。 这个问题似乎来自“oTexCoords”的价值观。 你可以尝试: fragColour = vec4(vec3(result),1.0) * vec4(oTexCoords, 0.0, 1.0); 并检查是否在立方体上看到红色/绿色渐变。 因此,当您移除光照时,请勿在着色器中使用光照组件(“结果”值),大多数编译器将删除导致计算“结果”的所有代码。 “结果”将被删除。 所以“norm”,“oNormal”,“vNormal”都会从你的着色器中消失 ...
  • 这很容易成为驱动程序问题,或者是另一张不支持扩展的卡。 在你的机器上试试他的二进制文件。 如果它仍然失败,则说明您的驱动程序是重击或者您正在使用卡不支持的命令。 另一方面,如果在使用他的机器上编译的代码时屏幕看起来正确,那么静态库就会出现问题。 This can very easily be a driver problem, or one card supporting extensions that the other does not. Try his binaries on your machine ...
  • 事实证明问题不在着色器中(感谢Zouch使用Shadertoy计算出来)。 我不小心把灯拉了两次,而不是一次。 Turns out the problem was NOT in the shaders (thank you Zouch for figuring that out using Shadertoy). I accidentally drew the lights twice, instead of once.
  • 检查vertex_normal和vertex_light_position值。 您可以通过使片段着色器执行以下操作来执行此操作: gl_FragColor = vertex_normal 我不确定是什么vertex_light_position ,但它听起来应该是从顶点到光的法线 ,而不是光的绝对位置。 编辑:请参阅http://www.opengl.org/sdk/docs/tutorials/ClockworkCoders/lighting.php Check your values for verte ...
  • 那不应该那么困难 是的,它应该是。 任意写入纹理并不是一件容易的事。 信息在OpenGL中以非常具体的方向流动:进入着色器。 着色器允许的唯一输出(通常)是实际的着色器输出变量。 例如,这就是你写入帧缓冲的方式。 顶点/几何着色器输出也可以馈送到变换反馈缓冲区。 现在,如果你有GL 4.x级硬件,你可以使用ARB_shader_image_load_store (GL 4.2中的核心)写入图像。 但是,在您启用此功能的那一刻,您将全权负责同步对内存的访问 。 That shouldn't be that d ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)