# ZeroEffect

Member

124

136 Neutral

• Rank
Member
1. ## Why do I get this casting error?

I have my warning level set at Level 4(/W4) and it occurs. When I drop the warning level to /W3 the warning is no longer displayed. It still seems odd that the error is displayed in the first place though.
2. ## Why do I get this casting error?

When I try to use the += operator between two unsigned chars I get the following error in Visual C++: warning C4244: '+=' : conversion from 'int' to 'unsigned char', possible loss of data However if, using the same variables (both unsigned chars) and the expanded form of the operator (temp = temp + temp2) then I get no errors Thanks.
3. ## Projective Texturing (and tex2Dproj)

I'm currently trying to better understand the math behind projective texturing wrt vertex & pixel shaders. Currently, since I'm working in DirectX, I must offset the texture so that the texel to pixel mapping is correct (offset by half a pixel in x and y). This involves multiplying vertex position in the light's perpective space by an adjustment matrix: | 0.5f 0.0f 0.0f 0.0f | | 0.0f -0.5f 0.0f 0.0f | | 0.0f 0.0f 0.0f 0.0f | | offsetX offsetY Bias 1.0f | Now, if my math is right, the x, y, z, w coords would be: x' = 0.5x + offsetX * w y' = -0.5y + offsetY * w z' = Bias * w w' = w My first question is: Will w always be equal to 1? Secondly: These coordinates are used as the texture lookup using the tex2Dproj(s, t) instruction. My understanding is that tex2Dproj divides t by t's fourth component before doing the lookup. But if the lookup is 2D then only x' and y' (uv in texture space) are used. What happens to z' (the Bias that I am applying to the projection)? Is there something that I don't understand about the tex2Dproj instruction? Thanks, Chris Z.
4. ## Material Alpha not working?

Currently I am trying to create a semi-transparent object using only a D3DMATERIAL. I've given the material an alpha value (for all components although diffuse color should suffice). Following the code in the SDK I am unable to get the object to be anything but opaque (although the color is correct). I would expect it to blend with the background color. Below is the SDK code. Are there any other render states that need to be enabled/disabled for this to work? from the SDK (Material Alpha): // use material diffuse color component m_pd3dDevice->SetRenderState( D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL ); ... // Initialize the material with an alpha value, and set the material before drawing. D3DMATERIAL9 mtrl; mtrl.Diffuse = mtrl.Ambient = mtrl.Specular = mtrl.Emissive = D3DCOLORVALUE(255,0,0,0.5f) m_pd3dDevice->SetMaterial(&mtrl); Thanks, Chris Z.

Thanks
6. ## one bounding sphere from two

Given that I have two bounding sphere and would like to create a new sphere (with the smallest volume) that encapsulates the two, what is the algorithm behind this? Thanks, Chris Z.
7. ## Maintaining size in viewport despite distance

How would I go about maintaining the viewport size of a 3D object in space regardless of its distance from the camera (object stays in the same position)? Would simple scaling be a viable solution or is another approach necessary? A good example of this behaviour is the transform indicators in modeling programs such as Maya or Max. Thanks, Chris Z.
8. ## Fast Sorting Algorithms?

Quote:Original post by eklypse I have a bubblesort in there right now. Just to prototype the manager and make sure it works how I want. Only I go from ~600fps (without sorting) down to ~1/1.5fps (with bubblesort). I'm just trying to improve the speed. To have this kind of performance hit I would assume that you are sorting every frame. If this is true you will need to ask youself, is this necessary? There may be alternatives to relying on a sort every frame. Chris Z.
9. ## Casting a const to a non const (C++)

I know that this will be considered poor programming, but the fact that I can compile under these circumstances raises the question... When I have a method that takes a constant (pointer in this case): void SomeMethod( const SomeObject* object) { ... } and somewhere in that method I pass that parameter to another method that uses the same pointer only in non-const form... If I don't explicitly cast the pointer, I get compile errors (expected) but if I do cast it to a non-const pointer: ... NewMethod( (SomeObject*)object ); ... it compiles fine. Will this cause problems down the road? If a const can be cast to a non-const, doesn't this defeat the purpose? Thanks, Chris Z.
10. ## Making a level editor / Dynamic size vertex buffers

I would tend to agree with sirob regarding the use of your own structures to manage the vertex data (internally) and then recreate/update the vertex buffer only when a change has been made to that vertex data. Relatively speaking, the time spent by a user adding/removing/modifying verties in a mesh is very small. As such, you should only ever recreate/modify the VB when an actual change has occurred. This may help in the sizing department as well. By recreating the VB you can size it exactly to match the number of vertices in a mesh (unless you reach the maximum limit of the video card). Try not to focus on how slow creating/updating the VB is. Focus on limiting the number of times you actually have to do it (i.e. every frame == very bad). Chris Z.
11. ## Setting Render States in .fx files (performance question)

Does setting the pipeline states in an .fx file provide better performance than using the SetRenderState method or is it just a wrapper used to clean up and simplify the pipeline? Chris Z.
12. ## SetLight() & SetMaterial()

Thanks, One follow up question then. Being that there is that really short time in which changes to the ptr may be realized, could I get into trouble if a local light/material object falls out of scope before the info is transferred? eg. SomeFunction() { D3D9Material9 material; // set defaults ... pd3dDevice->SetMaterial( &material ); // return immediately } Or, would the timeframe be so small that the memory wouldn't have time to be reallocated and overwritten?
13. ## SetLight() & SetMaterial()

When I set a light or a material using IDirect3DDevice9::SetMaterial Method or IDirect3DDevice9::SetLight Method, I'm passing in a pointer to a struct. My question is: Does Direct3D internally keep the pointer to the struct or does it copy the values to an internal struct? Meaning, if I make a change to that struct (color, etc...) will I need to set that light/material again? Or, if it is just accessing the ptr, will it be updated automatically? Thx, Chris Z.
14. ## Multiple viewports using Windows Forms

Currently I'm trying to find the best way to setup multiple DirectX viewports in a Window Form (Visual C++ .NET). I would also like to have the option to switch between a single viewport and multiple viewports. The first problem I am attempting to solve is how to have multiple viewports that can be sized (using the Splitter control or other control) without needing multiple D3D9 Devices. I would like to be able to us a simlar procedure to using one device and setting the D3DVIEWPORT9 structure for each view (as in a non-Forms app). Secondly, what would be the best approch to toggling between one and multiple viewports (especially if I am using Forms controls to split the viewports)? I can simply toggle the visibility for each panel (one being multi the other being single), but I am wondering if there is a better way. Although I have had some limited experience with Forms, this is my first attempt to incorperate Direct3D. Any ideas are appreciated. Chris Z.
15. ## Camera position from inverse view matrix

Realized my mistake while brushing my teeth :) Noob mistake: When I'm looking at the code (InvView[3]), arrays start at zero (doh!), so I am in fact using the fourth column. Thanks again for your help.