DirectX 9.0顶点缓冲区更新(DirectX 9.0 vertex buffer updating)
我使用DirectX 9.0制作了一个小型3D查看器应用程序。 现在我想添加一些编辑功能。 假设我想编辑一个大的多边形。 当用户编辑形状时,将添加,删除和移动顶点。 现在,每个多边形都存储为顶点缓冲区。 我的问题是,在用户编辑形状时存储和显示形状的最佳方法是什么? 如果我每次发生变化时都会破坏并重新创建顶点缓冲区,我相信它会过于耗费资源并且不够理想。
我虽然我也应该在主帖上问我的问题,所以他们在这里:
我有三个不同的任务,其中两个我不知道如何实现:
1)编辑顶点:简单,我将用VB中的新位置更新旧顶点。
2)删除顶点:这里发生了什么? 如何在不创建新VB的情况下删除它? 我应该添加一个空白的VB吗?
3)添加顶点:这里怎么样? 我可以更改动态VB的长度并在末尾添加顶点吗?我认为另一个想法会起作用:
1)编辑很容易
2)删除只意味着我将覆盖已删除的顶点,可能是前一个或下一个顶点的位置,因此它将不可见。
3)Addition将创建一个新的顶点缓冲区,但会像Vector或List一样调整大小。 每次重新创建它的大小都会是这样的
NewSize = OldSize * 1.1(增加10%)
所以连续添加不必重新创建VB。
所以1和2永远不会创建一个新的VB,3有时可能创建一个。 这听起来怎么样?I've made a small 3D viewer application using DirectX 9.0. Now I would like to add some editing functionality. Suppose that I want to edit a large polygon. While the user edits the shape, vertices would be added, deleted and moved. Right now each polygon is stored as a vertex buffer. My question is, what is the best way to store and display the shape while the user edits it? If i destroy and re-create the vertex buffer each time a change happens, I believe it will be too resource intensive and suboptimal.
I though I should ask my questions in the main post as well so here they are :
I have three different tasks, two of which I don't know how to implement :
1) Editing a vertex : Easy, I will just update the old vertex with the new position in the VB.
2) Deleting a vertex : What happens here? How do I remove it without creating a new VB? Should I just add a blank VB?
3) Adding a vertex : What about here? Can I change the length of a dynamic VB and add vertices at the end?Another thought here that I believe would work :
1) Editing is easy
2) Deleting would just mean that I will overwrite the deleted vertex with possibly the position of the previous or the next vertex, so it will not be visible.
3) Addition will create a new vertex buffer, but will resize like a Vector or a List. Each time it's re-created it's size would be something like
NewSize = OldSize * 1.1 (adding 10% more)
so that successive additions do not have to re-create the VB.
So 1 & 2 never create a new VB and 3 might sometimes create one. How does this sound?
原文:https://stackoverflow.com/questions/9537837
最满意答案
您可以从Binding派生一个类来预设ConverterCulture,并使用它来代替原始绑定,例如
Public Class Binding Inherits System.Windows.Data.Binding Public Sub New() MyBase.New() ConverterCulture = System.Globalization.CultureInfo.CurrentCulture End Sub Public Sub New(ByVal path As String) MyBase.New(path) ConverterCulture = System.Globalization.CultureInfo.CurrentCulture End Sub End Class
和
<TextBlock Text="{my:Binding TimeTest, StringFormat=t}" />
您也可以尝试自定义StringFormat,例如StringFormat ='HH:mm'
You can derive a class from Binding which presets the ConverterCulture, and use this instead of the original binding, like
Public Class Binding Inherits System.Windows.Data.Binding Public Sub New() MyBase.New() ConverterCulture = System.Globalization.CultureInfo.CurrentCulture End Sub Public Sub New(ByVal path As String) MyBase.New(path) ConverterCulture = System.Globalization.CultureInfo.CurrentCulture End Sub End Class
and
<TextBlock Text="{my:Binding TimeTest, StringFormat=t}" />
You might also try a custom StringFormat, like StringFormat='HH:mm'
相关问答
更多-
24小时时间下拉(24-hour time drop-down)[2022-06-23]
通常的方法是在00 。 00:15 12:15am 00:15 The usual way is prepending a 00. 00:15 for 12:15am -
在尝试格式化之前,请确保将检索到的字符串转换为[DateTime]对象,例如: C:\PS> "{0:HH:mm}" -f [datetime]'12:00 AM' 00:00 Make sure you convert the retrieved string to a [DateTime] object before trying to format it e.g.: C:\PS> "{0:HH:mm}" -f [datetime]'12:00 AM' 00:00
-
工作代码(考虑到您设法分割了字符串): public class App { public static void main(String[] args) { try { System.out.println(convertTo24HoursFormat("12:00AM")); // 00:00 System.out.println(convertTo24HoursFormat("12:00PM")); // 12:00 System.out.p ...
-
那么这应该工作: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init]; [dateFormatter setDateFormat:[NSDateFormatter dateFormatFromTemplate:@"hh:mm a" options:0 locale:[NSLocale currentLocale]]]; NSString *theTime = [dateFormatter stringFromDate:[NSDate ...
-
把24小时格式日期(“d / m / YH:i:s”)的h大写; Put the h capital for 24 hour format date("d/m/Y H:i:s");
-
尝试这个: $timeDiff = strtotime($itInfo['endTime']) - strtotime($itInfo['startTime']); echo substr('00'.($timeDiff / 3600 % 24),-2) .':'. substr('00'.($timeDiff / 60 % 60),-2) .':'. substr('00'.($timeDiff % 60),-2); Try this: $timeDiff = strtotime($i ...
-
只想分享一个有效的解决方案。 不一定有效率。 import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Test { public static void main(String[] args) throws Exception { int[] input = {1,2,6,7}; System.out.println(getLarg ...
-
如何让WPF在绑定中使用24小时时间格式强制执行(How do you get WPF to enforce using a 24 hour time format in bindings)[2024-03-18]
您可以从Binding派生一个类来预设ConverterCulture,并使用它来代替原始绑定,例如 Public Class Binding Inherits System.Windows.Data.Binding Public Sub New() MyBase.New() ConverterCulture = System.Globalization.CultureInfo.CurrentCulture ... -
如何将24小时时间格式转换为12小时时间格式?(How can I convert the 24 hour time format to 12 hour time format?)[2022-01-03]
如您所说,您应该使用NSDateFormatter获得所需的格式。 希望这会帮助你。 let date = NSDate() let formatter = NSDateFormatter() formatter.dateFormat = "hh:mm a" let time = formatter.stringFromDate(date) 有关日期格式化程序的更多信息,请参阅NSDateFormatter As you say, you should use NSDateFormatter for yo ... -
$timezone = +6; //(GMT +6:00) echo gmdate("H:i:s", time() + 3600*($timezone+date("I"))); $timezone = +6; //(GMT +6:00) echo gmdate("H:i:s", time() + 3600*($timezone+date("I")));