Wednesday, 18 September 2013

Use Perlin noise to render wood

Use Perlin noise to render wood

guys, I'm reading Shaders for Game Programming and Artists. In Chapter 13
"Building Materials from Scratch", the author introduced some render
techniques to simulate complex materials such as marble or wood by using
Perlin noise. But I'm puzzled by the wood rendering. To simulate the wood,
we need a function gives a circular value along a specific plane so that
we can create the rings in the woods. This is what the author said, "take
the dot product of two axes along a plane, creating the circular value on
that plane"
Circle = dot(noisetxr.xy, noisetxr.xy);
noisetxr is a float3, it's a texture coordinate to sample the noise
texture, I can't understand why the dot product will gives a circular
value
Here is the complete code(pixel shader in hlsl):
float persistance;
float4 wood_color; //a predefined value
sampler Texture0; // noise texture
float4 ps_main(float3 txr: TEXCOORD0) : COLOR
{
// Determine two set of coordinates, one for the noise
// and one for the wood rings
float3 noisetxr = txr;
txr = txr/8;
// Combine 3 octaves of noise together.
float final_noise = 0;
for(int i=0;i<2;i++)
final_noise += ((1.0/pow(persistance,i))*
((tex3D(Texture0, txr*pow(2,i))*2)-1));
// The wood is defined by a set of concentric rings in the XY
// plane. Those rings are pertubated by the computed noise.
final_noise = abs(final_noise);
float grain = cos(dot(noisetxr.xy,noisetxr.xy) + final_noise*4);//what
is this ??
return wood_color - pow(grain,8)/2; //raising the cosine to higher power
}
I know that raising the cosine function to higher power will create
sharper rings, but what does the dot product mean ? Why it can create a
circle value ?

Tuesday, 17 September 2013

Cannot pop() more than once from the static stack

Cannot pop() more than once from the static stack

I need to use a static stack in one of my android application. Here's how
i used it:
In the Constants File:
public static Stack<String> st = new Stack<String>();
And in the Activity File, inside the onBackPressed method following logic
is used:
if (!Constants.st.isEmpty()) {
Log.i("CHECK", "Stack is not empty.");
Log.v("CHECK", "PEEK: " + Constants.st.peek());
Constants.st.pop();
if(Constants.st.isEmpty()){
Log.i("CHECK", "Stack is empty.");
}else{
Log.v("CHECK", "PEEK after POP: " + Constants.st.peek());
}
}else{
Log.i("CHECK", "Stack is empty.");
}
Now when i press back button once it works (i mean pop() function works),
then second time it( pop() function ) doesn't. Here is the Log of the
above logic:
: Stack is not empty.
: PEEK: UI_FirstActivity
: Stack is empty.
: Stack is not empty.
: PEEK: UI_SecondActivity
: PEEK after POP: UI_FirstActivity
: Stack is not empty.
: PEEK: UI_FirstActivity
: PEEK after POP: UI_FirstActivity
PS: Another thing is that whenever all these UI.. functions contains
different dynamically created forms shown on the same activity. Now when
we enter/show any method/form its name i.e., UI.. is been pushed in the
stack.

create a global NSMutableArray

create a global NSMutableArray

I have a lot of View Controller and all use the same Class (ViewController).
In ViewController.m I have this code:
- (void)viewDidLoad
{
[super viewDidLoad];
pedidoNomeArray = [[NSMutableArray alloc] init];
pedidoValorArray = [[NSMutableArray alloc] init];
}
and when I go to View Controller number 2 my array pedidoNomeArray and
pedidoValorArray are null.
What I have to do to use the same array in all my View Controllers?
thanks

How can I chain a scope after a class method, or ignore the class method's default sorting?

How can I chain a scope after a class method, or ignore the class method's
default sorting?

