Monday, March 14, 2011 by Nate Bross
Someone asked on Stack Overflow:
I have Tab Control, with two tabs, and each tab contains a UserControl, the UserControls have Visual States defined along with Transitions.
The issue, that I’d like to get around, is that every time I change active tabs, the Visual State Transition storyboard runs, even when the control should already be in a state, and not need to be changed.
I’ve tracked this to the fact that changing tabs, causes the Constructor for all child UserControls in the newly visible tab to run. Is there a way to avoid this?
I posted the following answer, which was chosen as the accepted answer:
Turns out that because I binding the Content of the Tab it was unloading and reloading. Changing over to StaticResources and using DataContext fixed the issue in my case.
Originally posted on Stack Overflow — 0 upvotes (accepted answer). Licensed under CC BY-SA.
Wednesday, March 9, 2011 by Nate Bross
Someone asked on Game Development:
I’ve worked using Maya for animation and more film orientated projects however I am also focusing on my studies on video game development. Anyways, I was talking with one of my professor and we couldn’t figure out why all game engines (that I know of) convert to triangles.
Anyone happen to know why game engines convert to triangles compared to leaving the models as four sided polygons? Also what are the pros and cons (if any) of doing this?
I posted the following answer, which was chosen as the accepted answer and received 65 upvotes:
The bottom line is Triangle Rasterization, which is how computers render objects to the screen. Though others say it more elquently than I:
All 3D objects that we see on the computer screen are actually made of tiny little geometrical objects often called primitives. Quadrilaterals, triangles, n-gons etc. are example of primitives. We will concentrate on triangles mostly because of one main reason: every object can be split into triangles but a triangle cannot be split into anything else than triangles. Because of this, drawing triangles is a lot simpler than drawing polygons of higher order; less things to deal with. This is why those triangles are so commonly used in computer graphics.
Emphasis mine. Source: http://www.devmaster.net/articles/software-rendering/part3.php
Notable comments
Hatoru Hansou (6 upvotes): +1 Because is an answer I can safely use as reference when somebody ask me the same thing, to my bookmarks. Only say that, I always have thought that the reason triangles are the small possible primitive is because with the imprecision of float point arithmetic, tris are the only safe polygon you can guarantee to be planar in all cases, with quads you cannot guarantee they will be planar all the time. Modeling software probably show objects as quads or n-gons as convenience to the modeler but apply transforms/render dividing polygons as two or more triangles.
Originally posted on Game Development — 65 upvotes (accepted answer). Licensed under CC BY-SA.
Tuesday, March 8, 2011 by Nate Bross
Someone asked on Stack Overflow:
And when I say “install” I mean “move upon installation”. I want to package a movie file with an .apk, but it’s kind of big for internal storage (at least on older phones) as it is ~10mb.
Since there is no “run this custom code when you install” feature (reasonable), I can’t save to the SDcard the normal way… right?
There’s always the option of having the app download the movie and save it to the SDcard when the user first launches, but then they can’t watch the movie until it’s done downloading, and that doesn’t feel elegant since they just finished downloading the app and now have to wait again.
I know about installing the entire app to the SDcard, but that only works for 2.2+, eh? Enough phones are still running 2.1 that I want to support those.
I posted the following answer, which was chosen as the accepted answer:
I’ve seen several android apps offer something similar, via separate Marketplace downloads, space physics is a good example. Not really elegant, but it works well.
Originally posted on Stack Overflow — 0 upvotes (accepted answer). Licensed under CC BY-SA.
Monday, March 7, 2011 by Nate Bross
Someone asked on Game Development:
I’ve written a lot of the game, but it’s singleplayer. Now we want to join up and play together.
I want to host it like an MMO, but haven’t got any personal ability to host (no static IPs or direct access to a reasonable router that will allow me to port forward) so I wondered if there were any free / very cheap hosting solutions for people developing games that need to develop their MMO side.
In my case it’s a world server for a 2D game where the world map can be changed by the players. So, GAE sounds expensive, as there would be quite a few updates per second (I heard they bill for data updates but not for download, but can’t find refernce to billing anywhere on the FAQs)
I’d prefer to be able to write the server in python as that’s what the game is written in (with pygame), but C is fine, and maybe even better as it might prompt me to write some more performant world generator code ;)
I posted the following answer, which was chosen as the accepted answer and received 3 upvotes:
You might want to look into getting an EC2 instance (Micro) — you can run basically whatever you want on them, so writing python shouldn’t be a problem.
The smallest Linux instance is $0.02/hr as I recall, so it shouldn’t run you all that much.
However, I would build and test your server code on a LAN, and only once that is working well would I start looking for external hosting options. No need to pay for an Internet server, until you have something to actually test.
Notable comments
Nate (1 upvotes): I’m not saying you shouldn’t test in a WAN environment, but at east get it working on a LAN first.
coderanger (3 upvotes): Also of note, EC2 micro instances are free for a year to new customers.
Originally posted on Game Development — 3 upvotes (accepted answer). Licensed under CC BY-SA.
Monday, March 7, 2011 by Nate Bross
Someone asked on Stack Overflow:
I am attempting to bind my ViewModel’s IsInInputMode property to a Dependency Property in a UserControl. I am setting the UserControl’s DataContext to an instance of my ViewModel and all my XAML based bindings are working correctly. I need a code-behind solution to create this binding. I’ve tried a few things (at the bottom of the post) which have not worked.
I’m not getting any exceptions logged to the Output window either, which is where I’ve been told to look for Binding based exceptions.
I asked this similar question, on binding a Dependency Property in a UserControl through XAML — I was told this is not possible, so I’m looking for a code-behind solution.
The ViewModel looks like this:
class AddClientViewModel : ViewModelBase
{
private Boolean _isInInputMode;
public Boolean IsInInputMode
{
get { return _isInInputMode; }
set
{
_isInInputMode = value;
OnPropertyChanged("IsInInputMode");
}
}
public ICommand Cancel
{
get { return new RelayCommand(parm => { IsInInputMode = false; }); }
}
}
The Cancel command is successfully being data bound to a Button’s Command through XAML.
The Dependency Property in the UserControl looks like this:
public bool IsInInputMode
{
get { return (bool)GetValue(IsInInputModeProperty); }
set { SetValue(IsInInputModeProperty, value); }
}
public static readonly DependencyProperty IsInInputModeProperty =
DependencyProperty.Register("IsInInputMode", typeof(bool), typeof(AddClientView), new UIPropertyMetadata(new PropertyChangedCallback(_OnIsInInputModePropertyChanged)));
private static void _OnIsInInputModePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var mycontrol = d as AddClientView;
bool oldValue = (bool)e.OldValue;
bool newValue = (bool)e.NewValue;
if (null != mycontrol && oldValue != newValue)
{
mycontrol._OnIsInInputModeChanged(oldValue, newValue);
}
}
private void _OnIsInInputModeChanged(bool oldValue, bool newValue)
{
if (newValue)
{
VisualStateManager.GoToState(this, "InputState", false);
}
else
{
VisualStateManager.GoToState(this, "HiddenState", false);
}
}
The Binding in the Constructor of my UserControl has had a few iterations.
First Try:
public AddClientView()
{
InitializeComponent();
SetBinding(IsInInputModeProperty, "IsInInputMode");
}
Second Try:
public AddClientView()
{
InitializeComponent();
var b = new Binding();
b.Source = this.DataContext;
b.Path = new PropertyPath("IsInInputMode");
b.Mode = BindingMode.TwoWay;
b.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
BindingOperations.SetBinding(this, IsInInputModeProperty, b);
}
Neither of these “fail” with a compiler or runtime error; but when the IsInInputMode property changes in the ViewModel, the Dependency Property never updates, and the two even handlers there are never called.
As an additional note, the ViewModel has a few ICommand properties, which are being successfully bound to buttons in the UserControl via XAML — so I know the DataContext binding correctly.
I posted the following answer, which was chosen as the accepted answer:
Turns out it was a PEBKEC issue — I had a default value set somewhere, so OnNotifyPropertyChanged never got called, as such it appeared that the binding was broken.
I bound my boolean to a checkbox on the View, and using the UI control to change the value forced my animations to change, the correct code-behind binding was my first try:
SetBinding(IsInInputModeProperty, "IsInInputMode");
Originally posted on Stack Overflow — 0 upvotes (accepted answer). Licensed under CC BY-SA.
Friday, March 4, 2011 by Nate Bross
Someone asked on Stack Overflow:
Is there any difference between accessing a property that has a backing field
private int _id;
public int Id
{
get { return _id; }
set { _id = value; }
}
versus an auto-property?
public int Id { get; set; }
The reason I’m asking is that when letting ReSharper convert a property into an auto property it seems to scan my entire solution, or at least all aspx-files.
I can’t see any reason why there should be any difference between the two from outside the class. Is there?
I posted the following answer, which was chosen as the accepted answer and received 12 upvotes:
The compiler generates the backing field for Auto-Properties automatically, so no, there shouldn’t be any difference.
ReSharper is scanning all the files, because if you have a Partial class defined, it could be using the backing field instead of the public property even though the code exists in physically different files.
For Example:
// MyClass.cs
public partial class MyClass
{
int _id;
public int ID { get { return _id; } set { _id = value; } }
public MyClass(int identifier)
{
ID = identifier;
}
}
// MyClass2.cs
public partial class MyClass
{
public void ChangeID(int newID)
{
_id = newID;
}
}
ReSharper must scan all files, since it has no way to know where a partial class might be defined.
Notable comments
Nate (0 upvotes): @Ian — I’m not sure about files in other solutions, but ReSharper has no way of knowing the contents of a file until after it scans it, so it must scan ALL files to find any partial classes defined.
Originally posted on Stack Overflow — 12 upvotes (accepted answer). Licensed under CC BY-SA.
Wednesday, March 2, 2011 by Nate Bross
Someone asked on Game Development:
What is the effort required to use a game engine such as Unreal or Unity, etc. and create an avatar customization features…complete with clothes.
The user should be able to customize the body features and the clothes need to then fit onto the customized body.
What is needed? Can you create one set of 3D models for clothes and somehow programatically have the clothes adapt to the body shape? I.e. The same shirt model will be able to fit on a skinny person vs. someone with a big beer belly.
How difficult is this? What are the steps needed to implement this avatar creation/dressing feature.
I’m basically talking about something like in Rockband 3.
I posted the following answer, which was chosen as the accepted answer and received 2 upvotes:
In a general sense, the engines like Unreal or Unity provide you a way to get your assets on the screen. They may have tools for mashing up a bunch of assets, but you still need a program like Maya, 3D Studio Max, or Blender to build the assets you’re going to be mashing up.
Specifically, to answer your question on effort: the effort required is probably significant, but not insurmountable. It depends on your skills and dedication. If your a programmer, building the 3D models for each of the items you want will probably be the area you spend the most effort; on the other hand, if your already adept with a 3D modeling package, and aren’t much of a programmer, you’ll find yourself struggling with any engine.
The steps required, in my view are: (assuming you’re starting from absolute zero)
- Get one full-body 3D model
- Get one full set of 3D clothing models
- Download / Install the Unity or Unreal SDK
- Get a working creation model
- Using the scripting built-in to the engine to develop an interactive system
- Obtain all other full-body 3D models and associated clothing items
Note the unordered list, most of these can happen asynchronously, though if its just you working on it, it would probably make sense the serialize the process.
This is a relatively large task, that will probably require significant effort, and is probably (at least in my opinion) not a good place to start building games, I’d recommend biting off a smaller project if this is your first.
Originally posted on Game Development — 2 upvotes (accepted answer). Licensed under CC BY-SA.
Tuesday, March 1, 2011 by Nate Bross
Someone asked on Stack Overflow:
I’m attempting to use the .NET System.DirectoryServices.AccountManagement library to obtain the UserPrincipal for a particular Active Directory user.
I’ve got the following code:
PrincipalContext context = new PrincipalContext(ContextType.Domain, "DomainName");
userPrincipal = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, username);
This code is running as a valid domain user, but when I execute it I get the following exception:
System.DirectoryServices.DirectoryServicesCOMException (0x8007052E): Logon failure: unknown user name or bad password.
What’s interesting is that I can make the following call, using the same context, without a problem:
context.ValidateCredentials(username, password, ContextOptions.Negotiate)
Ideas?
I posted the following answer, which was chosen as the accepted answer and received 13 upvotes:
You need to use the the PrincipalContext constructor that takes username and password.
The reason that Validate works is because its using the provided credentials to bind to the directory.
Notable comments
Nate (0 upvotes): As far as I know, that shouldn’t be any different between Windows 2008 and Windows 2003 domains. If you’re only reading data, you delegation may not be necessary.
Nate (1 upvotes): In the Active Directory Users and Computers (on the domain controller) you need to select the Organizational Unit you want to manage, and “Delegate Control” in the delegate wizard, put in the credentials that your service is running as.
Nate (0 upvotes): I think you misunderstood, ValidateCredentials uses the credentials provided in the parameter list for ValidateCredentials — the Context you’ve defined has no credentials associated with it besides the ones of the current thread. I suspect your issues is in the configuration/deployment of the server. Make sure the account running the service has been delegated to within the domain.
Originally posted on Stack Overflow — 13 upvotes (accepted answer). Licensed under CC BY-SA.
Sunday, February 13, 2011 by Nate Bross
Someone asked on Game Development:
Do you remember an arcade game, that allowed two people to versus or play each other? It was a Galaga/Gradius type game.
Me and a couple of other people I know want to make a game like this. We want to get some other opinions on what programming languages to use. (C or C++ isn’t an option).
We plan to use an engine to help us build the game and it’s going to be a multiplayer game, so we would be handling the networking with this language as well.
We are thinking about C#, Java, or Actionscript 3.
Any advice on this? And if anyone knows the arcade game I am referring to please post up!
Edit
Let me add something here, this game will be played on computers and laptops only. We mainly want to know what’s good for handling the networking and Dual screen play.
I posted the following answer, which was chosen as the accepted answer and received 5 upvotes:
C# and XNA will allow you to develop for Windows, XBox, and Windows Phone. It supports multi-player two former platforms. One of the game samples that comes with the developer tools used to be a space shooter.
In my experience it has a very low barrier to entry, the tools are free for Windows, and only $99/year for XBox and Windows Phone.
Notable comments
Nate (0 upvotes): @bummzack Your point is true, but C# is listed in the OPs list of potential candidates.
Originally posted on Game Development — 5 upvotes (accepted answer). Licensed under CC BY-SA.
Thursday, February 10, 2011 by Nate Bross
Someone asked on Stack Overflow:
I’m trying to develop a server-client application for Android mobile devices. Here I need to test my client application with a server application which is dealing with the database. As I’m developing this application using the Eclips-ganymede SR2 with Android SDK plugins, I’m confusing how I can test my application with a server.
Is it possible to use my hard disk as the server? I mean will the Android emulator can access my hard disk?? Please give any idea related this
Thanks on Regards..
I posted the following answer, which was chosen as the accepted answer:
There is no way for the Android emulator to access your hard drive in the sense that you’re talking about. You may be able to mount a folder on your hard drive as an SD Card, but you would NOT want your app to use this, since it will go away once you deploy your app to the market. I recommend you build a web-service to run on your desktop (which will later be deployed to the Internet) and write your Android application to call this web-service.
Notable comments
Nate (0 upvotes): Depends on how you mean “access” — you should be able to access services on the host, IIRC the Android emulator is on the same LAN as your PC, so you should be able to access it by LAN IP. I may be wrong about that, can’t find where I read it.
Originally posted on Stack Overflow — 0 upvotes (accepted answer). Licensed under CC BY-SA.