I need to find a workaround so I can filter my @events by the .is_near
method then sort them by the .sort_today scope, in that order.
Individually they both work, and I can tack .is_near to the end of the
scope with no problem, but then my results are resorted by the default
sort parameters in .is_near, and I need to them to be sorted by
.sort_today.
Is there a way to ignore how .is_near returns/resorts my results? Or
someway to chain them together like
@events.is_near(session[:city]).sort_today? Currently I get this error
when chaining them like that: undefined method `sort_today' for
#Array:0x007f8ca3c673c0
Here's my models:
class Venue < ActiveRecord::Base
attr_accessible :name, :address, :latitude, :longitude
has_many :events, :dependent => :destroy
geocoded_by :address
def self.is_near(city)
self.near(city, 20, :units => :km).map(&:events).flatten
end
end
class Event < ActiveRecord::Base
attr_accessible :title, :details, :start_time, :end_time, :date, :cost,
:venue_id
belongs_to :venue
scope :is_today, where(:date => Date.today)
scope :sort_today, is_today.order(:start_time)
class << self
def is_near(*args, &block)
Venue.is_near(*args, &block)
end
end
end
So Venue is geocoded by the RubyGeocoder gem and it has all the events.
The .is_near method has to be in Venue because the latitude and longitude
properties are there. The .is_near method at the bottom of Event is
essentially a redirect. (I tried to get delegate to work, but this was the
only way I could do it)
Here's my controllers:
class EventsController < ApplicationController
def index
@events = Event.sort_today.is_near(session[:city]) #returns results
but sorted wrong
#@events = Event.is_near(session[:city]).sort_today #returns undefined
method `sort_today' error
end
end
class ApplicationController < ActionController::Base
before_filter :set_city
def set_city
unless session[:city].present?
session[:city] = request.location.city
end
end
end
The set_city method just gets what city the user enters through a input
field.

is not convertible by 'QueryStringConverter'

is not convertible by 'QueryStringConverter'

I'm still a little new to WCF, I have a service that takes as input an
object that contains a bunch of string properties, but when I try to
consume the service I get the following error:
Operation 'GetHouseholds' in contract 'IHouseholdService' has a query
variable named 'criteria' of type
'RGMPServices.Householding.Contracts.DataTransferObjcets.HouseholdSearch',
but type
'RGMPServices.Householding.Contracts.DataTransferObjcets.HouseholdSearch'
is not convertible by 'QueryStringConverter'. Variables for UriTemplate
query values must have types that can be converted by
'QueryStringConverter'.
how do I go about making an object 'QueryStringConvertable'??
I have contract which looks like this:
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json)]
HouseholdDto[] GetHouseholds(HouseholdSearch criteria);
And the implementation is this:
public HouseholdDto[] GetHouseholds(HouseholdSearch criteria)
{
IList<Household> households =
_kernel.Get<IHouseholdRepository>().Search(criteria);
IList<HouseholdDto> dtos = Mapper.Map<IList<Household>,
IList<HouseholdDto>>(households);
return dtos.ToArray();
}
And my data contract for the object to be passed in is this:
[DataContract(Namespace = "urn:RGMPServices.Householding.Services", Name =
"HouseholdSearch")]
public class HouseholdSearch : IHouseholdSearch
{
[DataMember(IsRequired = false, Name = "HouseholdNumber")]
public string HouseholdNumber { get; set; }
[DataMember(IsRequired = false, Name = "HouseholdName")]
public string HouseholdName { get; set; }
[DataMember(IsRequired = false, Name = "AccountNumber")]
public string AccountNumber { get; set; }
[DataMember(IsRequired = false, Name = "AccountName")]
public string AccountName { get; set; }
[DataMember(IsRequired = false, Name = "IaCodes")]
public string IaCodes { get; set; }
[DataMember(IsRequired = false, Name = "Category")]
public string Category { get; set; }
}

Meteor bundle ignores folder and file

Meteor bundle ignores folder and file

There exists a app/main/document/temp.bin but this file is missing after I
run meteor bundle.
When I ran meteor bundle --debug the file got put inside
`bundle/programs/client/app/main/document/temp.bin
so how can I make meteor bundle work?

Customer view for Team Foundation Service

Customer view for Team Foundation Service

My team recently migrated from onsite to the cloud Team Foundation Service
2012.
We had also maintained a separate SharePoint portal with extranet
capabilities to list projects/tasks etc. for external customers
Seeing that we're now online, I was wondering if there is a means to
restrict a view to PBIs/Certain properties of tasks [Time Elapsed, Time
Remaining] for certain accounts.
Alternatively, I recall seeing SSRS capabilities in the on site version.
Is there a means to configure reports (scheduled/manual) using the Team
Foundation Service?